Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2094967lqb; Mon, 27 May 2024 07:43:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVPzr2FXx0UWHeSJnWy3d+g0FefOPI24bpMPWMavVUW+caR3rvJf9iCCTCNH9fiIg7hkopb5rAriUCKHNkI0ExKRqqOTslx8D4NmiTv2w== X-Google-Smtp-Source: AGHT+IH3t6m4zfAb7DRtEJzIygUgcr3wpMALzBspMfejbBmjOrduPxFDuHFvjSAdLAdiDb6Vq4/L X-Received: by 2002:a17:903:24e:b0:1f3:62c:247f with SMTP id d9443c01a7336-1f339f0a2afmr159608835ad.11.1716821024380; Mon, 27 May 2024 07:43:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716821024; cv=pass; d=google.com; s=arc-20160816; b=M0K/aw4eTlZr8ZeWvucloGRvaPDW3mN+AaJ5gCLKc0L7ZHsEb4YnxRPwOEQyOEVSIW f5wkWNO0aIL0A/JymWfhqw1zw+z7OM1Pgg0Q0W8yOYHpOTRbuouKfwZjqwdCu7+Fa7wJ 923mQ9rzgW7eqMZ9572rKRGr3e7nGbJ8p3S5nw1dfbjwAFsm2sakyBuZjhXChKB8+0as dyiTSChR5/PbsH4qNW2auGeWjwkHX6jsqlf9txjs/aOdQ9zAppMpGznBLEM439wxE04p Yj0Wen/yesfI78MkHVjFxeVqMBs7fFuMH+JoXNXvTLCZ4Mev3ZfoZmEIt0XUmTVb9n7Q JjJQ== 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=Ligc76eeUisaBF7ypwso+HzhTDurcE+3PzVeKmsChT283Lgf4jkt6ESZgiaOySHStS 6LFrp87NSAfzhMGel+V12LAzM4pGpOCylosGSSMOAIrCyxCP6/7cC1rVWdTPSsbmCXO1 HzkKaiRYzTJ/jSc2llUOSPTqjG6EOcZ5/nX/1pxFcbQgkgnAmSkp8WzoMk8ZDsDoplKl wr9QeyGSb9RXaphRGt5kMkGPd6hyUFWkTvHJCuMaaS7T1E+3BSroEV2/X3foEC+aVd9Q doUBKxsrExU+M6SK52F7zm/r04ie0ymp5tdeeagXimHtOGmBYE35l2wMdrZsvnResTo/ 7AkA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pz8pfjDf; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190918-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190918-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f44c9bb747si42623995ad.473.2024.05.27.07.43.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 07:43:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190918-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pz8pfjDf; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190918-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190918-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 06C25382070 for ; Mon, 27 May 2024 14:43:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E82DD61FD3; Mon, 27 May 2024 14:18:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pz8pfjDf" 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 179C621C18D; Mon, 27 May 2024 14:18:33 +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=1716819514; cv=none; b=JqeXPx4e8O8lnAPkEdffr+FQT2D/vAEPH8BcfjH9rTFoUPDeD3WHmM37TnB091AJ+Lmg+hJCqEEkHPr6rSP413HCHjS66rk20MAjXgZ/Jlki1ZXqescdL+VYs0ETnajiznb8oGfojozTVrW4OV/5APB0/akOz2sv9b0BkoxJCsc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716819514; c=relaxed/simple; bh=J8uClXr1sJc5Omn1C8LtHID4JkPQqEiIvsApn4DMkQM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tDliafKk50AsqUsc2CsP9Z2/hr5UTAmeGA30/YEgJOt4x4QN6RHxFQlKI2NNyGvMFHkmijVS5SSci6arEOnYvojLS9GeD8qNQoU6g4BfaH84Nxm7SkZRjk2sljvTVjFzRZ9RmlWj63p3WebfXpLXSD2AjL0ocC7sdLU/1TsTUCU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pz8pfjDf; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D94BC2BBFC; Mon, 27 May 2024 14:18:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716819513; bh=J8uClXr1sJc5Omn1C8LtHID4JkPQqEiIvsApn4DMkQM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pz8pfjDfRMQDAL0sSAExKc2kx5hIsdQqtEOtJ8Acm6evyofXn/ah/ZU0Tyc3IePxP HufMZWCgN3plMpRvuO+3769aVxHedxY8/usE/Uz3Yx2xRJmWE5tYyk1H5v4m+wsswQ 1YoWJI+G38tp6X04vmTGZ+e58ebJc0DEOybjXfgijV83tkyOlxQeVwVL4ORBIFtjbG xgUdKEC4VNXiqpIeCSirxkSWF3aCGnyvo9Rq4MThol0qToAg2wo3m35ikGTKPBjbsk Lzuqukj6E8O82/Ms+c2G6itXDheODjTUomq5NA3/0YjTR7uxFubatiNjp84qBP4OfM H8KCwpoFylUKw== 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.15 07/13] scsi: qedi: Fix crash while reading debugfs attribute Date: Mon, 27 May 2024 10:18:01 -0400 Message-ID: <20240527141819.3854376-7-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240527141819.3854376-1-sashal@kernel.org> References: <20240527141819.3854376-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.15.160 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