linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [syzbot] [kernel?] UBSAN: shift-out-of-bounds in pcl726_attach
@ 2025-07-05 11:02 syzbot
  2025-07-05 12:47 ` Hillf Danton
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: syzbot @ 2025-07-05 11:02 UTC (permalink / raw)
  To: abbotti, hsweeten, linux-kernel, syzkaller-bugs

Hello,

syzbot found the following issue on:

HEAD commit:    c435a4f487e8 Merge tag 'riscv-for-linus-6.16-rc5' of git:/..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=14ea4f70580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=5ba6cef8f153bfeb
dashboard link: https://syzkaller.appspot.com/bug?extid=5cd373521edd68bebcb3
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=1116c582580000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=12ea4f70580000

Downloadable assets:
disk image (non-bootable): https://storage.googleapis.com/syzbot-assets/d900f083ada3/non_bootable_disk-c435a4f4.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/691cd7284e87/vmlinux-c435a4f4.xz
kernel image: https://storage.googleapis.com/syzbot-assets/e61b1a511aab/bzImage-c435a4f4.xz

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

------------[ cut here ]------------
UBSAN: shift-out-of-bounds in drivers/comedi/drivers/pcl726.c:331:46
shift exponent -2147450880 is negative
CPU: 2 UID: 0 PID: 6107 Comm: syz.0.16 Not tainted 6.16.0-rc4-syzkaller-00286-gc435a4f487e8 #0 PREEMPT(full) 
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2~bpo12+1 04/01/2014
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:233 [inline]
 __ubsan_handle_shift_out_of_bounds+0x27f/0x420 lib/ubsan.c:494
 pcl726_attach.cold+0x19/0x1e drivers/comedi/drivers/pcl726.c:331
 comedi_device_attach+0x3b0/0x900 drivers/comedi/drivers.c:996
 do_devconfig_ioctl+0x1a7/0x580 drivers/comedi/comedi_fops.c:855
 comedi_unlocked_ioctl+0x15bb/0x2e90 drivers/comedi/comedi_fops.c:2136
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:907 [inline]
 __se_sys_ioctl fs/ioctl.c:893 [inline]
 __x64_sys_ioctl+0x18b/0x210 fs/ioctl.c:893
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xcd/0x4c0 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fcefa58e929
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 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 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd9f2c5a28 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007fcefa7b5fa0 RCX: 00007fcefa58e929
RDX: 0000200000002b40 RSI: 0000000040946400 RDI: 0000000000000003
RBP: 00007fcefa610b39 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007fcefa7b5fa0 R14: 00007fcefa7b5fa0 R15: 0000000000000003
 </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] 13+ messages in thread

* Re: [syzbot] [kernel?] UBSAN: shift-out-of-bounds in pcl726_attach
  2025-07-05 11:02 [syzbot] [kernel?] UBSAN: shift-out-of-bounds in pcl726_attach syzbot
@ 2025-07-05 12:47 ` Hillf Danton
  2025-07-05 13:06   ` syzbot
  2025-07-06  1:51 ` Edward Adam Davis
  2025-07-06  2:10 ` [PATCH] commdi: pcl726: Prevent invalid irq number Edward Adam Davis
  2 siblings, 1 reply; 13+ messages in thread
From: Hillf Danton @ 2025-07-05 12:47 UTC (permalink / raw)
  To: syzbot; +Cc: linux-kernel, syzkaller-bugs

> Date: Sat, 05 Jul 2025 04:02:32 -0700
> Hello,
> 
> syzbot found the following issue on:
> 
> HEAD commit:    c435a4f487e8 Merge tag 'riscv-for-linus-6.16-rc5' of git:/..
> git tree:       upstream
> console output: https://syzkaller.appspot.com/x/log.txt?x=14ea4f70580000
> kernel config:  https://syzkaller.appspot.com/x/.config?x=5ba6cef8f153bfeb
> dashboard link: https://syzkaller.appspot.com/bug?extid=5cd373521edd68bebcb3
> 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=1116c582580000
> C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=12ea4f70580000

#syz test

--- x/drivers/comedi/drivers/pcl726.c
+++ y/drivers/comedi/drivers/pcl726.c
@@ -316,6 +316,8 @@ static int pcl726_attach(struct comedi_d
 	int ret;
 	int i;
 
+	if (it->options[1] < 0 || it->options[1] > 31)
+		return -EINVAL;
 	ret = comedi_request_region(dev, it->options[0], board->io_len);
 	if (ret)
 		return ret;
--

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

* Re: [syzbot] [kernel?] UBSAN: shift-out-of-bounds in pcl726_attach
  2025-07-05 12:47 ` Hillf Danton
