public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [syzbot] [scsi?] UBSAN: shift-out-of-bounds in sg_build_indirect
@ 2025-02-14 19:58 syzbot
  2025-02-16  3:35 ` [PATCH] scsi: sg: prevent the use of size 0 to obtain the page order of sg Edward Adam Davis
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: syzbot @ 2025-02-14 19:58 UTC (permalink / raw)
  To: James.Bottomley, dgilbert, linux-kernel, linux-scsi,
	martin.petersen, syzkaller-bugs

Hello,

syzbot found the following issue on:

HEAD commit:    128c8f96eb86 Merge tag 'drm-fixes-2025-02-14' of https://g..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=15908bf8580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=40c8b8384bc47ab0
dashboard link: https://syzkaller.appspot.com/bug?extid=270f1c719ee7baab9941
compiler:       gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=149a87df980000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=167a8f18580000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/da4c858d8649/disk-128c8f96.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/4bd8410dd596/vmlinux-128c8f96.xz
kernel image: https://storage.googleapis.com/syzbot-assets/038939e96f8b/bzImage-128c8f96.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+270f1c719ee7baab9941@syzkaller.appspotmail.com

------------[ cut here ]------------
UBSAN: shift-out-of-bounds in drivers/scsi/sg.c:1897:13
shift exponent 64 is too large for 32-bit type 'int'
CPU: 1 UID: 0 PID: 5832 Comm: syz-executor361 Not tainted 6.14.0-rc2-syzkaller-00185-g128c8f96eb86 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 12/27/2024
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:94 [inline]
 dump_stack_lvl+0x16c/0x1f0 lib/dump_stack.c:120
 ubsan_epilogue lib/ubsan.c:231 [inline]
 __ubsan_handle_shift_out_of_bounds+0x24f/0x3f0 lib/ubsan.c:468
 sg_build_indirect.cold+0x1b/0x20 drivers/scsi/sg.c:1897
 sg_build_reserve+0xc4/0x180 drivers/scsi/sg.c:2007
 sg_add_sfp drivers/scsi/sg.c:2189 [inline]
 sg_open+0xc37/0x1910 drivers/scsi/sg.c:348
 chrdev_open+0x237/0x6a0 fs/char_dev.c:414
 do_dentry_open+0x735/0x1c40 fs/open.c:956
 vfs_open+0x82/0x3f0 fs/open.c:1086
 do_open fs/namei.c:3830 [inline]
 path_openat+0x1e88/0x2d80 fs/namei.c:3989
 do_filp_open+0x20c/0x470 fs/namei.c:4016
 do_sys_openat2+0x17a/0x1e0 fs/open.c:1428
 do_sys_open fs/open.c:1443 [inline]
 __do_sys_openat fs/open.c:1459 [inline]
 __se_sys_openat fs/open.c:1454 [inline]
 __x64_sys_openat+0x175/0x210 fs/open.c:1454
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f1dc41ca3e9
Code: 48 83 c4 28 c3 e8 37 17 00 00 0f 1f 80 00 00 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 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffeaa93f3d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000101
RAX: ffffffffffffffda RBX: 00007ffeaa93f5a8 RCX: 00007f1dc41ca3e9
RDX: 000000000008a002 RSI: 00004000000000c0 RDI: ffffffffffffff9c
RBP: 00007f1dc423d610 R08: 00007ffeaa93f5a8 R09: 00007ffeaa93f5a8
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
R13: 00007ffeaa93f598 R14: 0000000000000001 R15: 0000000000000001
 </TASK>
---[ end trace ]---


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

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

* [PATCH] scsi: sg: prevent the use of size 0 to obtain the page order of sg
  2025-02-14 19:58 [syzbot] [scsi?] UBSAN: shift-out-of-bounds in sg_build_indirect syzbot
@ 2025-02-16  3:35 ` Edward Adam Davis
  2025-09-28  3:58 ` Forwarded: Re: [syzbot] [scsi?] UBSAN: shift-out-of-bounds in sg_build_indirect syzbot
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Edward Adam Davis @ 2025-02-16  3:35 UTC (permalink / raw)
  To: syzbot+270f1c719ee7baab9941
  Cc: James.Bottomley, dgilbert, linux-kernel, linux-scsi,
	martin.petersen, syzkaller-bugs

syzbot reported a shift-out-of-bounds in sg_build_indirect. [1]

The reproducer changes the value of scatter_elem_sz to 0 before executing
the open operation to open "/dev/sg0", which leads to [1].

When the value of num is 0, set its value to PAGE_SIZE to avoid this oob.

[1]
UBSAN: shift-out-of-bounds in drivers/scsi/sg.c:1897:13
shift exponent 64 is too large for 32-bit type 'int'
CPU: 1 UID: 0 PID: 5832 Comm: syz-executor361 Not tainted 6.14.0-rc2-syzkaller-00185-g128c8f96eb86 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 12/27/2024
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:94 [inline]
 dump_stack_lvl+0x16c/0x1f0 lib/dump_stack.c:120
 ubsan_epilogue lib/ubsan.c:231 [inline]
 __ubsan_handle_shift_out_of_bounds+0x24f/0x3f0 lib/ubsan.c:468
 sg_build_indirect.cold+0x1b/0x20 drivers/scsi/sg.c:1897
 sg_build_reserve+0xc4/0x180 drivers/scsi/sg.c:2007
 sg_add_sfp drivers/scsi/sg.c:2189 [inline]
 sg_open+0xc37/0x1910 drivers/scsi/sg.c:348
 chrdev_open+0x237/0x6a0 fs/char_dev.c:414
 do_dentry_open+0x735/0x1c40 fs/open.c:956
 vfs_open+0x82/0x3f0 fs/open.c:1086
 do_open fs/namei.c:3830 [inline]
 path_openat+0x1e88/0x2d80 fs/namei.c:3989
 do_filp_open+0x20c/0x470 fs/namei.c:4016
 do_sys_openat2+0x17a/0x1e0 fs/open.c:1428
 do_sys_open fs/open.c:1443 [inline]
 __do_sys_openat fs/open.c:1459 [inline]
 __se_sys_openat fs/open.c:1454 [inline]
 __x64_sys_openat+0x175/0x210 fs/open.c:1454
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Reported-by: syzbot+270f1c719ee7baab9941@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=270f1c719ee7baab9941
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
 drivers/scsi/sg.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index effb7e768165..a9c445b7dab3 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1888,6 +1888,8 @@ sg_build_indirect(Sg_scatter_hold * schp, Sg_fd * sfp, int buff_size)
 		if (num < PAGE_SIZE) {
 			scatter_elem_sz = PAGE_SIZE;
 			scatter_elem_sz_prev = PAGE_SIZE;
+			if (!num)
+				num = PAGE_SIZE;
 		} else
 			scatter_elem_sz_prev = num;
 	}
-- 
2.43.0


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

* Forwarded: Re: [syzbot] [scsi?] UBSAN: shift-out-of-bounds in sg_build_indirect
  2025-02-14 19:58 [syzbot] [scsi?] UBSAN: shift-out-of-bounds in sg_build_indirect syzbot
  2025-02-16  3:35 ` [PATCH] scsi: sg: prevent the use of size 0 to obtain the page order of sg Edward Adam Davis
