From patchwork Tue Mar 7 16:56:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 65762 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2574161wrd; Tue, 7 Mar 2023 09:58:22 -0800 (PST) X-Google-Smtp-Source: AK7set+sitYKjMojBMNIGFJ6CuV6j0XDLXHbrEzj9n2suVPtQnTD/sT7y15Ib66lbkbUrUnytMBp X-Received: by 2002:a50:ed18:0:b0:4af:7bdc:1891 with SMTP id j24-20020a50ed18000000b004af7bdc1891mr14780115eds.11.1678211902387; Tue, 07 Mar 2023 09:58:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678211902; cv=none; d=google.com; s=arc-20160816; b=e+b/FBJR22BgZIrHjpA2fMpHis5CyqOpJZEGZhLxNldwRv3vqKI3sLCP5nJ7XyZ+Ye sc82vz3HwY72nzIDRnJbGDWCrXOzWe6deR0rsugcA6mibtcVs3JUFZwwuDuQYYur/4OM J3b2x+Ra9/ykGvhzWKV73bBLErLPe6/dR9En2wJZQADwZ2cbEMF9aFV7fhdGUUSDEmY7 Otcy+fxyrtEn/NSNHf3JEAimKjVJxp3WxPHbVA44oithW4rwIBDpkj1uaxsxnEKacLA6 RZmwHXs8qrs9hRr2LvaUhOKoo1I3kr9E0XVn0ZE2wrHpqgU9F7z7p3RDuaciE4UD5fPU 2ZJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=G2e6moS34PZVDlEtlIuSOgMSiYGZrbHQe2ITWs/FfjU=; b=EdFSI7WyJj1TRfv1lZkRQKLafM86GbpKS6pAtH3FACzZInz8K/8kOKnUgyarUi88HD grSsfMKoyqIj86pN6q9i0OITVIPJ0dnvNIIER9loTkthkihuhnEgjYUITa8P2PjnwHH/ mYYr2gaEXnDYBbG87A0a5+ysSQ0nAykDb7nj3RtAtrs2FVD+CAkXPybs/PP9pfq5cvvo r0ZF4p1Zz4XJS140t31l/nNJe/vrXCJiImH+FUHD7lN2o08veojaRiG1499umTerISQF cvJPrIA+WMd7y7Zc17XQ54Kc8UTq/HrL2qvyyZXUzRzs1xgCcZ0lITmiJhCVy+OU2tzK QJsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2gcyqtS6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f16-20020a056402069000b004ad119f4af3si2656609edy.412.2023.03.07.09.57.58; Tue, 07 Mar 2023 09:58:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2gcyqtS6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232072AbjCGRod (ORCPT + 99 others); Tue, 7 Mar 2023 12:44:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231825AbjCGRoQ (ORCPT ); Tue, 7 Mar 2023 12:44:16 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21E5995E2D; Tue, 7 Mar 2023 09:40:03 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EDFDC6150F; Tue, 7 Mar 2023 17:40:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 089ACC4339B; Tue, 7 Mar 2023 17:40:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1678210802; bh=LeQHH3A/YVVZ58VA0ghtE+gGqnsXTxc4CFRT2Hs5Ukw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2gcyqtS6qNaq4Ip3pLV2Ye3RiQF8tU1VewsXO8Fmb8o3xzeYFn7Me2+IceGyfCNeE IFilnnxYxR2TZ5ZID6ficdj6JY74o0YGuziXn4PzRVcJPJr7LuCG4UpCV+S74VHGQq v/hue8EpI2Yr7mFo9JsmjXvYBPeUOOFT5KCXseB8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jens Axboe , Steven Rostedt , Masami Hiramatsu , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Bart Van Assche , Sasha Levin Subject: [PATCH 6.2 0628/1001] trace/blktrace: fix memory leak with using debugfs_lookup() Date: Tue, 7 Mar 2023 17:56:40 +0100 Message-Id: <20230307170048.806712929@linuxfoundation.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307170022.094103862@linuxfoundation.org> References: <20230307170022.094103862@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759732723371744759?= X-GMAIL-MSGID: =?utf-8?q?1759732723371744759?= From: Greg Kroah-Hartman [ Upstream commit 83e8864fee26f63a7435e941b7c36a20fd6fe93e ] When calling debugfs_lookup() the result must have dput() called on it, otherwise the memory will leak over time. To make things simpler, just call debugfs_lookup_and_remove() instead which handles all of the logic at once. Cc: Jens Axboe Cc: Steven Rostedt Cc: Masami Hiramatsu Cc: linux-block@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-trace-kernel@vger.kernel.org Signed-off-by: Greg Kroah-Hartman Reviewed-by: Bart Van Assche Link: https://lore.kernel.org/r/20230202141956.2299521-1-gregkh@linuxfoundation.org Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- kernel/trace/blktrace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index 918a7d12df8ff..5743be5594153 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -320,8 +320,8 @@ static void blk_trace_free(struct request_queue *q, struct blk_trace *bt) * under 'q->debugfs_dir', thus lookup and remove them. */ if (!bt->dir) { - debugfs_remove(debugfs_lookup("dropped", q->debugfs_dir)); - debugfs_remove(debugfs_lookup("msg", q->debugfs_dir)); + debugfs_lookup_and_remove("dropped", q->debugfs_dir); + debugfs_lookup_and_remove("msg", q->debugfs_dir); } else { debugfs_remove(bt->dir); } From patchwork Tue Mar 7 16:58:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 65760 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2573856wrd; Tue, 7 Mar 2023 09:57:45 -0800 (PST) X-Google-Smtp-Source: AK7set+H8Ly+CIn4tMcGybCD6yK6VMbpRq348Qq3wrDjhqNa7T0hTjvoWYQMG8X3HjZAVnv+5Zhd X-Received: by 2002:aa7:db53:0:b0:4b0:616d:48a8 with SMTP id n19-20020aa7db53000000b004b0616d48a8mr13996790edt.16.1678211864931; Tue, 07 Mar 2023 09:57:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678211864; cv=none; d=google.com; s=arc-20160816; b=GAXiuGVZ7dIgO1bSegBXi+VtakECa6DLKMufOnE0RMLQZJLc07QkgcMvJxQYQoZP5L ttGv2KVdE9A8jAGwH1AEuJhXkyHsCqezEXGtxJaUSOP/9/1lYTZ9yMU8tfo4wv+aabCG 00mPPRPJEyvBiY/izvGsoMH3lFZFz0ZyTC+3ioulV0oMybX4hrDZarBpkboSMhap6wgo e4eAbY+QwCJGTW+FshC2MghIdIjiO7CKONQswMjhXf46xAZojOYf9DBPTPJzHfjhly1f 4EBmXks12OLjwYwkAQx0NmBWMTm3PMQoxZOeJXvYGzNYTE++0uiBOPf/n0oKG/uOqkKc ZTKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=R4pGadYGATpGMQi5KZfDbpTZoaAeAuygWcB9LzBFGzA=; b=XfeE60UUVwENYybc0goRnj6kraZ9g0JqAMBcEqEZhVuxMKdM5rCa70C/9jgwsQTGYD Vm4T2zDEnuJAxdRk5T5UF4HSuInDVJs2EVSMAjmIRzJcUMtyAUPk8yyrjbfkMtRoOLTk ILx2XW25Gxb5f6S2hCxgPLK9iS5sZwziuz2v7+bBFm/VEOM20ovm2Yo/cAFRrSYz7S4P ixzzlggkCY8xQBHG5JLJBtTV2mQWOqzeKK+yrxsrwI7UDVPSSkDTSkJ14kaD79PbvuGY ty1cozHcVbX7RE+T5a9DKuMWoOCxkn21dP42az8VGTWBCOhdb14bnYcr7OfdeOjK2eBA 9hZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=b1RXqCRg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u21-20020aa7d995000000b004aadaa706ecsi10357826eds.169.2023.03.07.09.57.21; Tue, 07 Mar 2023 09:57:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=b1RXqCRg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232109AbjCGRux (ORCPT + 99 others); Tue, 7 Mar 2023 12:50:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231922AbjCGRuY (ORCPT ); Tue, 7 Mar 2023 12:50:24 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31808A0296; Tue, 7 Mar 2023 09:45:24 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C2FC5614E8; Tue, 7 Mar 2023 17:45:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B75CEC433EF; Tue, 7 Mar 2023 17:45:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1678211123; bh=eZhh6BSFQ1k6BW1csQ0X36HHVeHgWxg0M5U+VtotJqY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b1RXqCRggUynjMgz4L0pMspKQhydFmiEEDLdbxFZYVX+ACrpts+KdfanYIp4ZNDbW QSWuoGibFBKLsS/A1r28uTbJlGkELrXpTa8Y7Ov+HjSxvL7vG+cSQ5Qh6OZCUgly25 X5MWPiSPs5TGjkS7iKwwRh3PIVCG14yDaD4hA7Ts= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Karan Tilak Kumar , Sesidhar Baddela , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Sasha Levin Subject: [PATCH 6.2 0729/1001] scsi: snic: Fix memory leak with using debugfs_lookup() Date: Tue, 7 Mar 2023 17:58:21 +0100 Message-Id: <20230307170053.340405583@linuxfoundation.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307170022.094103862@linuxfoundation.org> References: <20230307170022.094103862@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759732684389197304?= X-GMAIL-MSGID: =?utf-8?q?1759732684389197304?= From: Greg Kroah-Hartman [ Upstream commit ad0e4e2fab928477f74d742e6e77d79245d3d3e7 ] When calling debugfs_lookup() the result must have dput() called on it, otherwise the memory will leak over time. To make things simpler, just call debugfs_lookup_and_remove() instead which handles all of the logic at once. Link: https://lore.kernel.org/r/20230202141009.2290380-1-gregkh@linuxfoundation.org Cc: Karan Tilak Kumar Cc: Sesidhar Baddela Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Greg Kroah-Hartman Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/snic/snic_debugfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/snic/snic_debugfs.c b/drivers/scsi/snic/snic_debugfs.c index 57bdc3ba49d9c..9dd975b36b5bd 100644 --- a/drivers/scsi/snic/snic_debugfs.c +++ b/drivers/scsi/snic/snic_debugfs.c @@ -437,6 +437,6 @@ void snic_trc_debugfs_init(void) void snic_trc_debugfs_term(void) { - debugfs_remove(debugfs_lookup(TRC_FILE, snic_glob->trc_root)); - debugfs_remove(debugfs_lookup(TRC_ENABLE_FILE, snic_glob->trc_root)); + debugfs_lookup_and_remove(TRC_FILE, snic_glob->trc_root); + debugfs_lookup_and_remove(TRC_ENABLE_FILE, snic_glob->trc_root); } From patchwork Tue Mar 7 17:00:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 65779 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2623813wrd; Tue, 7 Mar 2023 11:39:43 -0800 (PST) X-Google-Smtp-Source: AK7set/aSB3tyWfvoLNAh3HU6Nt0xopj0n/xs5EKxm/Z859NKG9ONm8k494Cp4yXXqteRj9jrt61 X-Received: by 2002:a17:907:c0c:b0:8af:2cf7:dd2b with SMTP id ga12-20020a1709070c0c00b008af2cf7dd2bmr20021425ejc.13.1678217983443; Tue, 07 Mar 2023 11:39:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678217983; cv=none; d=google.com; s=arc-20160816; b=vLLO1Kfk2F6D44xVUiNIWYLrrfEjC06jt5K6yTMCyMriUmBoWGa3XC1loclaGLb3/a jga8GhZWHUBWlhXVfsKSqZwZ/bjt/Bk8lzmIdhwS9dn4Uk6i6p7vfsvC6lbUjeYLiXVo fS+vqWfX4Flxw78qmoKiAl5/rdl625CRt7/ek3Cqi5c8vDTXZhVZXGkN2+LnK1bPOLGx VDMFomtXiTZ+NFJp2mM8GvtcPS93ExDu031k3/vuA0i053yqUmUZYM5mvxw8lQM4ZuqW AggxpUrXnZuQJ/7LMHTGJt1X+1g3nlV6s4dhjfFgI3gd//mU9u9IAh98du1XG9t7Lzzc FnGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FYHFfQzaxpiVfBr9Ol6aKTuHCCtuYhg59kJioGs6NF0=; b=FGG5M9Jciv5ozPgD16m2xwR30n69LaHsgg8XMcoV5OawZzPJBuexS2SSNVkrEhF3ac 0NGXw1cDwUg9ybhZEQkxnwQHdLA2tLx+5qOwJNjAybypyJCn1UPO5XYto3AU5RRPpz+u pLpSmJEeXI8KV+LV+qJwHbV3Ed0vrOT1ImGEtZ2zpXnx6dwx/rB8+i9at1LI7CoIcpF7 99xbY0AkC8C6v2v0wv2ybfZyEd1vpUVLu64rt8EYMGObEsgkchx100USOm1lcWYpsTdR OmfZqHFINF9Z37TYgkX704qeY5+SKNi+IQEEF8j2c8NBQZWy61U6ab9IZms2edUKwgVy MT1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ayuyW1a4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e18-20020a17090658d200b008b194cc10acsi17510958ejs.381.2023.03.07.11.39.19; Tue, 07 Mar 2023 11:39:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ayuyW1a4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231825AbjCGRyn (ORCPT + 99 others); Tue, 7 Mar 2023 12:54:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230466AbjCGRyS (ORCPT ); Tue, 7 Mar 2023 12:54:18 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE46994F68; Tue, 7 Mar 2023 09:49:07 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 95DBA6150C; Tue, 7 Mar 2023 17:49:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E30BC433D2; Tue, 7 Mar 2023 17:49:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1678211346; bh=+M1gEsg3qEIv515pBeyxMHFtrxXp6A5XzXwfNBlR9Zo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ayuyW1a4AeqVn0puUPO6lGfTmriye8wkvkSK/4ASJXZ2qIEmGn6HekvZQAG/7k6YZ dIsNSaw+GpGqPPFFpU9VRkr2Ri2LjM9h6eisnnTRQ/zULEBCzRMUxPDKC6mow/Dy4m EjN46CuHUGtZwbFDXrSfDRTAwAN6hT6+hlxfYGUg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Andy Nguyen , Thomas Lendacky , Peter Gonda , David Rientjes , Paolo Bonzini , Sean Christopherson , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6.2 0833/1001] KVM: SVM: Fix potential overflow in SEVs send|receive_update_data() Date: Tue, 7 Mar 2023 18:00:05 +0100 Message-Id: <20230307170057.940444308@linuxfoundation.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307170022.094103862@linuxfoundation.org> References: <20230307170022.094103862@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759739100207348269?= X-GMAIL-MSGID: =?utf-8?q?1759739100207348269?= From: Peter Gonda commit f94f053aa3a5d6ff17951870483d9eb9e13de2e2 upstream. KVM_SEV_SEND_UPDATE_DATA and KVM_SEV_RECEIVE_UPDATE_DATA have an integer overflow issue. Params.guest_len and offset are both 32 bits wide, with a large params.guest_len the check to confirm a page boundary is not crossed can falsely pass: /* Check if we are crossing the page boundary * offset = params.guest_uaddr & (PAGE_SIZE - 1); if ((params.guest_len + offset > PAGE_SIZE)) Add an additional check to confirm that params.guest_len itself is not greater than PAGE_SIZE. Note, this isn't a security concern as overflow can happen if and only if params.guest_len is greater than 0xfffff000, and the FW spec says these commands fail with lengths greater than 16KB, i.e. the PSP will detect KVM's goof. Fixes: 15fb7de1a7f5 ("KVM: SVM: Add KVM_SEV_RECEIVE_UPDATE_DATA command") Fixes: d3d1af85e2c7 ("KVM: SVM: Add KVM_SEND_UPDATE_DATA command") Reported-by: Andy Nguyen Suggested-by: Thomas Lendacky Signed-off-by: Peter Gonda Cc: David Rientjes Cc: Paolo Bonzini Cc: Sean Christopherson Cc: kvm@vger.kernel.org Cc: stable@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Tom Lendacky Link: https://lore.kernel.org/r/20230207171354.4012821-1-pgonda@google.com Signed-off-by: Sean Christopherson Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/svm/sev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1293,7 +1293,7 @@ static int sev_send_update_data(struct k /* Check if we are crossing the page boundary */ offset = params.guest_uaddr & (PAGE_SIZE - 1); - if ((params.guest_len + offset > PAGE_SIZE)) + if (params.guest_len > PAGE_SIZE || (params.guest_len + offset) > PAGE_SIZE) return -EINVAL; /* Pin guest memory */ @@ -1473,7 +1473,7 @@ static int sev_receive_update_data(struc /* Check if we are crossing the page boundary */ offset = params.guest_uaddr & (PAGE_SIZE - 1); - if ((params.guest_len + offset > PAGE_SIZE)) + if (params.guest_len > PAGE_SIZE || (params.guest_len + offset) > PAGE_SIZE) return -EINVAL; hdr = psp_copy_user_blob(params.hdr_uaddr, params.hdr_len);