Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2120787lqb; Mon, 27 May 2024 08:29:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUKdG9q8wYZYx/9QuJG+pAd03J83RdB+eYpJ71MHEWChwUR5LU2nQfmX+fDf4t7fWUekqcY3uaJIXgMfs8/D5Bikxhcwm0hdnEnzN139g== X-Google-Smtp-Source: AGHT+IEYEvOmPAV6mOPuFp9IssrlIGCLIhdy9X8sm6NVZwHsb6LOvDLSZcINymNaaNAjUwlF7P0T X-Received: by 2002:a05:6358:52d4:b0:18d:8fd8:e523 with SMTP id e5c5f4694b2df-197e53174ccmr1364236455d.15.1716823740262; Mon, 27 May 2024 08:29:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716823740; cv=pass; d=google.com; s=arc-20160816; b=I3/HUJBizA27ncsm0y2PvjCiGRLwWW37Q8HWc5sHnHOuwelIEjgUCoSBOWh/kdpeSm VZDltqIhNQA6v3GGwWURKOdqtvLzz7ZuC0G72FEBA0LE1NnkJEqZNpkvNgiuJeFYxhhQ iP3h3vtOcfBsgNCLqoVcIo8Q4GZ1X1xSyL/KVH6pk3x+XOfNqLeJ9Nz5xWETXRwnKsDQ 55NF25cF4Tnj093MBqWoqEt5HvJfCydIFcdAL58nX2ooBmcpJGnm9OisSCavEez9rHF0 6BfTHltvUozI5rLq9ihxPqsdDvB0J+mIvLnNVcKVAzHGOKyyj3Gm3Yfy0qM9K8WEWNXV /SPg== 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=cDqTgKg7Dkbr1B4FS9eXvqGyoi0G3xe7r/eaFQRWuEkbFMb0SztNF2aK3vFrV3fRlp Yg0bx+u6wwG3nRTQ+f1bcgMuYxLnMoe2xBupAmbTLIoGlwwGo6mPUz/EPxefjZ53eJ0X 4+yCe4dLh8oYQCBjlgp/utsuGhE4FFHUvNW3l15l0jHfRs4z8pmKJSopIU7a5RTLpMwe 3wgUgXiC+Si9IZfP4wleO0pv5VnpCNdZuSs8RPv5SxWmqFn15SiZ4y7Q3tjo4/m66q+4 ypiR3+5rLlR2yZ81dSkDuvoDWjxKCdOVgDzjzGZqF4qETCzDUQjTzD4Mm5KDHs+LYRgw fZoQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OrswxXR0; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190931-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190931-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-6822ae582d7si6647470a12.817.2024.05.27.08.28.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 08:29:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190931-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=OrswxXR0; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190931-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190931-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 0B23AB33333 for ; Mon, 27 May 2024 14:48:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AB1AA167D86; Mon, 27 May 2024 14:19:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OrswxXR0" 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 CE448167296; Mon, 27 May 2024 14:19:27 +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=1716819567; cv=none; b=tfDQxzviIo+n4tsa5plIiGb4wbPr5zRj1u8THl9BAReU+EqO6cYv1Rl16WT6ocW35Cn9wqZk8/PfzuatQNrtSbd2l2OtGSFK4ZJ3eLEeJ8BmC0SXxYhc92YO4JfOC0yWUEvMuQCUE07fAOIVHBPxZ7ZspeaHU+vK659on76+Ob0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716819567; c=relaxed/simple; bh=J8uClXr1sJc5Omn1C8LtHID4JkPQqEiIvsApn4DMkQM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PYz9KCqXQAroEgZIOw+pOX0umg8qtXW1QbjJvcxA7SxL9+YjCaToodbi7jcrS/wGDz4claFphtjfCCjeFitUhnss5rVL32SF10VjtA/AVWKhvb0QrFUNVCJS93rHph79zyEzH6/thBsn8D1EPapAPtAFbnPUiebRN+PVw2W1uMk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OrswxXR0; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2ED31C2BBFC; Mon, 27 May 2024 14:19:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716819567; bh=J8uClXr1sJc5Omn1C8LtHID4JkPQqEiIvsApn4DMkQM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OrswxXR0RZhbhgBYYQavbK/lpX8qqYK0K1QajttWXSu41xFEr9JLorwbtxTXPOx0b j3SxR7KJz2ibJhO8y7FfQg9XnFkHcf8GTPajgA5N89DIkfqSsvQafWhKDC5CeBQd6L 0DQkjnN4nNYZFaiDVqauH3Q+1JoqeGQsmc8PRLlgQfaUfOt2GB2CRabiHpaz7JgyFC pQtP/vMhQwPKMK8kLlXrT2AQCRH47v2MXyaWrktVNxe71D77eWRK25uArHNst5JjiN tv7A/ubRHVpQUR8fjGvOqazOWIatyp6tIif67u1cIN307YeAVedPJLJ5NOskf9Y8VJ yHKhls6EK327Q== 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.10 07/13] scsi: qedi: Fix crash while reading debugfs attribute Date: Mon, 27 May 2024 10:18:44 -0400 Message-ID: <20240527141901.3854691-7-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240527141901.3854691-1-sashal@kernel.org> References: <20240527141901.3854691-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.10.218 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