@ 2025-07-05 13:06   ` syzbot
  0 siblings, 0 replies; 13+ messages in thread
From: syzbot @ 2025-07-05 13:06 UTC (permalink / raw)
  To: hdanton, linux-kernel, syzkaller-bugs

Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-by: syzbot+5cd373521edd68bebcb3@syzkaller.appspotmail.com
Tested-by: syzbot+5cd373521edd68bebcb3@syzkaller.appspotmail.com

Tested on:

commit:         a79a588f Merge tag 'pm-6.16-rc5' of git://git.kernel.o..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=11ba1c8c580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=5ba6cef8f153bfeb
dashboard link: https://syzkaller.appspot.com/bug?extid=5cd373521edd68bebcb3
compiler:       gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
patch:          https://syzkaller.appspot.com/x/patch.diff?x=136c2582580000

Note: testing is done by a robot and is best-effort only.

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

* Re: [syzbot] [kernel?] UBSAN: shift-out-of-bounds in pcl726_attach
  2025-07-05 11:02 [syzbot] [kernel?] UBSAN: shift-out-of-bounds in pcl726_attach syzbot
  2025-07-05 12:47 ` Hillf Danton
@ 2025-07-06  1:51 ` Edward Adam Davis
  2025-07-06  2:10   ` syzbot
  2025-07-06  2:10 ` [PATCH] commdi: pcl726: Prevent invalid irq number Edward Adam Davis
  2 siblings, 1 reply; 13+ messages in thread
From: Edward Adam Davis @ 2025-07-06  1:51 UTC (permalink / raw)
  To: syzbot+5cd373521edd68bebcb3; +Cc: linux-kernel, syzkaller-bugs

#syz test

diff --git a/drivers/comedi/drivers/pcl726.c b/drivers/comedi/drivers/pcl726.c
index 0430630e6ebb..8802f33f1954 100644
--- a/drivers/comedi/drivers/pcl726.c
+++ b/drivers/comedi/drivers/pcl726.c
@@ -328,6 +328,9 @@ static int pcl726_attach(struct comedi_device *dev,
 	 * Hook up the external trigger source interrupt only if the
 	 * user config option is valid and the board supports interrupts.
 	 */
+	if (it->options[1] < 0 || it->options[1] > 31)
+		return -EINVAL;
+
 	if (it->options[1] && (board->irq_mask & (1 << it->options[1]))) {
 		ret = request_irq(it->options[1], pcl726_interrupt, 0,
 				  dev->board_name, dev);


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

* Re: [syzbot] [kernel?] UBSAN: shift-out-of-bounds in pcl726_attach
  2025-07-06  1:51 ` Edward Adam Davis