@ 2025-09-28  3:58 ` syzbot
  2025-10-06 13:34 ` Forwarded: " syzbot
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: syzbot @ 2025-09-28  3:58 UTC (permalink / raw)
  To: linux-kernel, syzkaller-bugs

For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.

***

Subject: Re: [syzbot] [scsi?] UBSAN: shift-out-of-bounds in sg_build_indirect
Author: xandfury@gmail.com

syzbot <syzbot+270f1c719ee7baab9941@syzkaller.appspotmail.com> writes:

> Hello,
>
> syzbot found the following issue on:
>
> HEAD commit:    128c8f96eb86 Merge tag ’drm-fixes-2025-02-14’ of <https://g>..
> git tree:       upstream
> console output: <https://syzkaller.appspot.com/x/log.txt?x=15908bf8580000>
> kernel config:  <https://syzkaller.appspot.com/x/.config?x=40c8b8384bc47ab0>
> dashboard link: <https://syzkaller.appspot.com/bug?extid=270f1c719ee7baab9941>
> compiler:       gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
> syz repro:      <https://syzkaller.appspot.com/x/repro.syz?x=149a87df980000>
> C reproducer:   <https://syzkaller.appspot.com/x/repro.c?x=167a8f18580000>
>
> Downloadable assets:
> disk image: <https://storage.googleapis.com/syzbot-assets/da4c858d8649/disk-128c8f96.raw.xz>
> vmlinux: <https://storage.googleapis.com/syzbot-assets/4bd8410dd596/vmlinux-128c8f96.xz>
> kernel image: <https://storage.googleapis.com/syzbot-assets/038939e96f8b/bzImage-128c8f96.xz>
>
> IMPORTANT: if you fix the issue, please add the following tag to the commit:
> Reported-by: syzbot+270f1c719ee7baab9941@syzkaller.appspotmail.com
>
> ————[ cut here ]————
> UBSAN: shift-out-of-bounds in drivers/scsi/sg.c:1897:13
> shift exponent 64 is too large for 32-bit type ’int’
> CPU: 1 UID: 0 PID: 5832 Comm: syz-executor361 Not tainted 6.14.0-rc2-syzkaller-00185-g128c8f96eb86 #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 12/27/2024
> Call Trace:
>  <TASK>
>  __dump_stack lib/dump_stack.c:94 [inline]
>  dump_stack_lvl+0x16c/0x1f0 lib/dump_stack.c:120
>  ubsan_epilogue lib/ubsan.c:231 [inline]
>  __ubsan_handle_shift_out_of_bounds+0x24f/0x3f0 lib/ubsan.c:468
>  sg_build_indirect.cold+0x1b/0x20 drivers/scsi/sg.c:1897
>  sg_build_reserve+0xc4/0x180 drivers/scsi/sg.c:2007
>  sg_add_sfp drivers/scsi/sg.c:2189 [inline]
>  sg_open+0xc37/0x1910 drivers/scsi/sg.c:348
>  chrdev_open+0x237/0x6a0 fs/char_dev.c:414
>  do_dentry_open+0x735/0x1c40 fs/open.c:956
>  vfs_open+0x82/0x3f0 fs/open.c:1086
>  do_open fs/namei.c:3830 [inline]
>  path_openat+0x1e88/0x2d80 fs/namei.c:3989
>  do_filp_open+0x20c/0x470 fs/namei.c:4016
>  do_sys_openat2+0x17a/0x1e0 fs/open.c:1428
>  do_sys_open fs/open.c:1443 [inline]
>  __do_sys_openat fs/open.c:1459 [inline]
>  __se_sys_openat fs/open.c:1454 [inline]
>  __x64_sys_openat+0x175/0x210 fs/open.c:1454
>  do_syscall_x64 arch/x86/entry/common.c:52 [inline]
>  do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
>  entry_SYSCALL_64_after_hwframe+0x77/0x7f
> RIP: 0033:0x7f1dc41ca3e9
> Code: 48 83 c4 28 c3 e8 37 17 00 00 0f 1f 80 00 00 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 b8 ff ff ff f7 d8 64 89 01 48
> RSP: 002b:00007ffeaa93f3d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000101
> RAX: ffffffffffffffda RBX: 00007ffeaa93f5a8 RCX: 00007f1dc41ca3e9
> RDX: 000000000008a002 RSI: 00004000000000c0 RDI: ffffffffffffff9c
> RBP: 00007f1dc423d610 R08: 00007ffeaa93f5a8 R09: 00007ffeaa93f5a8
> R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
> R13: 00007ffeaa93f598 R14: 0000000000000001 R15: 0000000000000001
>  </TASK>
> —[ end trace ]—
>
>
> —
> This report is generated by a bot. It may contain errors.
> See <https://goo.gl/tpsmEJ> for more information about syzbot.
> syzbot engineers can be reached at syzkaller@googlegroups.com.
>
> syzbot will keep track of this issue. See:
> <https://goo.gl/tpsmEJ#status> for how to communicate with syzbot.
>
> If the report is already addressed, let syzbot know by replying with:
> #syz fix: exact-commit-title
>
> If you want syzbot to run the reproducer, reply with:
> #syz test: git://repo/address.git branch-or-commit-hash
> If you attach or paste a git patch, syzbot will apply it before testing.
>
> If you want to overwrite report’s subsystems, reply with:
> #syz set subsystems: new-subsystem
> (See the list of subsystem names on the web dashboard)
>
> If the report is a duplicate of another one, reply with:
> #syz dup: exact-subject-of-another-report
>
> If you want to undo deduplication, reply with:
> #syz undup

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

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

