Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2128608lqb; Mon, 27 May 2024 08:43:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVkF+bU7sQJB/BI0dQEYeT8rzRTjmlte0KU9XZuz+BM3JAjOXr5wzIgl+XXboq5AiXArzZ44dqQyfcPbjgI/12FZsFDs6Svchqnai6YNQ== X-Google-Smtp-Source: AGHT+IEHomaXnrSCo34ck5pW4PcjR0SUlB7Xt8X5xk8pg64aHFltzkQTh0KODV6oC/xq/SGMmqtH X-Received: by 2002:aa7:9a84:0:b0:6f3:89d3:cb1c with SMTP id d2e1a72fcca58-6f8f370389cmr7811353b3a.16.1716824617803; Mon, 27 May 2024 08:43:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716824617; cv=pass; d=google.com; s=arc-20160816; b=KUECNpSjP+Przn5HkC9FT0wRpM0+tA1mePi4JV3tTen/0z8yzS2ZuCe2dDe5DGczzW S1g+a7fULt8T6HikGSX9AAQOfpHX3kBOtUGQPR/FrkVS3ds/tzY/ly8hJv5ZXrAQ7jIm BkxLaT5JCAaas0t3X1bb+slR4UiLMpLSj9FzYq+XQ7ybGgslW0OYSnwSKt7xDlDbuWGJ 9YdZEhIdjvGHXy2dAVNWhcfh8LfO9SF92LPib/Egq+tlh9lSG8k3Eo7WhsVt0fPZyP2+ 9avb7tEPi8z2+WFRXZyW2cUBtjsYMeIF0ABySt2SRsNSIjs8QLDj8n5j9Mb1EuCmj0LE +QCw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=HoWrSy4ylm1wPV9yoBi19m+XXunEBpfSZdyOASbJaEg=; fh=jbBpQ8f+THBDy93uM+aqoj3LwltIlYOA7BzcoKLa5Jg=; b=SErqJixH/3DYpeNsJt+lDFawBVRLyqUBEuFgW7FkYTTjAGL5jqzVGiymG6QYj+ssqD zNQWm04TUWSQ+2iIUuvPtWYVCCLPEaqPv1PUxdoeclKsNFmedyfX3XoeZHS4gCkICnXo +VMR8KVbCcndOiKSPbfTzaI7mEtP93t1jaIiJosD3RWtOYjqTr7HK7mX53TgBaWE1SQ9 L8BnE6LjnXdSvT6Zye9o2d/a2zN+uePK0lmmldZ/Uftzj6UIOVdhvJOlPCmocib1thsQ a58a5k7pdeeDwGjWaTODMGHWWaLOPmz8opGJdvPbgPdutKawvF8lzCX6S+0ttwqyMK6C ObUQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BINMyKNN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190941-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190941-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-6822b234f80si6844822a12.869.2024.05.27.08.43.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 08:43:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190941-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BINMyKNN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190941-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190941-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 862E5B3353E for ; Mon, 27 May 2024 14:52:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 367E416B728; Mon, 27 May 2024 14:19:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BINMyKNN" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 506E616A39E; Mon, 27 May 2024 14:19:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716819598; cv=none; b=qqz03EwpsGxyLTdnpMpoWb7jxImP7Ba1u/rjoSO0MySe6azt8fSfoi0UPYvW0lALSVUKUrpl2odEbnYWJzT6sPgvd9r3PcO+T41FFDW7mXhxyuQoyRYr9B2JnwjxMzTpJUHfPo+WM+cITrVwrwPdKovYExc6Xmh9dS0Ve7TzIig= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716819598; c=relaxed/simple; bh=J8uClXr1sJc5Omn1C8LtHID4JkPQqEiIvsApn4DMkQM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ogz639TnQ6wUNZV+ercyogHuTUolp2lMWcUx8/23t650ty0jRnXN9o388+imxkBV1lonVFN5xRuiXgirkwdG539K70okwLkzBj7WGc0TeDv4cKgSaEYa93giy2Or820WWlzSsfSsYDSRgfs8PY+w5xrrqdXu/N5cDBRIaCvT62Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BINMyKNN; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 996C2C32781; Mon, 27 May 2024 14:19:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716819597; bh=J8uClXr1sJc5Omn1C8LtHID4JkPQqEiIvsApn4DMkQM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BINMyKNND89gNEnoDkuH1JhJIzuH0CjVIHvIF0wVHHCnYBcVQNjvQ4TZWi79lJo50 YPbOeRmibONWyoT5zqxbVjqimJN9a15ETn500vQGc9CDd7/QmtpBcvwpvYyVDQEDKv Ec9gn+FMMvxG1piNQwuzwb+5IXMZ/Q0nGBnVxSD3FJNoUw/IU+swSy7Cvx398Fr92Q zhAqVsU+cXkuY+YgPt5+y6pdTH7/Cj/56enAxjzW6pWsa+5RWkT4FqXsKdKPi3wKXd KOwb5qj3rqdu95ypqGhLKPGlq4CWQ/l0761oUdRIYNtYO0oU0Gg4LRjVaxsOXV05Fo Yteuat+tOJXWA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Manish Rangankar , Martin Hoyer , John Meneghini , "Martin K . Petersen" , Sasha Levin , njavali@marvell.com, GR-QLogic-Storage-Upstream@marvell.com, James.Bottomley@HansenPartnership.com, linux-scsi@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 4/6] scsi: qedi: Fix crash while reading debugfs attribute Date: Mon, 27 May 2024 10:19:41 -0400 Message-ID: <20240527141950.3854993-4-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240527141950.3854993-1-sashal@kernel.org> References: <20240527141950.3854993-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.4.277 Content-Transfer-Encoding: 8bit From: Manish Rangankar [ Upstream commit 28027ec8e32ecbadcd67623edb290dad61e735b5 ] The qedi_dbg_do_not_recover_cmd_read() function invokes sprintf() directly on a __user pointer, which results into the crash. To fix this issue, use a small local stack buffer for sprintf() and then call simple_read_from_buffer(), which in turns make the copy_to_user() call. BUG: unable to handle page fault for address: 00007f4801111000 PGD 8000000864df6067 P4D 8000000864df6067 PUD 864df7067 PMD 846028067 PTE 0 Oops: 0002 [#1] PREEMPT SMP PTI Hardware name: HPE ProLiant DL380 Gen10/ProLiant DL380 Gen10, BIOS U30 06/15/2023 RIP: 0010:memcpy_orig+0xcd/0x130 RSP: 0018:ffffb7a18c3ffc40 EFLAGS: 00010202 RAX: 00007f4801111000 RBX: 00007f4801111000 RCX: 000000000000000f RDX: 000000000000000f RSI: ffffffffc0bfd7a0 RDI: 00007f4801111000 RBP: ffffffffc0bfd7a0 R08: 725f746f6e5f6f64 R09: 3d7265766f636572 R10: ffffb7a18c3ffd08 R11: 0000000000000000 R12: 00007f4881110fff R13: 000000007fffffff R14: ffffb7a18c3ffca0 R15: ffffffffc0bfd7af FS: 00007f480118a740(0000) GS:ffff98e38af00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f4801111000 CR3: 0000000864b8e001 CR4: 00000000007706e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 PKRU: 55555554 Call Trace: ? __die_body+0x1a/0x60 ? page_fault_oops+0x183/0x510 ? exc_page_fault+0x69/0x150 ? asm_exc_page_fault+0x22/0x30 ? memcpy_orig+0xcd/0x130 vsnprintf+0x102/0x4c0 sprintf+0x51/0x80 qedi_dbg_do_not_recover_cmd_read+0x2f/0x50 [qedi 6bcfdeeecdea037da47069eca2ba717c84a77324] full_proxy_read+0x50/0x80 vfs_read+0xa5/0x2e0 ? folio_add_new_anon_rmap+0x44/0xa0 ? set_pte_at+0x15/0x30 ? do_pte_missing+0x426/0x7f0 ksys_read+0xa5/0xe0 do_syscall_64+0x58/0x80 ? __count_memcg_events+0x46/0x90 ? count_memcg_event_mm+0x3d/0x60 ? handle_mm_fault+0x196/0x2f0 ? do_user_addr_fault+0x267/0x890 ? exc_page_fault+0x69/0x150 entry_SYSCALL_64_after_hwframe+0x72/0xdc RIP: 0033:0x7f4800f20b4d Tested-by: Martin Hoyer Reviewed-by: John Meneghini Signed-off-by: Manish Rangankar Link: https://lore.kernel.org/r/20240415072155.30840-1-mrangankar@marvell.com Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/qedi/qedi_debugfs.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/qedi/qedi_debugfs.c b/drivers/scsi/qedi/qedi_debugfs.c index 42f5afb60055c..6e724f47ab9e8 100644 --- a/drivers/scsi/qedi/qedi_debugfs.c +++ b/drivers/scsi/qedi/qedi_debugfs.c @@ -120,15 +120,11 @@ static ssize_t qedi_dbg_do_not_recover_cmd_read(struct file *filp, char __user *buffer, size_t count, loff_t *ppos) { - size_t cnt = 0; - - if (*ppos) - return 0; + char buf[64]; + int len; - cnt = sprintf(buffer, "do_not_recover=%d\n", qedi_do_not_recover); - cnt = min_t(int, count, cnt - *ppos); - *ppos += cnt; - return cnt; + len = sprintf(buf, "do_not_recover=%d\n", qedi_do_not_recover); + return simple_read_from_buffer(buffer, count, ppos, buf, len); } static int -- 2.43.0