From nobody Sat Feb 7 17:48:48 2026 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 6C6B3C04A94 for ; Mon, 31 Jul 2023 08:45:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231578AbjGaIpH (ORCPT ); Mon, 31 Jul 2023 04:45:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229978AbjGaIo1 (ORCPT ); Mon, 31 Jul 2023 04:44:27 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66C831AC for ; Mon, 31 Jul 2023 01:40:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690792847; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1FE1ufQGk4FRdYyxGSofHwL0Yu7YL6ku1l84mtlMcQY=; b=HPEv8Jwt3WeWez5XjhxJJ7jkHlJ+QckgufDM2tt9lFpdk9mdSm+nG3m+8Bj9dTpXbt0/36 ooFnSnWtktluza3wT1TlBdMjOonfJiXMqAnPJl669kSrB/ot6NEiNCaoRqO2IeziHY1qLk hj2acgiCN3nscyIaZ/c2PewcgRNF0Sc= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-212-dZtD3UxHMwCo_QzldOKC7Q-1; Mon, 31 Jul 2023 04:40:43 -0400 X-MC-Unique: dZtD3UxHMwCo_QzldOKC7Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 156DD3815EE3; Mon, 31 Jul 2023 08:40:43 +0000 (UTC) Received: from localhost (unknown [10.45.224.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id C463BC57964; Mon, 31 Jul 2023 08:40:36 +0000 (UTC) From: Oleksandr Natalenko To: linux-kernel@vger.kernel.org Cc: linux-scsi@vger.kernel.org, Saurav Kashyap , Johannes Thumshirn , David Laight , GR-QLogic-Storage-Upstream@marvell.com, "James E.J. Bottomley" , "Martin K. Petersen" , Jozef Bacik , Laurence Oberman , Rob Evers Subject: [PATCH v2 1/3] scsi: qedf: do not touch __user pointer in qedf_dbg_stop_io_on_error_cmd_read() directly Date: Mon, 31 Jul 2023 10:40:32 +0200 Message-ID: <20230731084034.37021-2-oleksandr@redhat.com> In-Reply-To: <20230731084034.37021-1-oleksandr@redhat.com> References: <20230731084034.37021-1-oleksandr@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The qedf_dbg_stop_io_on_error_cmd_read() function invokes sprintf() directly on a __user pointer, which may crash the kernel. Avoid doing that by using a small on-stack buffer for scnprintf() and then calling simple_read_from_buffer() which does a proper copy_to_user() call. Fixes: 61d8658b4a ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver fra= mework.") Link: https://lore.kernel.org/lkml/20230724120241.40495-1-oleksandr@redhat.= com/ Link: https://lore.kernel.org/linux-scsi/20230726101236.11922-1-skashyap@ma= rvell.com/ Cc: Saurav Kashyap Cc: Rob Evers Cc: Johannes Thumshirn Cc: David Laight Cc: Jozef Bacik Cc: Laurence Oberman Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: GR-QLogic-Storage-Upstream@marvell.com Cc: linux-scsi@vger.kernel.org Reviewed-by: Laurence Oberman Reviewed-by: Johannes Thumshirn Tested-by: Laurence Oberman Acked-by: Saurav Kashyap Signed-off-by: Oleksandr Natalenko --- drivers/scsi/qedf/qedf_debugfs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/qedf/qedf_debugfs.c b/drivers/scsi/qedf/qedf_debu= gfs.c index a3ed681c8ce3f..3eb4334ac6a32 100644 --- a/drivers/scsi/qedf/qedf_debugfs.c +++ b/drivers/scsi/qedf/qedf_debugfs.c @@ -185,18 +185,17 @@ qedf_dbg_stop_io_on_error_cmd_read(struct file *filp,= char __user *buffer, size_t count, loff_t *ppos) { int cnt; + char cbuf[7]; struct qedf_dbg_ctx *qedf_dbg =3D (struct qedf_dbg_ctx *)filp->private_data; struct qedf_ctx *qedf =3D container_of(qedf_dbg, struct qedf_ctx, dbg_ctx); =20 QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n"); - cnt =3D sprintf(buffer, "%s\n", + cnt =3D scnprintf(cbuf, sizeof(cbuf), "%s\n", qedf->stop_io_on_error ? "true" : "false"); =20 - cnt =3D min_t(int, count, cnt - *ppos); - *ppos +=3D cnt; - return cnt; + return simple_read_from_buffer(buffer, count, ppos, cbuf, cnt); } =20 static ssize_t --=20 2.41.0 From nobody Sat Feb 7 17:48:48 2026 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 7667BC001DE for ; Mon, 31 Jul 2023 08:45:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229827AbjGaIpY (ORCPT ); Mon, 31 Jul 2023 04:45:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231621AbjGaIod (ORCPT ); Mon, 31 Jul 2023 04:44:33 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2D2F4698 for ; Mon, 31 Jul 2023 01:40:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690792848; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YgHQpEbLJguvAb28DMKBegK14yQyhVaGjEEtVU0RXL8=; b=gX+n2vIMxByPOz+Iru4gH/wF6seihStoCNTSDtKWeOBmXElh1thXL+htAioB0GilzC22Qp gp6B5K8higN9WuyyJMbgbcAVRPrF7+5R8B0H2smVyD8/I+o/e6TtCmvCU2QznGVTvFqJaL eWBUUhfittIs+OdTOGcBr0wAtPC4mD4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-611-Rt1tM8ssPnSEZoh2I2xJJg-1; Mon, 31 Jul 2023 04:40:44 -0400 X-MC-Unique: Rt1tM8ssPnSEZoh2I2xJJg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2930A88D120; Mon, 31 Jul 2023 08:40:44 +0000 (UTC) Received: from localhost (unknown [10.45.224.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id DAFC1401061; Mon, 31 Jul 2023 08:40:43 +0000 (UTC) From: Oleksandr Natalenko To: linux-kernel@vger.kernel.org Cc: linux-scsi@vger.kernel.org, Saurav Kashyap , Johannes Thumshirn , David Laight , GR-QLogic-Storage-Upstream@marvell.com, "James E.J. Bottomley" , "Martin K. Petersen" , Jozef Bacik , Laurence Oberman , Rob Evers Subject: [PATCH v2 2/3] scsi: qedf: do not touch __user pointer in qedf_dbg_debug_cmd_read() directly Date: Mon, 31 Jul 2023 10:40:33 +0200 Message-ID: <20230731084034.37021-3-oleksandr@redhat.com> In-Reply-To: <20230731084034.37021-1-oleksandr@redhat.com> References: <20230731084034.37021-1-oleksandr@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The qedf_dbg_debug_cmd_read() function invokes sprintf() directly on a __user pointer, which may crash the kernel. Avoid doing that by using a small on-stack buffer for scnprintf() and then calling simple_read_from_buffer() which does a proper copy_to_user() call. Fixes: 61d8658b4a ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver fra= mework.") Link: https://lore.kernel.org/lkml/20230724120241.40495-1-oleksandr@redhat.= com/ Link: https://lore.kernel.org/linux-scsi/20230726101236.11922-1-skashyap@ma= rvell.com/ Cc: Saurav Kashyap Cc: Rob Evers Cc: Johannes Thumshirn Cc: David Laight Cc: Jozef Bacik Cc: Laurence Oberman Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: GR-QLogic-Storage-Upstream@marvell.com Cc: linux-scsi@vger.kernel.org Reviewed-by: Laurence Oberman Reviewed-by: Johannes Thumshirn Tested-by: Laurence Oberman Acked-by: Saurav Kashyap Signed-off-by: Oleksandr Natalenko --- drivers/scsi/qedf/qedf_debugfs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/qedf/qedf_debugfs.c b/drivers/scsi/qedf/qedf_debu= gfs.c index 3eb4334ac6a32..1c5716540e465 100644 --- a/drivers/scsi/qedf/qedf_debugfs.c +++ b/drivers/scsi/qedf/qedf_debugfs.c @@ -138,15 +138,14 @@ qedf_dbg_debug_cmd_read(struct file *filp, char __use= r *buffer, size_t count, loff_t *ppos) { int cnt; + char cbuf[32]; struct qedf_dbg_ctx *qedf_dbg =3D (struct qedf_dbg_ctx *)filp->private_data; =20 QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "debug mask=3D0x%x\n", qedf_debug); - cnt =3D sprintf(buffer, "debug mask =3D 0x%x\n", qedf_debug); + cnt =3D scnprintf(cbuf, sizeof(cbuf), "debug mask =3D 0x%x\n", qedf_debug= ); =20 - cnt =3D min_t(int, count, cnt - *ppos); - *ppos +=3D cnt; - return cnt; + return simple_read_from_buffer(buffer, count, ppos, cbuf, cnt); } =20 static ssize_t --=20 2.41.0 From nobody Sat Feb 7 17:48:48 2026 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 9D1BCC001DE for ; Mon, 31 Jul 2023 08:45:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231877AbjGaIp2 (ORCPT ); Mon, 31 Jul 2023 04:45:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231784AbjGaIoe (ORCPT ); Mon, 31 Jul 2023 04:44:34 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54EEB46A5 for ; Mon, 31 Jul 2023 01:40:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690792851; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bLpuuQXqbdvIXV/TOWefk7mBtffNE7xC4rEJrxjA0zc=; b=AO/kE4sFMmKp1xs/FnA3TJLuuoupove+9j5rSJteSrE1YUhvNiXTbcDsJoZDYY3bSYo8iF BzgIq0mw5ecYH04Msnd9SmZD7j29no757VUpPvwRit2OHMwBVky2k+ldXQr4/htv1CkQ7Q DcfjDBPFfwBYE1mHTetLWNP0pwB6aHE= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-634-Dvjo4e2uPUG7rYGYqupZWg-1; Mon, 31 Jul 2023 04:40:45 -0400 X-MC-Unique: Dvjo4e2uPUG7rYGYqupZWg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1E8931C2C5AF; Mon, 31 Jul 2023 08:40:45 +0000 (UTC) Received: from localhost (unknown [10.45.224.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1F432166B25; Mon, 31 Jul 2023 08:40:44 +0000 (UTC) From: Oleksandr Natalenko To: linux-kernel@vger.kernel.org Cc: linux-scsi@vger.kernel.org, Saurav Kashyap , Johannes Thumshirn , David Laight , GR-QLogic-Storage-Upstream@marvell.com, "James E.J. Bottomley" , "Martin K. Petersen" , Jozef Bacik , Laurence Oberman , Rob Evers Subject: [PATCH v2 3/3] scsi: qedf: do not touch __user pointer in qedf_dbg_fp_int_cmd_read() directly Date: Mon, 31 Jul 2023 10:40:34 +0200 Message-ID: <20230731084034.37021-4-oleksandr@redhat.com> In-Reply-To: <20230731084034.37021-1-oleksandr@redhat.com> References: <20230731084034.37021-1-oleksandr@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The qedf_dbg_fp_int_cmd_read() function invokes sprintf() directly on a __user pointer, which may crash the kernel. Avoid doing that by vmalloc()'ating a buffer for scnprintf() and then calling simple_read_from_buffer() which does a proper copy_to_user() call. Fixes: 61d8658b4a ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver fra= mework.") Link: https://lore.kernel.org/lkml/20230724120241.40495-1-oleksandr@redhat.= com/ Link: https://lore.kernel.org/linux-scsi/20230726101236.11922-1-skashyap@ma= rvell.com/ Cc: Saurav Kashyap Cc: Rob Evers Cc: Johannes Thumshirn Cc: David Laight Cc: Jozef Bacik Cc: Laurence Oberman Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: GR-QLogic-Storage-Upstream@marvell.com Cc: linux-scsi@vger.kernel.org Reviewed-by: Laurence Oberman Reviewed-by: Johannes Thumshirn Tested-by: Laurence Oberman Acked-by: Saurav Kashyap Signed-off-by: Oleksandr Natalenko --- drivers/scsi/qedf/qedf_dbg.h | 2 ++ drivers/scsi/qedf/qedf_debugfs.c | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/qedf/qedf_dbg.h b/drivers/scsi/qedf/qedf_dbg.h index f4d81127239eb..5ec2b817c694a 100644 --- a/drivers/scsi/qedf/qedf_dbg.h +++ b/drivers/scsi/qedf/qedf_dbg.h @@ -59,6 +59,8 @@ extern uint qedf_debug; #define QEDF_LOG_NOTICE 0x40000000 /* Notice logs */ #define QEDF_LOG_WARN 0x80000000 /* Warning logs */ =20 +#define QEDF_DEBUGFS_LOG_LEN (2 * PAGE_SIZE) + /* Debug context structure */ struct qedf_dbg_ctx { unsigned int host_no; diff --git a/drivers/scsi/qedf/qedf_debugfs.c b/drivers/scsi/qedf/qedf_debu= gfs.c index 1c5716540e465..451fd236bfd05 100644 --- a/drivers/scsi/qedf/qedf_debugfs.c +++ b/drivers/scsi/qedf/qedf_debugfs.c @@ -8,6 +8,7 @@ #include #include #include +#include =20 #include "qedf.h" #include "qedf_dbg.h" @@ -98,7 +99,9 @@ static ssize_t qedf_dbg_fp_int_cmd_read(struct file *filp, char __user *buffer, size_t co= unt, loff_t *ppos) { + ssize_t ret; size_t cnt =3D 0; + char *cbuf; int id; struct qedf_fastpath *fp =3D NULL; struct qedf_dbg_ctx *qedf_dbg =3D @@ -108,19 +111,25 @@ qedf_dbg_fp_int_cmd_read(struct file *filp, char __us= er *buffer, size_t count, =20 QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n"); =20 - cnt =3D sprintf(buffer, "\nFastpath I/O completions\n\n"); + cbuf =3D vmalloc(QEDF_DEBUGFS_LOG_LEN); + if (!cbuf) + return 0; + + cnt +=3D scnprintf(cbuf + cnt, QEDF_DEBUGFS_LOG_LEN - cnt, "\nFastpath I/= O completions\n\n"); =20 for (id =3D 0; id < qedf->num_queues; id++) { fp =3D &(qedf->fp_array[id]); if (fp->sb_id =3D=3D QEDF_SB_ID_NULL) continue; - cnt +=3D sprintf((buffer + cnt), "#%d: %lu\n", id, - fp->completions); + cnt +=3D scnprintf(cbuf + cnt, QEDF_DEBUGFS_LOG_LEN - cnt, + "#%d: %lu\n", id, fp->completions); } =20 - cnt =3D min_t(int, count, cnt - *ppos); - *ppos +=3D cnt; - return cnt; + ret =3D simple_read_from_buffer(buffer, count, ppos, cbuf, cnt); + + vfree(cbuf); + + return ret; } =20 static ssize_t --=20 2.41.0