Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2085149lqb; Mon, 27 May 2024 07:25:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWpmc+0ijHhwJMjYYYcf0mZVlWDJwy50vE4p7PGCBeuSsEs97Ek3GEBELiPT7JGlKiFiAGd6RnOoZilAZPGesfa8v7CjZYSBBRN5rAHRQ== X-Google-Smtp-Source: AGHT+IGB36Rte0FlbDK0tTmIR7gxs/uW9gxKXE8K5Dt0bK2dZBk1hB3zRPwLY4kZ4dmCa11UoKG7 X-Received: by 2002:a05:6122:3c54:b0:4d8:4a7f:c166 with SMTP id 71dfb90a1353d-4e4f02d957dmr9526346e0c.12.1716819953058; Mon, 27 May 2024 07:25:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716819953; cv=pass; d=google.com; s=arc-20160816; b=X9zmcMXKzV8EIrc71XVoUZWoEI2OuibiIK6rohonskYMrefuQePEqiDXACyRbBZBM5 kXw5GpXHomtQLiM5DO1V7aqOeYsIIb6dU7cQR6vz0umM6xTj6vwrTJ7skbvcF0hVB7E9 HbblV2hS+k38+wxLjExCJFooyda7Abs1QijZnF/kt5Pep2wabwlZliBUr6ZvAVdK6C9r egNY2wM3P8tAUe0AKZOzv1fSiKO338w8muJxAQ0YDQIZS6ppNbjlHEEhiiH+tgGmnIo2 oyruYa4gq+2ImvDio6AEyufNjB5N41WETOACt6vKOtOqSUhmYAEyP0lpRA+TkZiBu1bI Uwzw== 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=B7Gklf0KDhd4/lg760NLJakc4RrFwre4XkVGt3uhldQ=; fh=jbBpQ8f+THBDy93uM+aqoj3LwltIlYOA7BzcoKLa5Jg=; b=uRd2GMo0vDkhMVyIvofLKgPfixyKvp2cAgEh/uYqJoTSxTmaYLX4G7P+jhCDp2o2m+ q1/Clbit/uXNe13kOti5V8PT+khr1XNTH9SF9iS/YNN4jxdBrHh/v69Lyef1QhdR6sj8 kTggtaWkU9PQ/LihBMq5sW1xEbQI1ffEeVvxcpubTgRjo0ScfJEFh8Ofb+e3vE8ZYyBM eNP747j5X9RPbc4Ub7i43BG9OTefrR9UHXw/JOI+X8CNOtsJJUfNbcLSCthrYwi98bSi 8289GYL2LAT/W7Nuvzy6g8BxTVhwLxQFCWdABg9Ko3BFk/MXt3PK/6kwxHmkHX5CRvWr 95AQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Wck8f/8u"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190849-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190849-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ada2fe7eead31-48a3a206c84si1837492137.43.2024.05.27.07.25.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 07:25:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190849-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Wck8f/8u"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190849-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190849-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B26F51C218C8 for ; Mon, 27 May 2024 14:25:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 52C6B175549; Mon, 27 May 2024 14:14:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Wck8f/8u" 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 71980174EE1; Mon, 27 May 2024 14:14:43 +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=1716819283; cv=none; b=DKjfeYyZE7PIZ9EkNGitYUPdEO3/uy1T7yNy/u/JmAYVOSGP7jPbW2YRbTVpp8U5qHa3ZPJx9BQ5eRjiMKM4guxxkSKMvYpnd1prsXIebhKbIXTTUfs3H539L4JAcbZp90Jm6W12h/agD4H0rcG+kxgjvskwECQuzKtRMGkeZGk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716819283; c=relaxed/simple; bh=tNphdjirBb9tdMxisUu7AmYR16l1TQhNBoK7qKrb16g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WqTnIMD5BjCVtGeQWos7hf232i9huxkH7NXA2r8+IDXPYUEnH2LyKFdpavgBk3RhXOHUN5c1u+1sWRJvtNcgPtdh7BMVta2vp7Zc+32BerhSJW6UnLNy74jfz5UwunXRHKMMoq73I7o2tV8T7V90Ff58KEuS21uVJShv6QjyLME= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Wck8f/8u; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26F5AC32789; Mon, 27 May 2024 14:14:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716819283; bh=tNphdjirBb9tdMxisUu7AmYR16l1TQhNBoK7qKrb16g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wck8f/8u/nAiP5aiFrKoZD2SIq8vRSVjUMOd450JWwdd1vSeAPxLECnqiOmlSeeHn Ti4feHAF5LiRzIZzOlnqoV9//gSqySVPKWtL70fosEKfwaVwBHxg+EZAuga/K5oUz2 +V6FvE2mxO1vcm4wFRqsKpLFSJdLTE5X0IfUgiIfCCYmRsDmdg0rnty+ZkFILkKo2G uaOAh/uqwE2KUOuYhc83tCSjl6Hnd6Cgcsi+6cnwOAXeusFuq2If5Fg8PVLwpojdgH IQ6BEp8bVIwdPXTrPdjNBPwNNnkx/RhSlpGVwqcQezikoGim4SZxcjcmSmCfJRzvKl Z2KbczEcplt/Q== 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 6.8 13/30] scsi: qedi: Fix crash while reading debugfs attribute Date: Mon, 27 May 2024 10:13:22 -0400 Message-ID: <20240527141406.3852821-13-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240527141406.3852821-1-sashal@kernel.org> References: <20240527141406.3852821-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 6.8.11 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 8deb2001dc2ff..37eed6a278164 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