linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][V2] scsi: qedf: remove memset/memcpy to nfunc and use func instead
@ 2019-04-12  9:48 Colin King
  2019-04-18  8:13 ` Saurav Kashyap
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Colin King @ 2019-04-12  9:48 UTC (permalink / raw)
  To: QLogic-Storage-Upstream, James E . J . Bottomley,
	Martin K . Petersen, linux-scsi
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently the qedf_dbg_* family of functions can overrun the end
of the source string if it is less than the destination buffer
length because of the use of a fixed sized memcpy. Remove the
memset/memcpy calls to nfunc and just use func instead as it
is always a null terminated string.

Addresses-Coverity: ("Out-of-bounds access")
Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---

V2: replace the V1 strscpy with just using func since this is always
    going to be a NUL terminated string. Thanks to Rasmus Villemoes for
    noticing that.

---
 drivers/scsi/qedf/qedf_dbg.c | 32 ++++++++------------------------
 1 file changed, 8 insertions(+), 24 deletions(-)

diff --git a/drivers/scsi/qedf/qedf_dbg.c b/drivers/scsi/qedf/qedf_dbg.c
index f2397ee9ba69..f7d170bffc82 100644
--- a/drivers/scsi/qedf/qedf_dbg.c
+++ b/drivers/scsi/qedf/qedf_dbg.c
@@ -15,10 +15,6 @@ qedf_dbg_err(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
 {
 	va_list va;
 	struct va_format vaf;
-	char nfunc[32];
-
-	memset(nfunc, 0, sizeof(nfunc));
-	memcpy(nfunc, func, sizeof(nfunc) - 1);
 
 	va_start(va, fmt);
 
@@ -27,9 +23,9 @@ qedf_dbg_err(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
 
 	if (likely(qedf) && likely(qedf->pdev))
 		pr_err("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)),
-			nfunc, line, qedf->host_no, &vaf);
+			func, line, qedf->host_no, &vaf);
 	else
-		pr_err("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
+		pr_err("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
 
 	va_end(va);
 }
@@ -40,10 +36,6 @@ qedf_dbg_warn(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
 {
 	va_list va;
 	struct va_format vaf;
-	char nfunc[32];
-
-	memset(nfunc, 0, sizeof(nfunc));
-	memcpy(nfunc, func, sizeof(nfunc) - 1);
 
 	va_start(va, fmt);
 
@@ -55,9 +47,9 @@ qedf_dbg_warn(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
 
 	if (likely(qedf) && likely(qedf->pdev))
 		pr_warn("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)),
-			nfunc, line, qedf->host_no, &vaf);
+			func, line, qedf->host_no, &vaf);
 	else
-		pr_warn("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
+		pr_warn("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
 
 ret:
 	va_end(va);
@@ -69,10 +61,6 @@ qedf_dbg_notice(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
 {
 	va_list va;
 	struct va_format vaf;
-	char nfunc[32];
-
-	memset(nfunc, 0, sizeof(nfunc));
-	memcpy(nfunc, func, sizeof(nfunc) - 1);
 
 	va_start(va, fmt);
 
@@ -84,10 +72,10 @@ qedf_dbg_notice(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
 
 	if (likely(qedf) && likely(qedf->pdev))
 		pr_notice("[%s]:[%s:%d]:%d: %pV",
-			  dev_name(&(qedf->pdev->dev)), nfunc, line,
+			  dev_name(&(qedf->pdev->dev)), func, line,
 			  qedf->host_no, &vaf);
 	else
-		pr_notice("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
+		pr_notice("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
 
 ret:
 	va_end(va);
@@ -99,10 +87,6 @@ qedf_dbg_info(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
 {
 	va_list va;
 	struct va_format vaf;
-	char nfunc[32];
-
-	memset(nfunc, 0, sizeof(nfunc));
-	memcpy(nfunc, func, sizeof(nfunc) - 1);
 
 	va_start(va, fmt);
 
@@ -114,9 +98,9 @@ qedf_dbg_info(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
 
 	if (likely(qedf) && likely(qedf->pdev))
 		pr_info("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)),
-			nfunc, line, qedf->host_no, &vaf);
+			func, line, qedf->host_no, &vaf);
 	else
-		pr_info("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
+		pr_info("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
 
 ret:
 	va_end(va);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH][V2] scsi: qedf: remove memset/memcpy to nfunc and use func instead
  2019-04-12  9:48 [PATCH][V2] scsi: qedf: remove memset/memcpy to nfunc and use func instead Colin King
@ 2019-04-18  8:13 ` Saurav Kashyap
  2019-04-19  0:33 ` Martin K. Petersen
  2019-04-20  4:05 ` [PATCH] scsi: qedi: " Yue Haibing
  2 siblings, 0 replies; 7+ messages in thread