* Forwarded: UBSAN: shift-out-of-bounds in sg_build_indirect
  2025-02-14 19:58 [syzbot] [scsi?] UBSAN: shift-out-of-bounds in sg_build_indirect syzbot
  2025-02-16  3:35 ` [PATCH] scsi: sg: prevent the use of size 0 to obtain the page order of sg Edward Adam Davis
  2025-09-28  3:58 ` Forwarded: Re: [syzbot] [scsi?] UBSAN: shift-out-of-bounds in sg_build_indirect syzbot
@ 2025-10-06 13:34 ` syzbot
  2025-10-10 11:44 ` syzbot
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: syzbot @ 2025-10-06 13:34 UTC (permalink / raw)
  To: linux-kernel, syzkaller-bugs

For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.

***

Subject: UBSAN: shift-out-of-bounds in sg_build_indirect
Author: kshitijvparanjape@gmail.com

#syz test

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

* Forwarded: UBSAN: shift-out-of-bounds in sg_build_indirect
  2025-02-14 19:58 [syzbot] [scsi?] UBSAN: shift-out-of-bounds in sg_build_indirect syzbot
                   ` (2 preceding siblings ...)
  2025-10-06 13:34 ` Forwarded: " syzbot
@ 2025-10-10 11:44 ` syzbot
  2025-11-07 17:29 ` Forwarded: Add module validation parameters in scatter_elem_sz syzbot
  2025-11-07 18:02 ` Forwarded: Add validation for scatter_elem_sz syzbot
  5 siblings, 0 replies; 7+ messages in thread
From: syzbot @ 2025-10-10 11:44 UTC (permalink / raw)
  To: linux-kernel, syzkaller-bugs

For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.

***

Subject: UBSAN: shift-out-of-bounds in sg_build_indirect
Author: kshitijvparanjape@gmail.com

#syz test

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

* Forwarded: Add module validation parameters in scatter_elem_sz
  2025-02-14 19:58 [syzbot] [scsi?] UBSAN: shift-out-of-bounds in sg_build_indirect syzbot
                   ` (3 preceding siblings ...)
  2025-10-10 11:44 ` syzbot
@ 2025-11-07 17:29 ` syzbot
  2025-11-07 18:02 ` Forwarded: Add validation for scatter_elem_sz syzbot
  5 siblings, 0 replies; 7+ messages in thread
From: syzbot @ 2025-11-07 17:29 UTC (permalink / raw)
  To: linux-kernel, syzkaller-bugs

For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.

***

Subject: Add module validation parameters in scatter_elem_sz
Author: kshitijvparanjape@gmail.com

#syz test

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

* Forwarded: Add validation for scatter_elem_sz
  2025-02-14 19:58 [syzbot] [scsi?] UBSAN: shift-out-of-bounds in sg_build_indirect syzbot
                   ` (4 preceding siblings ...)
  2025-11-07 17:29 ` Forwarded: Add module validation parameters in scatter_elem_sz syzbot
@ 2025-11-07 18:02 ` syzbot
  5 siblings, 0 replies; 7+ messages in thread
From: syzbot @ 2025-11-07 18:02 UTC (permalink / raw)
  To: linux-kernel, syzkaller-bugs

For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.

***

Subject: Add validation for scatter_elem_sz
Author: kshitijvparanjape@gmail.com

#syz test

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

end of thread, other threads:[~2025-11-07 18:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-14 19:58 [syzbot] [scsi?] UBSAN: shift-out-of-bounds in sg_build_indirect syzbot
2025-02-16  3:35 ` [PATCH] scsi: sg: prevent the use of size 0 to obtain the page order of sg Edward Adam Davis
2025-09-28  3:58 ` Forwarded: Re: [syzbot] [scsi?] UBSAN: shift-out-of-bounds in sg_build_indirect syzbot
2025-10-06 13:34 ` Forwarded: " syzbot
2025-10-10 11:44 ` syzbot
2025-11-07 17:29 ` Forwarded: Add module validation parameters in scatter_elem_sz syzbot
2025-11-07 18:02 ` Forwarded: Add validation for scatter_elem_sz syzbot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox