From nobody Thu Dec 18 12:44:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BAF8C32772 for ; Tue, 23 Aug 2022 09:14:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348616AbiHWJOX (ORCPT ); Tue, 23 Aug 2022 05:14:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349098AbiHWJLL (ORCPT ); Tue, 23 Aug 2022 05:11:11 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40B17286D5; Tue, 23 Aug 2022 01:31:30 -0700 (PDT) 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 7E4EC6132D; Tue, 23 Aug 2022 08:31:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8281FC433D6; Tue, 23 Aug 2022 08:30:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661243459; bh=cFQps2UgGzKfxxucgJAhHcyTCzeTMbAGguhyK1OacKw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CWF1Z9nhrRlE6ZAXegC8VGI0H8NWto1hBTRZV/TIZMNltDrWskq9wuxAGEgMg+Mcn w/wNCxJaVBdcv+6CkmIlD+p151jLkIbtxBdB/CyQ6GyBlCGop3dhq6I5w+r2rHbZyr ELljfYUD62v/s/MbEumOMBiTvipS6XLKLI7pE77M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Justin Tee , James Smart , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.19 284/365] scsi: lpfc: Prevent buffer overflow crashes in debugfs with malformed user input Date: Tue, 23 Aug 2022 10:03:05 +0200 Message-Id: <20220823080130.060142264@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080118.128342613@linuxfoundation.org> References: <20220823080118.128342613@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: James Smart [ Upstream commit f8191d40aa612981ce897e66cda6a88db8df17bb ] Malformed user input to debugfs results in buffer overflow crashes. Adapt input string lengths to fit within internal buffers, leaving space for NULL terminators. Link: https://lore.kernel.org/r/20220701211425.2708-3-jsmart2021@gmail.com Co-developed-by: Justin Tee Signed-off-by: Justin Tee Signed-off-by: James Smart Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/lpfc/lpfc_debugfs.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debu= gfs.c index 7b24c932e812..25deacc92b02 100644 --- a/drivers/scsi/lpfc/lpfc_debugfs.c +++ b/drivers/scsi/lpfc/lpfc_debugfs.c @@ -2607,8 +2607,8 @@ lpfc_debugfs_multixripools_write(struct file *file, c= onst char __user *buf, struct lpfc_sli4_hdw_queue *qp; struct lpfc_multixri_pool *multixri_pool; =20 - if (nbytes > 64) - nbytes =3D 64; + if (nbytes > sizeof(mybuf) - 1) + nbytes =3D sizeof(mybuf) - 1; =20 memset(mybuf, 0, sizeof(mybuf)); =20 @@ -2688,8 +2688,8 @@ lpfc_debugfs_nvmestat_write(struct file *file, const = char __user *buf, if (!phba->targetport) return -ENXIO; =20 - if (nbytes > 64) - nbytes =3D 64; + if (nbytes > sizeof(mybuf) - 1) + nbytes =3D sizeof(mybuf) - 1; =20 memset(mybuf, 0, sizeof(mybuf)); =20 @@ -2826,8 +2826,8 @@ lpfc_debugfs_ioktime_write(struct file *file, const c= har __user *buf, char mybuf[64]; char *pbuf; =20 - if (nbytes > 64) - nbytes =3D 64; + if (nbytes > sizeof(mybuf) - 1) + nbytes =3D sizeof(mybuf) - 1; =20 memset(mybuf, 0, sizeof(mybuf)); =20 @@ -2954,8 +2954,8 @@ lpfc_debugfs_nvmeio_trc_write(struct file *file, cons= t char __user *buf, char mybuf[64]; char *pbuf; =20 - if (nbytes > 63) - nbytes =3D 63; + if (nbytes > sizeof(mybuf) - 1) + nbytes =3D sizeof(mybuf) - 1; =20 memset(mybuf, 0, sizeof(mybuf)); =20 @@ -3060,8 +3060,8 @@ lpfc_debugfs_hdwqstat_write(struct file *file, const = char __user *buf, char *pbuf; int i; =20 - if (nbytes > 64) - nbytes =3D 64; + if (nbytes > sizeof(mybuf) - 1) + nbytes =3D sizeof(mybuf) - 1; =20 memset(mybuf, 0, sizeof(mybuf)); =20 --=20 2.35.1