@ 2025-07-06  2:10   ` syzbot
  0 siblings, 0 replies; 13+ messages in thread
From: syzbot @ 2025-07-06  2:10 UTC (permalink / raw)
  To: eadavis, linux-kernel, syzkaller-bugs

Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-by: syzbot+5cd373521edd68bebcb3@syzkaller.appspotmail.com
Tested-by: syzbot+5cd373521edd68bebcb3@syzkaller.appspotmail.com

Tested on:

commit:         1f988d07 Merge tag 'hid-for-linus-2025070502' of git:/..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=150f2f70580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=5ba6cef8f153bfeb
dashboard link: https://syzkaller.appspot.com/bug?extid=5cd373521edd68bebcb3
compiler:       gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
patch:          https://syzkaller.appspot.com/x/patch.diff?x=14a4dc8c580000

Note: testing is done by a robot and is best-effort only.

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

* [PATCH] commdi: pcl726: Prevent invalid irq number
  2025-07-05 11:02 [syzbot] [kernel?] UBSAN: shift-out-of-bounds in pcl726_attach syzbot
  2025-07-05 12:47 ` Hillf Danton
  2025-07-06  1:51 ` Edward Adam Davis
@ 2025-07-06  2:10 ` Edward Adam Davis
  2025-07-07  9:47   ` Ian Abbott
  2 siblings, 1 reply; 13+ messages in thread
From: Edward Adam Davis @ 2025-07-06  2:10 UTC (permalink / raw)
  To: syzbot+5cd373521edd68bebcb3
  Cc: abbotti, hsweeten, linux-kernel, syzkaller-bugs

The reproducer passed in an irq number(0x80008000) that was too large,
which triggered the oob.

Added an interrupt number check to prevent users from passing in an irq
number that was too large.

Fixes: fff46207245c ("staging: comedi: pcl726: enable the interrupt support code")
Reported-by: syzbot+5cd373521edd68bebcb3@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=5cd373521edd68bebcb3
Tested-by: syzbot+5cd373521edd68bebcb3@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
 drivers/comedi/drivers/pcl726.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/comedi/drivers/pcl726.c b/drivers/comedi/drivers/pcl726.c
index 0430630e6ebb..8802f33f1954 100644
--- a/drivers/comedi/drivers/pcl726.c
+++ b/drivers/comedi/drivers/pcl726.c
@@ -328,6 +328,9 @@ static int pcl726_attach(struct comedi_device *dev,
 	 * Hook up the external trigger source interrupt only if the
 	 * user config option is valid and the board supports interrupts.
 	 */
+	if (it->options[1] < 0 || it->options[1] > 31)
+		return -EINVAL;
+
 	if (it->options[1] && (board->irq_mask & (1 << it->options[1]))) {
 		ret = request_irq(it->options[1], pcl726_interrupt, 0,
 				  dev->board_name, dev);
-- 
2.43.0


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

* Re: [PATCH] commdi: pcl726: Prevent invalid irq number
  2025-07-06  2:10 ` [PATCH] commdi: pcl726: Prevent invalid irq number Edward Adam Davis
@ 2025-07-07  9:47   ` Ian Abbott
  2025-07-07 10:01     ` Ian Abbott
  0 siblings, 1 reply; 13+ messages in thread
From: Ian Abbott @ 2025-07-07  9:47 UTC (permalink / raw)
  To: Edward Adam Davis, syzbot+5cd373521edd68bebcb3
  Cc: hsweeten, linux-kernel, syzkaller-bugs

On 06/07/2025 03:10, Edward Adam Davis wrote:

The "comedi" tag in the subject line is misspelled.

> The reproducer passed in an irq number(0x80008000) that was too large,
> which triggered the oob.
> 
> Added an interrupt number check to prevent users from passing in an irq
> number that was too large.
> 
> Fixes: fff46207245c ("staging: comedi: pcl726: enable the interrupt support code")
> Reported-by: syzbot+5cd373521edd68bebcb3@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=5cd373521edd68bebcb3
> Tested-by: syzbot+5cd373521edd68bebcb3@syzkaller.appspotmail.com

Thanks.

You could add:

Cc: <stable@vger.kernel.org> # 5.13+

to apply it to stable kernels.  (The 5.13+ is because comedi was moved 
out of the "staging" directory in 5.13, and a backport would be required 
for longterm series < 5.13.)

More comments below...

