Skip to content
This repository was archived by the owner on Sep 11, 2019. It is now read-only.

Commit c09581a

Browse files
YueHaibingmartinkpetersen
YueHaibing
authored andcommitted
scsi: qedi: remove memset/memcpy to nfunc and use func instead
KASAN reports 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+ GrapheneOS#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 <[email protected]> Fixes: ace7f46 ("scsi: qedi: Add QLogic FastLinQ offload iSCSI driver framework.") Signed-off-by: YueHaibing <[email protected]> Reviewed-by: Dan Carpenter <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 5386a4e commit c09581a

File tree

1 file changed

+8
-24
lines changed

1 file changed

+8
-24
lines changed

drivers/scsi/qedi/qedi_dbg.c

+8-24
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ qedi_dbg_err(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
1616
{
1717
va_list va;
1818
struct va_format vaf;
19-
char nfunc[32];
20-
21-
memset(nfunc, 0, sizeof(nfunc));
22-
memcpy(nfunc, func, sizeof(nfunc) - 1);
2319

2420
va_start(va, fmt);
2521

@@ -28,9 +24,9 @@ qedi_dbg_err(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
2824

2925
if (likely(qedi) && likely(qedi->pdev))
3026
pr_err("[%s]:[%s:%d]:%d: %pV", dev_name(&qedi->pdev->dev),
31-
nfunc, line, qedi->host_no, &vaf);
27+
func, line, qedi->host_no, &vaf);
3228
else
33-
pr_err("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
29+
pr_err("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
3430

3531
va_end(va);
3632
}
@@ -41,10 +37,6 @@ qedi_dbg_warn(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
4137
{
4238
va_list va;
4339
struct va_format vaf;
44-
char nfunc[32];
45-
46-
memset(nfunc, 0, sizeof(nfunc));
47-
memcpy(nfunc, func, sizeof(nfunc) - 1);
4840

4941
va_start(va, fmt);
5042

@@ -56,9 +48,9 @@ qedi_dbg_warn(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
5648

5749
if (likely(qedi) && likely(qedi->pdev))
5850
pr_warn("[%s]:[%s:%d]:%d: %pV", dev_name(&qedi->pdev->dev),
59-
nfunc, line, qedi->host_no, &vaf);
51+
func, line, qedi->host_no, &vaf);
6052
else
61-
pr_warn("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
53+
pr_warn("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
6254

6355
ret:
6456
va_end(va);
@@ -70,10 +62,6 @@ qedi_dbg_notice(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
7062
{
7163
va_list va;
7264
struct va_format vaf;
73-
char nfunc[32];
74-
75-
memset(nfunc, 0, sizeof(nfunc));
76-
memcpy(nfunc, func, sizeof(nfunc) - 1);
7765

7866
va_start(va, fmt);
7967

@@ -85,10 +73,10 @@ qedi_dbg_notice(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
8573

8674
if (likely(qedi) && likely(qedi->pdev))
8775
pr_notice("[%s]:[%s:%d]:%d: %pV",
88-
dev_name(&qedi->pdev->dev), nfunc, line,
76+
dev_name(&qedi->pdev->dev), func, line,
8977
qedi->host_no, &vaf);
9078
else
91-
pr_notice("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
79+
pr_notice("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
9280

9381
ret:
9482
va_end(va);
@@ -100,10 +88,6 @@ qedi_dbg_info(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
10088
{
10189
va_list va;
10290
struct va_format vaf;
103-
char nfunc[32];
104-
105-
memset(nfunc, 0, sizeof(nfunc));
106-
memcpy(nfunc, func, sizeof(nfunc) - 1);
10791

10892
va_start(va, fmt);
10993

@@ -115,9 +99,9 @@ qedi_dbg_info(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
11599

116100
if (likely(qedi) && likely(qedi->pdev))
117101
pr_info("[%s]:[%s:%d]:%d: %pV", dev_name(&qedi->pdev->dev),
118-
nfunc, line, qedi->host_no, &vaf);
102+
func, line, qedi->host_no, &vaf);
119103
else
120-
pr_info("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
104+
pr_info("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
121105

122106
ret:
123107
va_end(va);

0 commit comments

Comments
 (0)