From: Saurav Kashyap @ 2019-04-18  8:13 UTC (permalink / raw)
  To: Colin King, QLogic-Storage-Upstream, James E . J . Bottomley,
	Martin K . Petersen, linux-scsi
  Cc: kernel-janitors, linux-kernel



-----Original Message-----
From: Colin King <colin.king@canonical.com>
Date: Friday, 12 April 2019 at 3:18 PM
To: <QLogic-Storage-Upstream@cavium.com>, "James E . J . Bottomley"
<jejb@linux.ibm.com>, "Martin K . Petersen" <martin.petersen@oracle.com>,
<linux-scsi@vger.kernel.org>
Cc: <kernel-janitors@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH][V2] scsi: qedf: remove memset/memcpy to nfunc and use
func instead
Resent-From: <Saurav.Kashyap@cavium.com>
Resent-Date: Fri, 12 Apr 2019 02:48:45 -0700

>From: Colin Ian King <colin.king@canonical.com>
>
>Currently the qedf_dbg_* family of functions can overrun the end
>of the source string if it is less than the destination buffer
>length because of the use of a fixed sized memcpy. Remove the
>memset/memcpy calls to nfunc and just use func instead as it
>is always a null terminated string.
>
>Addresses-Coverity: ("Out-of-bounds access")
>Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver
>framework.")
>Signed-off-by: Colin Ian King <colin.king@canonical.com>
>---
>
>V2: replace the V1 strscpy with just using func since this is always
>    going to be a NUL terminated string. Thanks to Rasmus Villemoes for
>    noticing that.
>
>---
> drivers/scsi/qedf/qedf_dbg.c | 32 ++++++++------------------------
> 1 file changed, 8 insertions(+), 24 deletions(-)
>
>diff --git a/drivers/scsi/qedf/qedf_dbg.c b/drivers/scsi/qedf/qedf_dbg.c
>index f2397ee9ba69..f7d170bffc82 100644
>--- a/drivers/scsi/qedf/qedf_dbg.c
>+++ b/drivers/scsi/qedf/qedf_dbg.c
>@@ -15,10 +15,6 @@ qedf_dbg_err(struct qedf_dbg_ctx *qedf, const char
>*func, u32 line,
> {
> 	va_list va;
> 	struct va_format vaf;
>-	char nfunc[32];
>-
>-	memset(nfunc, 0, sizeof(nfunc));
>-	memcpy(nfunc, func, sizeof(nfunc) - 1);
> 
> 	va_start(va, fmt);
> 
>@@ -27,9 +23,9 @@ qedf_dbg_err(struct qedf_dbg_ctx *qedf, const char
>*func, u32 line,
> 
> 	if (likely(qedf) && likely(qedf->pdev))
> 		pr_err("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)),
>-			nfunc, line, qedf->host_no, &vaf);
>+			func, line, qedf->host_no, &vaf);
> 	else
>-		pr_err("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
>+		pr_err("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
> 
> 	va_end(va);
> }
>@@ -40,10 +36,6 @@ qedf_dbg_warn(struct qedf_dbg_ctx *qedf, const char
>*func, u32 line,
> {
> 	va_list va;
> 	struct va_format vaf;
>-	char nfunc[32];
>-
>-	memset(nfunc, 0, sizeof(nfunc));
>-	memcpy(nfunc, func, sizeof(nfunc) - 1);
> 
> 	va_start(va, fmt);
> 
>@@ -55,9 +47,9 @@ qedf_dbg_warn(struct qedf_dbg_ctx *qedf, const char
>*func, u32 line,
> 
> 	if (likely(qedf) && likely(qedf->pdev))
> 		pr_warn("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)),
>-			nfunc, line, qedf->host_no, &vaf);
>+			func, line, qedf->host_no, &vaf);
> 	else
>-		pr_warn("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
>+		pr_warn("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
> 
> ret:
> 	va_end(va);
>@@ -69,10 +61,6 @@ qedf_dbg_notice(struct qedf_dbg_ctx *qedf, const char
>*func, u32 line,
> {
> 	va_list va;
> 	struct va_format vaf;
>-	char nfunc[32];
>-
>-	memset(nfunc, 0, sizeof(nfunc));
>-	memcpy(nfunc, func, sizeof(nfunc) - 1);
> 
> 	va_start(va, fmt);
> 
>@@ -84,10 +72,10 @@ qedf_dbg_notice(struct qedf_dbg_ctx *qedf, const char
>*func, u32 line,
> 
> 	if (likely(qedf) && likely(qedf->pdev))
> 		pr_notice("[%s]:[%s:%d]:%d: %pV",
>-			  dev_name(&(qedf->pdev->dev)), nfunc, line,
>+			  dev_name(&(qedf->pdev->dev)), func, line,
> 			  qedf->host_no, &vaf);
> 	else
>-		pr_notice("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
>+		pr_notice("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
> 
> ret:
> 	va_end(va);
>@@ -99,10 +87,6 @@ qedf_dbg_info(struct qedf_dbg_ctx *qedf, const char
>*func, u32 line,
> {
> 	va_list va;
> 	struct va_format vaf;
>-	char nfunc[32];
>-
>-	memset(nfunc, 0, sizeof(nfunc));
>-	memcpy(nfunc, func, sizeof(nfunc) - 1);
> 
> 	va_start(va, fmt);
> 
>@@ -114,9 +98,9 @@ qedf_dbg_info(struct qedf_dbg_ctx *qedf, const char
>*func, u32 line,
> 
> 	if (likely(qedf) && likely(qedf->pdev))
> 		pr_info("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)),
>-			nfunc, line, qedf->host_no, &vaf);
>+			func, line, qedf->host_no, &vaf);
> 	else
>-		pr_info("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
>+		pr_info("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
> 
> ret:
> 	va_end(va);
>-- 
>2.20.1

Thanks,
Acked-by: Saurav Kashyap <skashyap@marvell.com>


>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH][V2] scsi: qedf: remove memset/memcpy to nfunc and use func instead
  2019-04-12  9:48 [PATCH][V2] scsi: qedf: remove memset/memcpy to nfunc and use func instead Colin King
  2019-04-18  8:13 ` Saurav Kashyap
@ 2019-04-19  0:33 ` Martin K. Petersen
  2019-04-20  4:05 ` [PATCH] scsi: qedi: " Yue Haibing
  2 siblings, 0 replies; 7+ messages in thread
From: Martin K. Petersen @ 2019-04-19  0:33 UTC (permalink / raw)
  To: Colin King
  Cc: QLogic-Storage-Upstream, James E . J . Bottomley,
	Martin K . Petersen, linux-scsi, kernel-janitors, linux-kernel


Colin,

> Currently the qedf_dbg_* family of functions can overrun the end of
> the source string if it is less than the destination buffer length
> because of the use of a fixed sized memcpy. Remove the memset/memcpy
> calls to nfunc and just use func instead as it is always a null
> terminated string.

Applied to 5.2/scsi-queue, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] scsi: qedi: remove memset/memcpy to nfunc and use func instead
  2019-04-12  9:48 [PATCH][V2] scsi: qedf: remove memset/memcpy to nfunc and use func instead Colin King
  2019-04-18  8:13 ` Saurav Kashyap
  2019-04-19  0:33 ` Martin K. Petersen
@ 2019-04-20  4:05 ` Yue Haibing
  2019-05-09 14:50   ` YueHaibing
                     ` (2 more replies)
  2 siblings, 3 replies; 7+ messages in thread
From: Yue Haibing @ 2019-04-20  4:05 UTC (permalink / raw)
  To: QLogic-Storage-Upstream, jejb, martin.petersen, mojha, skashyap
  Cc: linux-kernel, linux-scsi, kernel-janitors, YueHaibing

From: YueHaibing <yuehaibing@huawei.com>

KASAN report this:

BUG: KASAN: global-out-of-bounds in qedi_dbg_err+0xda/0x330 [qedi]
Read of size 31 at addr ffffffffc12b0ae0 by task syz-executor.0/2429

CPU: 0 PID: 2429 Comm: syz-executor.0 Not tainted 5.0.0-rc7+ #45
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0xfa/0x1ce lib/dump_stack.c:113
 print_address_description+0x1c4/0x270 mm/kasan/report.c:187
 kasan_report+0x149/0x18d mm/kasan/report.c:317
 memcpy+0x1f/0x50 mm/kasan/common.c:130
 qedi_dbg_err+0xda/0x330 [qedi]
 ? 0xffffffffc12d0000
 qedi_init+0x118/0x1000 [qedi]
 ? 0xffffffffc12d0000
 ? 0xffffffffc12d0000
 ? 0xffffffffc12d0000
 do_one_initcall+0xfa/0x5ca init/main.c:887
 do_init_module+0x204/0x5f6 kernel/module.c:3460
 load_module+0x66b2/0x8570 kernel/module.c:3808
 __do_sys_finit_module+0x238/0x2a0 kernel/module.c:3902
 do_syscall_64+0x147/0x600 arch/x86/entry/common.c:290
 entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x462e99
Code: f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 bc ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f2d57e55c58 EFLAGS: 00000246 ORIG_RAX: 0000000000000139
RAX: ffffffffffffffda RBX: 000000000073bfa0 RCX: 0000000000462e99
RDX: 0000000000000000 RSI: 00000000200003c0 RDI: 0000000000000003
RBP: 00007f2d57e55c70 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007f2d57e566bc
R13: 00000000004bcefb R14: 00000000006f7030 R15: 0000000000000004

The buggy address belongs to the variable:
 __func__.67584+0x0/0xffffffffffffd520 [qedi]

Memory state around the buggy address:
 ffffffffc12b0980: fa fa fa fa 00 04 fa fa fa fa fa fa 00 00 05 fa
 ffffffffc12b0a00: fa fa fa fa 00 00 04 fa fa fa fa fa 00 05 fa fa
> ffffffffc12b0a80: fa fa fa fa 00 06 fa fa fa fa fa fa 00 02 fa fa
                                                          ^
 ffffffffc12b0b00: fa fa fa fa 00 00 04 fa fa fa fa fa 00 00 03 fa
 ffffffffc12b0b80: fa fa fa fa 00 00 02 fa fa fa fa fa 00 00 04 fa

Currently the qedi_dbg_* family of functions can overrun the end
of the source string if it is less than the destination buffer
length because of the use of a fixed sized memcpy. Remove the
memset/memcpy calls to nfunc and just use func instead as it
is always a null terminated string.

Reported-by: Hulk Robot <hulkci@huawei.com>
Fixes: ace7f46ba5fd ("scsi: qedi: Add QLogic FastLinQ offload iSCSI driver framework.")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 drivers/scsi/qedi/qedi_dbg.c | 32 ++++++++------------------------
 1 file changed, 8 insertions(+), 24 deletions(-)

diff --git a/drivers/scsi/qedi/qedi_dbg.c b/drivers/scsi/qedi/qedi_dbg.c
index 8fd28b0..3383314 100644
--- a/drivers/scsi/qedi/qedi_dbg.c
+++ b/drivers/scsi/qedi/qedi_dbg.c
@@ -16,10 +16,6 @@ qedi_dbg_err(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
 {
 	va_list va;
 	struct va_format vaf;
-	char nfunc[32];
-
-	memset(nfunc, 0, sizeof(nfunc));
-	memcpy(nfunc, func, sizeof(nfunc) - 1);
 
 	va_start(va, fmt);
 
@@ -28,9 +24,9 @@ qedi_dbg_err(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
 
 	if (likely(qedi) && likely(qedi->pdev))
 		pr_err("[%s]:[%s:%d]:%d: %pV", dev_name(&qedi->pdev->dev),
-		       nfunc, line, qedi->host_no, &vaf);
+		       func, line, qedi->host_no, &vaf);
 	else
-		pr_err("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
+		pr_err("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
 
 	va_end(va);
 }
@@ -41,10 +37,6 @@ qedi_dbg_warn(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
 {
 	va_list va;
 	struct va_format vaf;
-	char nfunc[32];
-
-	memset(nfunc, 0, sizeof(nfunc));
-	memcpy(nfunc, func, sizeof(nfunc) - 1);
 
 	va_start(va, fmt);
 
@@ -56,9 +48,9 @@ qedi_dbg_warn(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
 
 	if (likely(qedi) && likely(qedi->pdev))
 		pr_warn("[%s]:[%s:%d]:%d: %pV", dev_name(&qedi->pdev->dev),
-			nfunc, line, qedi->host_no, &vaf);
+			func, line, qedi->host_no, &vaf);
 	else
-		pr_warn("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
+		pr_warn("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
 
 ret:
 	va_end(va);
@@ -70,10 +62,6 @@ qedi_dbg_notice(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
 {
 	va_list va;
 	struct va_format vaf;
-	char nfunc[32];
-
-	memset(nfunc, 0, sizeof(nfunc));
-	memcpy(nfunc, func, sizeof(nfunc) - 1);
 
 	va_start(va, fmt);
 
@@ -85,10 +73,10 @@ qedi_dbg_notice(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
 
 	if (likely(qedi) && likely(qedi->pdev))
 		pr_notice("[%s]:[%s:%d]:%d: %pV",
-			  dev_name(&qedi->pdev->dev), nfunc, line,
+			  dev_name(&qedi->pdev->dev), func, line,
 			  qedi->host_no, &vaf);
 	else
-		pr_notice("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
+		pr_notice("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
 
 ret:
 	va_end(va);
@@ -100,10 +88,6 @@ qedi_dbg_info(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
 {
 	va_list va;
 	struct va_format vaf;
-	char nfunc[32];
-
-	memset(nfunc, 0, sizeof(nfunc));
-	memcpy(nfunc, func, sizeof(nfunc) - 1);
 
 	va_start(va, fmt);
 
@@ -115,9 +99,9 @@ qedi_dbg_info(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
 
 	if (likely(qedi) && likely(qedi->pdev))
 		pr_info("[%s]:[%s:%d]:%d: %pV", dev_name(&qedi->pdev->dev),
-			nfunc, line, qedi->host_no, &vaf);
+			func, line, qedi->host_no, &vaf);
 	else
-		pr_info("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
+		pr_info("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
 
 ret:
 	va_end(va);
-- 
2.7.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] scsi: qedi: remove memset/memcpy to nfunc and use func instead
  2019-04-20  4:05 ` [PATCH] scsi: qedi: " Yue Haibing
@ 2019-05-09 14:50   ` YueHaibing
  2019-05-10 11:29   ` Dan Carpenter
  2019-05-13 22:31   ` Martin K. Petersen
  2 siblings, 0 replies; 7+ messages in thread
From: YueHaibing @ 2019-05-09 14:50 UTC (permalink / raw)
  To: QLogic-Storage-Upstream, jejb, martin.petersen, mojha, skashyap, gregkh
  Cc: linux-kernel, linux-scsi, kernel-janitors


Friendly ping, could someone review this patch ?

On 2019/4/20 12:05, Yue Haibing wrote:
> From: YueHaibing <yuehaibing@huawei.com>
> 
> KASAN report this:
> 
> BUG: KASAN: global-out-of-bounds in qedi_dbg_err+0xda/0x330 [qedi]
> Read of size 31 at addr ffffffffc12b0ae0 by task syz-executor.0/2429
> 
> CPU: 0 PID: 2429 Comm: syz-executor.0 Not tainted 5.0.0-rc7+ #45
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
> Call Trace:
>  __dump_stack lib/dump_stack.c:77 [inline]
>  dump_stack+0xfa/0x1ce lib/dump_stack.c:113
>  print_address_description+0x1c4/0x270 mm/kasan/report.c:187
>  kasan_report+0x149/0x18d mm/kasan/report.c:317
>  memcpy+0x1f/0x50 mm/kasan/common.c:130
>  qedi_dbg_err+0xda/0x330 [qedi]
>  ? 0xffffffffc12d0000
>  qedi_init+0x118/0x1000 [qedi]
>  ? 0xffffffffc12d0000
>  ? 0xffffffffc12d0000
>  ? 0xffffffffc12d0000
>  do_one_initcall+0xfa/0x5ca init/main.c:887
>  do_init_module+0x204/0x5f6 kernel/module.c:3460
>  load_module+0x66b2/0x8570 kernel/module.c:3808
>  __do_sys_finit_module+0x238/0x2a0 kernel/module.c:3902
>  do_syscall_64+0x147/0x600 arch/x86/entry/common.c:290
>  entry_SYSCALL_64_after_hwframe+0x49/0xbe
> RIP: 0033:0x462e99
> Code: f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 bc ff ff ff f7 d8 64 89 01 48
> RSP: 002b:00007f2d57e55c58 EFLAGS: 00000246 ORIG_RAX: 0000000000000139
> RAX: ffffffffffffffda RBX: 000000000073bfa0 RCX: 0000000000462e99
> RDX: 0000000000000000 RSI: 00000000200003c0 RDI: 0000000000000003
> RBP: 00007f2d57e55c70 R08: 0000000000000000 R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000246 R12: 00007f2d57e566bc
> R13: 00000000004bcefb R14: 00000000006f7030 R15: 0000000000000004
> 
> The buggy address belongs to the variable:
>  __func__.67584+0x0/0xffffffffffffd520 [qedi]
> 
> Memory state around the buggy address:
>  ffffffffc12b0980: fa fa fa fa 00 04 fa fa fa fa fa fa 00 00 05 fa
>  ffffffffc12b0a00: fa fa fa fa 00 00 04 fa fa fa fa fa 00 05 fa fa
>> ffffffffc12b0a80: fa fa fa fa 00 06 fa fa fa fa fa fa 00 02 fa fa
>                                                           ^
>  ffffffffc12b0b00: fa fa fa fa 00 00 04 fa fa fa fa fa 00 00 03 fa
>  ffffffffc12b0b80: fa fa fa fa 00 00 02 fa fa fa fa fa 00 00 04 fa
> 
> Currently the qedi_dbg_* family of functions can overrun the end
> of the source string if it is less than the destination buffer
> length because of the use of a fixed sized memcpy. Remove the
> memset/memcpy calls to nfunc and just use func instead as it
> is always a null terminated string.
> 
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Fixes: ace7f46ba5fd ("scsi: qedi: Add QLogic FastLinQ offload iSCSI driver framework.")
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
>  drivers/scsi/qedi/qedi_dbg.c | 32 ++++++++------------------------
>  1 file changed, 8 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/scsi/qedi/qedi_dbg.c b/drivers/scsi/qedi/qedi_dbg.c
> index 8fd28b0..3383314 100644
> --- a/drivers/scsi/qedi/qedi_dbg.c
> +++ b/drivers/scsi/qedi/qedi_dbg.c
> @@ -16,10 +16,6 @@ qedi_dbg_err(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
>  {
>  	va_list va;
>  	struct va_format vaf;
> -	char nfunc[32];
> -
> -	memset(nfunc, 0, sizeof(nfunc));
> -	memcpy(nfunc, func, sizeof(nfunc) - 1);
>  
>  	va_start(va, fmt);
>  
> @@ -28,9 +24,9 @@ qedi_dbg_err(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
>  
>  	if (likely(qedi) && likely(qedi->pdev))
>  		pr_err("[%s]:[%s:%d]:%d: %pV", dev_name(&qedi->pdev->dev),
> -		       nfunc, line, qedi->host_no, &vaf);
> +		       func, line, qedi->host_no, &vaf);
>  	else
> -		pr_err("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
> +		pr_err("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
>  
>  	va_end(va);
>  }
> @@ -41,10 +37,6 @@ qedi_dbg_warn(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
>  {
>  	va_list va;
>  	struct va_format vaf;
> -	char nfunc[32];
> -
> -	memset(nfunc, 0, sizeof(nfunc));
> -	memcpy(nfunc, func, sizeof(nfunc) - 1);
>  
>  	va_start(va, fmt);
>  
> @@ -56,9 +48,9 @@ qedi_dbg_warn(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
>  
>  	if (likely(qedi) && likely(qedi->pdev))
>  		pr_warn("[%s]:[%s:%d]:%d: %pV", dev_name(&qedi->pdev->dev),
> -			nfunc, line, qedi->host_no, &vaf);
> +			func, line, qedi->host_no, &vaf);
>  	else
> -		pr_warn("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
> +		pr_warn("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
>  
>  ret:
>  	va_end(va);
> @@ -70,10 +62,6 @@ qedi_dbg_notice(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
>  {
>  	va_list va;
>  	struct va_format vaf;
> -	char nfunc[32];
> -
> -	memset(nfunc, 0, sizeof(nfunc));
> -	memcpy(nfunc, func, sizeof(nfunc) - 1);
>  
>  	va_start(va, fmt);
>  
> @@ -85,10 +73,10 @@ qedi_dbg_notice(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
>  
>  	if (likely(qedi) && likely(qedi->pdev))
>  		pr_notice("[%s]:[%s:%d]:%d: %pV",
> -			  dev_name(&qedi->pdev->dev), nfunc, line,
> +			  dev_name(&qedi->pdev->dev), func, line,
>  			  qedi->host_no, &vaf);
>  	else
> -		pr_notice("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
> +		pr_notice("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
>  
>  ret:
>  	va_end(va);
> @@ -100,10 +88,6 @@ qedi_dbg_info(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
>  {
>  	va_list va;
>  	struct va_format vaf;
> -	char nfunc[32];
> -
> -	memset(nfunc, 0, sizeof(nfunc));
> -	memcpy(nfunc, func, sizeof(nfunc) - 1);
>  
>  	va_start(va, fmt);
>  
> @@ -115,9 +99,9 @@ qedi_dbg_info(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
>  
>  	if (likely(qedi) && likely(qedi->pdev))
>  		pr_info("[%s]:[%s:%d]:%d: %pV", dev_name(&qedi->pdev->dev),
> -			nfunc, line, qedi->host_no, &vaf);
> +			func, line, qedi->host_no, &vaf);
>  	else
> -		pr_info("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
> +		pr_info("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
>  
>  ret:
>  	va_end(va);
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] scsi: qedi: remove memset/memcpy to nfunc and use func instead
  2019-04-20  4:05 ` [PATCH] scsi: qedi: " Yue Haibing
  2019-05-09 14:50   ` YueHaibing
@ 2019-05-10 11:29   ` Dan Carpenter
  2019-05-13 22:31   ` Martin K. Petersen
  2 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2019-05-10 11:29 UTC (permalink / raw)
  To: Yue Haibing
  Cc: QLogic-Storage-Upstream, jejb, martin.petersen, mojha, skashyap,
	linux-kernel, linux-scsi, kernel-janitors

It took me a while to figure out that this is almost the same as Colin's
qedf patch but for qedi.

Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] scsi: qedi: remove memset/memcpy to nfunc and use func instead
  2019-04-20  4:05 ` [PATCH] scsi: qedi: " Yue Haibing
  2019-05-09 14:50   ` YueHaibing
  2019-05-10 11:29   ` Dan Carpenter
@ 2019-05-13 22:31   ` Martin K. Petersen
  2 siblings, 0 replies; 7+ messages in thread
From: Martin K. Petersen @ 2019-05-13 22:31 UTC (permalink / raw)
  To: Yue Haibing
  Cc: QLogic-Storage-Upstream, jejb, martin.petersen, mojha, skashyap,
	linux-kernel, linux-scsi, kernel-janitors


Yue,

> KASAN report this:
>
> BUG: KASAN: global-out-of-bounds in qedi_dbg_err+0xda/0x330 [qedi]
> Read of size 31 at addr ffffffffc12b0ae0 by task syz-executor.0/2429

Applied to 5.2/scsi-queue. Thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-05-13 22:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-12  9:48 [PATCH][V2] scsi: qedf: remove memset/memcpy to nfunc and use func instead Colin King
2019-04-18  8:13 ` Saurav Kashyap
2019-04-19  0:33 ` Martin K. Petersen
2019-04-20  4:05 ` [PATCH] scsi: qedi: " Yue Haibing
2019-05-09 14:50   ` YueHaibing
2019-05-10 11:29   ` Dan Carpenter
2019-05-13 22:31   ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).