> Signed-off-by: Edward Adam Davis <eadavis@qq.com>
> ---
>   drivers/comedi/drivers/pcl726.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/comedi/drivers/pcl726.c b/drivers/comedi/drivers/pcl726.c
> index 0430630e6ebb..8802f33f1954 100644
> --- a/drivers/comedi/drivers/pcl726.c
> +++ b/drivers/comedi/drivers/pcl726.c
> @@ -328,6 +328,9 @@ static int pcl726_attach(struct comedi_device *dev,
>   	 * Hook up the external trigger source interrupt only if the
>   	 * user config option is valid and the board supports interrupts.
>   	 */
> +	if (it->options[1] < 0 || it->options[1] > 31)
> +		return -EINVAL;
> +
>   	if (it->options[1] && (board->irq_mask & (1 << it->options[1]))) {
>   		ret = request_irq(it->options[1], pcl726_interrupt, 0,
>   				  dev->board_name, dev);

If `it->options[1]` is 31, then `1 << it->options[1]` is still invalid 
because it shifts a 1-bit into the sign bit (which is UB in C). 
Possible solutions include reducing the upper bound on the 
`it->options[1]` value to 30 or lower, or using `1U << it->options[1]`.

-- 
-=( Ian Abbott <abbotti@mev.co.uk> || MEV Ltd. is a company  )=-
-=( registered in England & Wales.  Regd. number: 02862268.  )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-

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

* Re: [PATCH] commdi: pcl726: Prevent invalid irq number
  2025-07-07  9:47   ` Ian Abbott
@ 2025-07-07 10:01     ` Ian Abbott
  2025-07-07 11:43       ` [PATCH V2] " Edward Adam Davis
  0 siblings, 1 reply; 13+ messages in thread
From: Ian Abbott @ 2025-07-07 10:01 UTC (permalink / raw)
  To: Edward Adam Davis, syzbot+5cd373521edd68bebcb3
  Cc: hsweeten, linux-kernel, syzkaller-bugs

On 07/07/2025 10:47, Ian Abbott wrote:
> On 06/07/2025 03:10, Edward Adam Davis wrote:
> 
> The "comedi" tag in the subject line is misspelled.
> 
>> The reproducer passed in an irq number(0x80008000) that was too large,
>> which triggered the oob.
>>
>> Added an interrupt number check to prevent users from passing in an irq
>> number that was too large.
>>
>> Fixes: fff46207245c ("staging: comedi: pcl726: enable the interrupt 
>> support code")
>> Reported-by: syzbot+5cd373521edd68bebcb3@syzkaller.appspotmail.com
>> Closes: https://syzkaller.appspot.com/bug?extid=5cd373521edd68bebcb3
>> Tested-by: syzbot+5cd373521edd68bebcb3@syzkaller.appspotmail.com
> 
> Thanks.
> 
> You could add:
> 
> Cc: <stable@vger.kernel.org> # 5.13+
> 
> to apply it to stable kernels.  (The 5.13+ is because comedi was moved 
> out of the "staging" directory in 5.13, and a backport would be required 
> for longterm series < 5.13.)
> 
> More comments below...
> 
>> Signed-off-by: Edward Adam Davis <eadavis@qq.com>
>> ---
>>   drivers/comedi/drivers/pcl726.c | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/comedi/drivers/pcl726.c b/drivers/comedi/drivers/ 
>> pcl726.c
>> index 0430630e6ebb..8802f33f1954 100644
>> --- a/drivers/comedi/drivers/pcl726.c
>> +++ b/drivers/comedi/drivers/pcl726.c
>> @@ -328,6 +328,9 @@ static int pcl726_attach(struct comedi_device *dev,
>>        * Hook up the external trigger source interrupt only if the
>>        * user config option is valid and the board supports interrupts.
>>        */
>> +    if (it->options[1] < 0 || it->options[1] > 31)
>> +        return -EINVAL;
>> +

I missed this one earlier, but returning `-EINVAL` changes the behavior. 
  The old code would just not attempt to request the IRQ if the 
`options[1]` value were invalid.  And it would still configure the 
device without interrupts even if the call to `request_irq` returned an 
error.  So it would be better to combine this test with the test below.

>>       if (it->options[1] && (board->irq_mask & (1 << it->options[1]))) {
>>           ret = request_irq(it->options[1], pcl726_interrupt, 0,
>>                     dev->board_name, dev);
> 
> If `it->options[1]` is 31, then `1 << it->options[1]` is still invalid 
> because it shifts a 1-bit into the sign bit (which is UB in C). Possible 
> solutions include reducing the upper bound on the `it->options[1]` value 
> to 30 or lower, or using `1U << it->options[1]`.
> 

For example:

	if (it->options[1] > 0 && it->options[1] < 16 &&
             (board->irq_mask & (1U << it->options[1])) {

Thanks.

-- 
-=( Ian Abbott <abbotti@mev.co.uk> || MEV Ltd. is a company  )=-
-=( registered in England & Wales.  Regd. number: 02862268.  )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-

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

* [PATCH V2] commdi: pcl726: Prevent invalid irq number
  2025-07-07 10:01     ` Ian Abbott
@ 2025-07-07 11:43       ` Edward Adam Davis
  2025-07-07 12:23         ` Ian Abbott
  0 siblings, 1 reply; 13+ messages in thread
From: Edward Adam Davis @ 2025-07-07 11:43 UTC (permalink / raw)
  To: abbotti; +Cc: eadavis, hsweeten, linux-kernel, syzkaller-bugs

The reproducer passed in an irq number(0x80008000) that was too large,
which triggered the oob.

Added an interrupt number check to prevent users from passing in an irq
number that was too large.

If `it->options[1]` is 31, then `1 << it->options[1]` is still invalid
because it shifts a 1-bit into the sign bit (which is UB in C).
Possible solutions include reducing the upper bound on the
`it->options[1]` value to 30 or lower, or using `1U << it->options[1]`.

The old code would just not attempt to request the IRQ if the
`options[1]` value were invalid.  And it would still configure the
device without interrupts even if the call to `request_irq` returned an
error.  So it would be better to combine this test with the test below.

Fixes: fff46207245c ("staging: comedi: pcl726: enable the interrupt support code")
Cc: <stable@vger.kernel.org> # 5.13+
Reported-by: syzbot+5cd373521edd68bebcb3@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=5cd373521edd68bebcb3
Tested-by: syzbot+5cd373521edd68bebcb3@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
V1 -> V2: combine test with old test

 drivers/comedi/drivers/pcl726.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/comedi/drivers/pcl726.c b/drivers/comedi/drivers/pcl726.c
index 0430630e6ebb..b542896fa0e4 100644
--- a/drivers/comedi/drivers/pcl726.c
+++ b/drivers/comedi/drivers/pcl726.c
@@ -328,7 +328,8 @@ static int pcl726_attach(struct comedi_device *dev,
 	 * Hook up the external trigger source interrupt only if the
 	 * user config option is valid and the board supports interrupts.
 	 */
-	if (it->options[1] && (board->irq_mask & (1 << it->options[1]))) {
+	if (it->options[1] > 0 && it->options[1] < 16 &&
+	    (board->irq_mask & (1U << it->options[1]))) {
 		ret = request_irq(it->options[1], pcl726_interrupt, 0,
 				  dev->board_name, dev);
 		if (ret == 0) {
-- 
2.43.0


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

* Re: [PATCH V2] commdi: pcl726: Prevent invalid irq number
  2025-07-07 11:43       ` [PATCH V2] " Edward Adam Davis
@ 2025-07-07 12:23         ` Ian Abbott
  2025-07-07 12:39           ` [PATCH V3] comedi: " Edward Adam Davis
  0 siblings, 1 reply; 13+ messages in thread
From: Ian Abbott @ 2025-07-07 12:23 UTC (permalink / raw)
  To: Edward Adam Davis; +Cc: hsweeten, linux-kernel, syzkaller-bugs

On 07/07/2025 12:43, Edward Adam Davis wrote:
> The reproducer passed in an irq number(0x80008000) that was too large,
> which triggered the oob.
> 
> Added an interrupt number check to prevent users from passing in an irq
> number that was too large.
> 
> If `it->options[1]` is 31, then `1 << it->options[1]` is still invalid
> because it shifts a 1-bit into the sign bit (which is UB in C).
> Possible solutions include reducing the upper bound on the
> `it->options[1]` value to 30 or lower, or using `1U << it->options[1]`.
> 
> The old code would just not attempt to request the IRQ if the
> `options[1]` value were invalid.  And it would still configure the
> device without interrupts even if the call to `request_irq` returned an
> error.  So it would be better to combine this test with the test below.
> 
> Fixes: fff46207245c ("staging: comedi: pcl726: enable the interrupt support code")
> Cc: <stable@vger.kernel.org> # 5.13+
> Reported-by: syzbot+5cd373521edd68bebcb3@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=5cd373521edd68bebcb3
> Tested-by: syzbot+5cd373521edd68bebcb3@syzkaller.appspotmail.com
> Signed-off-by: Edward Adam Davis <eadavis@qq.com>
> ---
> V1 -> V2: combine test with old test
> 
>   drivers/comedi/drivers/pcl726.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/comedi/drivers/pcl726.c b/drivers/comedi/drivers/pcl726.c
> index 0430630e6ebb..b542896fa0e4 100644
> --- a/drivers/comedi/drivers/pcl726.c
> +++ b/drivers/comedi/drivers/pcl726.c
> @@ -328,7 +328,8 @@ static int pcl726_attach(struct comedi_device *dev,
>   	 * Hook up the external trigger source interrupt only if the
>   	 * user config option is valid and the board supports interrupts.
>   	 */
> -	if (it->options[1] && (board->irq_mask & (1 << it->options[1]))) {
> +	if (it->options[1] > 0 && it->options[1] < 16 &&
> +	    (board->irq_mask & (1U << it->options[1]))) {
>   		ret = request_irq(it->options[1], pcl726_interrupt, 0,
>   				  dev->board_name, dev);
>   		if (ret == 0) {

Looks good apart from the subject line that still has the "comedi" tag 
misspelled.  Please could you fix that?

You can also add my Reviewed-by: line:

Reviewed-by: Ian Abbott <abbotti@mev.co.uk>

Please also Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> because 
I do not have commit access to any pulled git repos.

Thanks!

-- 
-=( Ian Abbott <abbotti@mev.co.uk> || MEV Ltd. is a company  )=-
-=( registered in England & Wales.  Regd. number: 02862268.  )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-

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

* [PATCH V3] comedi: pcl726: Prevent invalid irq number
  2025-07-07 12:23         ` Ian Abbott
@ 2025-07-07 12:39           ` Edward Adam Davis
  2025-07-24 11:07             ` [PATCH V3 REPOST] " Ian Abbott
  0 siblings, 1 reply; 13+ messages in thread
From: Edward Adam Davis @ 2025-07-07 12:39 UTC (permalink / raw)
  To: abbotti; +Cc: eadavis, hsweeten, linux-kernel, syzkaller-bugs

The reproducer passed in an irq number(0x80008000) that was too large,
which triggered the oob.

Added an interrupt number check to prevent users from passing in an irq
number that was too large.

If `it->options[1]` is 31, then `1 << it->options[1]` is still invalid
because it shifts a 1-bit into the sign bit (which is UB in C).
Possible solutions include reducing the upper bound on the
`it->options[1]` value to 30 or lower, or using `1U << it->options[1]`.

The old code would just not attempt to request the IRQ if the
`options[1]` value were invalid.  And it would still configure the
device without interrupts even if the call to `request_irq` returned an
error.  So it would be better to combine this test with the test below.

Fixes: fff46207245c ("staging: comedi: pcl726: enable the interrupt support code")
Cc: <stable@vger.kernel.org> # 5.13+
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reported-by: syzbot+5cd373521edd68bebcb3@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=5cd373521edd68bebcb3
Tested-by: syzbot+5cd373521edd68bebcb3@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
---
V1 -> V2: combine test with old test
V2 -> V3: fix misspelled

 drivers/comedi/drivers/pcl726.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/comedi/drivers/pcl726.c b/drivers/comedi/drivers/pcl726.c
index 0430630e6ebb..b542896fa0e4 100644
--- a/drivers/comedi/drivers/pcl726.c
+++ b/drivers/comedi/drivers/pcl726.c
@@ -328,7 +328,8 @@ static int pcl726_attach(struct comedi_device *dev,
 	 * Hook up the external trigger source interrupt only if the
 	 * user config option is valid and the board supports interrupts.
 	 */
-	if (it->options[1] && (board->irq_mask & (1 << it->options[1]))) {
+	if (it->options[1] > 0 && it->options[1] < 16 &&
+	    (board->irq_mask & (1U << it->options[1]))) {
 		ret = request_irq(it->options[1], pcl726_interrupt, 0,
 				  dev->board_name, dev);
 		if (ret == 0) {
-- 
2.43.0


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

* [PATCH V3 REPOST] comedi: pcl726: Prevent invalid irq number
  2025-07-07 12:39           ` [PATCH V3] comedi: " Edward Adam Davis
@ 2025-07-24 11:07             ` Ian Abbott
  2025-07-24 11:11               ` Ian Abbott
  0 siblings, 1 reply; 13+ messages in thread
From: Ian Abbott @ 2025-07-24 11:07 UTC (permalink / raw)
  To: linux-kernel
  Cc: Greg Kroah-Hartman, H Hartley Sweeten, Edward Adam Davis,
	syzkaller-bugs, stable, syzbot+5cd373521edd68bebcb3, Ian Abbott

From: Edward Adam Davis <eadavis@qq.com>

The reproducer passed in an irq number(0x80008000) that was too large,
which triggered the oob.

Added an interrupt number check to prevent users from passing in an irq
number that was too large.

If `it->options[1]` is 31, then `1 << it->options[1]` is still invalid
because it shifts a 1-bit into the sign bit (which is UB in C).
Possible solutions include reducing the upper bound on the
`it->options[1]` value to 30 or lower, or using `1U << it->options[1]`.

The old code would just not attempt to request the IRQ if the
`options[1]` value were invalid.  And it would still configure the
device without interrupts even if the call to `request_irq` returned an
error.  So it would be better to combine this test with the test below.

Fixes: fff46207245c ("staging: comedi: pcl726: enable the interrupt support code")
Cc: <stable@vger.kernel.org> # 5.13+
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reported-by: syzbot+5cd373521edd68bebcb3@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=5cd373521edd68bebcb3
Tested-by: syzbot+5cd373521edd68bebcb3@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
---
 drivers/comedi/drivers/pcl726.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/comedi/drivers/pcl726.c b/drivers/comedi/drivers/pcl726.c
index 0430630e6ebb..b542896fa0e4 100644
--- a/drivers/comedi/drivers/pcl726.c
+++ b/drivers/comedi/drivers/pcl726.c
@@ -328,7 +328,8 @@ static int pcl726_attach(struct comedi_device *dev,
 	 * Hook up the external trigger source interrupt only if the
 	 * user config option is valid and the board supports interrupts.
 	 */
-	if (it->options[1] && (board->irq_mask & (1 << it->options[1]))) {
+	if (it->options[1] > 0 && it->options[1] < 16 &&
+	    (board->irq_mask & (1U << it->options[1]))) {
 		ret = request_irq(it->options[1], pcl726_interrupt, 0,
 				  dev->board_name, dev);
 		if (ret == 0) {
-- 
2.47.2


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

* Re: [PATCH V3 REPOST] comedi: pcl726: Prevent invalid irq number
  2025-07-24 11:07             ` [PATCH V3 REPOST] " Ian Abbott
@ 2025-07-24 11:11               ` Ian Abbott
  0 siblings, 0 replies; 13+ messages in thread
From: Ian Abbott @ 2025-07-24 11:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Greg Kroah-Hartman, H Hartley Sweeten, Edward Adam Davis,
	syzkaller-bugs, stable, syzbot+5cd373521edd68bebcb3

On 24/07/2025 12:07, Ian Abbott wrote:
> From: Edward Adam Davis <eadavis@qq.com>
> 
> The reproducer passed in an irq number(0x80008000) that was too large,
> which triggered the oob.
> 
> Added an interrupt number check to prevent users from passing in an irq
> number that was too large.
> 
> If `it->options[1]` is 31, then `1 << it->options[1]` is still invalid
> because it shifts a 1-bit into the sign bit (which is UB in C).
> Possible solutions include reducing the upper bound on the
> `it->options[1]` value to 30 or lower, or using `1U << it->options[1]`.
> 
> The old code would just not attempt to request the IRQ if the
> `options[1]` value were invalid.  And it would still configure the
> device without interrupts even if the call to `request_irq` returned an
> error.  So it would be better to combine this test with the test below.
> 
> Fixes: fff46207245c ("staging: comedi: pcl726: enable the interrupt support code")
> Cc: <stable@vger.kernel.org> # 5.13+
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Reported-by: syzbot+5cd373521edd68bebcb3@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=5cd373521edd68bebcb3
> Tested-by: syzbot+5cd373521edd68bebcb3@syzkaller.appspotmail.com
> Signed-off-by: Edward Adam Davis <eadavis@qq.com>
> Reviewed-by: Ian Abbott <abbotti@mev.co.uk>

I forgot to append the changelog from the original email:

V1 -> V2: combine test with old test
V2 -> V3: fix misspelled

Ian

-- 
-=( Ian Abbott <abbotti@mev.co.uk> || MEV Ltd. is a company  )=-
-=( registered in England & Wales.  Regd. number: 02862268.  )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-

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

end of thread, other threads:[~2025-07-24 12:26 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-05 11:02 [syzbot] [kernel?] UBSAN: shift-out-of-bounds in pcl726_attach syzbot
2025-07-05 12:47 ` Hillf Danton
2025-07-05 13:06   ` syzbot
2025-07-06  1:51 ` Edward Adam Davis
2025-07-06  2:10   ` syzbot
2025-07-06  2:10 ` [PATCH] commdi: pcl726: Prevent invalid irq number Edward Adam Davis
2025-07-07  9:47   ` Ian Abbott
2025-07-07 10:01     ` Ian Abbott
2025-07-07 11:43       ` [PATCH V2] " Edward Adam Davis
2025-07-07 12:23         ` Ian Abbott
2025-07-07 12:39           ` [PATCH V3] comedi: " Edward Adam Davis
2025-07-24 11:07             ` [PATCH V3 REPOST] " Ian Abbott
2025-07-24 11:11               ` Ian Abbott

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).