public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [syzbot] [media?] WARNING in __v4l2_ctrl_modify_dimensions
@ 2024-09-02 18:57 syzbot
  2024-09-03  2:57 ` Edward Adam Davis
  0 siblings, 1 reply; 4+ messages in thread
From: syzbot @ 2024-09-02 18:57 UTC (permalink / raw)
  To: linux-kernel, linux-media, mchehab, syzkaller-bugs

Hello,

syzbot found the following issue on:

HEAD commit:    1934261d8974 Merge tag 'input-for-v6.11-rc5' of git://git...
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=14d51929980000
kernel config:  https://syzkaller.appspot.com/x/.config?x=996585887acdadb3
dashboard link: https://syzkaller.appspot.com/bug?extid=a828133770f62293563e
compiler:       Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=1250552b980000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=1641150b980000

Downloadable assets:
disk image (non-bootable): https://storage.googleapis.com/syzbot-assets/7bc7510fe41f/non_bootable_disk-1934261d.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/dae6d4b5572b/vmlinux-1934261d.xz
kernel image: https://storage.googleapis.com/syzbot-assets/aabe290f51ea/bzImage-1934261d.xz

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

------------[ cut here ]------------
WARNING: CPU: 0 PID: 5111 at mm/util.c:665 __kvmalloc_node_noprof+0x17a/0x190 mm/util.c:665
Modules linked in:
CPU: 0 UID: 0 PID: 5111 Comm: syz-executor170 Not tainted 6.11.0-rc5-syzkaller-00219-g1934261d8974 #0
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2~bpo12+1 04/01/2014
RIP: 0010:__kvmalloc_node_noprof+0x17a/0x190 mm/util.c:665
Code: cc 44 89 fe 81 e6 00 20 00 00 31 ff e8 bf 23 bb ff 41 81 e7 00 20 00 00 74 0a e8 71 1f bb ff e9 3b ff ff ff e8 67 1f bb ff 90 <0f> 0b 90 e9 2d ff ff ff 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00
RSP: 0018:ffffc9000323f930 EFLAGS: 00010293
RAX: ffffffff81d86cc9 RBX: 00000000da6b5000 RCX: ffff88801ca92440
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
RBP: 0000000000000000 R08: ffffffff81d86cb1 R09: 00000000ffffffff
R10: ffffc9000323f7a0 R11: fffff52000647ef9 R12: 00000000da6b5000
R13: ffffc9000323fa60 R14: 00000000ffffffff R15: 0000000000000000
FS:  000055555ed0c380(0000) GS:ffff88801fe00000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f12c2b010f0 CR3: 000000003d746000 CR4: 0000000000350ef0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 <TASK>
 __v4l2_ctrl_modify_dimensions+0x43b/0xb60 drivers/media/v4l2-core/v4l2-ctrls-api.c:999
 v4l2_ctrl_modify_dimensions include/media/v4l2-ctrls.h:1013 [inline]
 vivid_update_format_cap+0x133c/0x2090 drivers/media/test-drivers/vivid/vivid-vid-cap.c:458
 vivid_vid_cap_s_dv_timings+0x535/0x1230 drivers/media/test-drivers/vivid/vivid-vid-cap.c:1500
 __video_do_ioctl+0xc26/0xde0 drivers/media/v4l2-core/v4l2-ioctl.c:3118
 video_usercopy+0x89b/0x1180 drivers/media/v4l2-core/v4l2-ioctl.c:3459
 v4l2_ioctl+0x18c/0x1e0 drivers/media/v4l2-core/v4l2-dev.c:364
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:907 [inline]
 __se_sys_ioctl+0xfc/0x170 fs/ioctl.c:893
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f12c2a8a939
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 c1 17 00 00 90 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:00007ffcb8e91828 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f12c2a8a939
RDX: 0000000020000200 RSI: 00000000c0845657 RDI: 0000000000000003
RBP: 00007f12c2afd5f0 R08: 0000000000000006 R09: 0000000000000006
R10: 00236962762f7665 R11: 0000000000000246 R12: 0000000000000001
R13: 431bde82d7b634db R14: 0000000000000001 R15: 0000000000000001
 </TASK>


---
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] 4+ messages in thread

* Re: [syzbot] [media?] WARNING in __v4l2_ctrl_modify_dimensions
  2024-09-02 18:57 [syzbot] [media?] WARNING in __v4l2_ctrl_modify_dimensions syzbot
@ 2024-09-03  2:57 ` Edward Adam Davis
  2024-09-03  3:18   ` syzbot
  2024-09-03 10:24   ` Hans Verkuil
  0 siblings, 2 replies; 4+ messages in thread
From: Edward Adam Davis @ 2024-09-03  2:57 UTC (permalink / raw)
  To: syzbot+a828133770f62293563e
  Cc: linux-kernel, linux-media, mchehab, syzkaller-bugs

The warning appears because the size passed to kvzalloc is larger than INT_MAX.

Add parameter size check before calling kvzalloc in __v4l2_ctrl_modify_dimensions.

#syz test

diff --git a/drivers/media/v4l2-core/v4l2-ctrls-api.c b/drivers/media/v4l2-core/v4l2-ctrls-api.c
index e5a364efd5e6..0b008cc94901 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-api.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-api.c
@@ -986,6 +986,7 @@ int __v4l2_ctrl_modify_dimensions(struct v4l2_ctrl *ctrl,
 	unsigned int elems = 1;
 	unsigned int i;
 	void *p_array;
+	unsigned int bytes;
 
 	lockdep_assert_held(ctrl->handler->lock);
 
@@ -996,7 +997,12 @@ int __v4l2_ctrl_modify_dimensions(struct v4l2_ctrl *ctrl,
 		elems *= dims[i];
 	if (elems == 0)
 		return -EINVAL;
-	p_array = kvzalloc(2 * elems * ctrl->elem_size, GFP_KERNEL);
+
+	bytes = 2 * elems * ctrl->elem_size;
+	if (unlikely(bytes > INT_MAX))
+		return -EINVAL;
+
+	p_array = kvzalloc(bytes, GFP_KERNEL);
 	if (!p_array)
 		return -ENOMEM;
 	kvfree(ctrl->p_array);


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

* Re: [syzbot] [media?] WARNING in __v4l2_ctrl_modify_dimensions
  2024-09-03  2:57 ` Edward Adam Davis
@ 2024-09-03  3:18   ` syzbot
  2024-09-03 10:24   ` Hans Verkuil
  1 sibling, 0 replies; 4+ messages in thread
From: syzbot @ 2024-09-03  3:18 UTC (permalink / raw)
  To: eadavis, linux-kernel, linux-media, mchehab, syzkaller-bugs

Hello,

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

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

Tested on:

commit:         67784a74 Merge tag 'ata-6.11-rc7' of git://git.kernel...
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=11b49929980000
kernel config:  https://syzkaller.appspot.com/x/.config?x=660f6eb11f9c7dc5
dashboard link: https://syzkaller.appspot.com/bug?extid=a828133770f62293563e
compiler:       Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch:          https://syzkaller.appspot.com/x/patch.diff?x=143f0f33980000

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

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

* Re: [syzbot] [media?] WARNING in __v4l2_ctrl_modify_dimensions
  2024-09-03  2:57 ` Edward Adam Davis
  2024-09-03  3:18   ` syzbot
@ 2024-09-03 10:24   ` Hans Verkuil
  1 sibling, 0 replies; 4+ messages in thread
From: Hans Verkuil @ 2024-09-03 10:24 UTC (permalink / raw)
  To: Edward Adam Davis, syzbot+a828133770f62293563e
  Cc: linux-kernel, linux-media, mchehab, syzkaller-bugs

Hi Edward,

On 03/09/2024 04:57, Edward Adam Davis wrote:
> The warning appears because the size passed to kvzalloc is larger than INT_MAX.
> 
> Add parameter size check before calling kvzalloc in __v4l2_ctrl_modify_dimensions.

I missed the original syzbot post, it ended up in my Spam folder :-(

In any case, this patch doesn't address the real problem, which is that vivid
was missing a check to prevent bad width and height values to be rejected. And
those checks really should take place in core functionality.

I've made a patch for that (you're CC-ed).

Regards,

	Hans

> 
> #syz test
> 
> diff --git a/drivers/media/v4l2-core/v4l2-ctrls-api.c b/drivers/media/v4l2-core/v4l2-ctrls-api.c
> index e5a364efd5e6..0b008cc94901 100644
> --- a/drivers/media/v4l2-core/v4l2-ctrls-api.c
> +++ b/drivers/media/v4l2-core/v4l2-ctrls-api.c
> @@ -986,6 +986,7 @@ int __v4l2_ctrl_modify_dimensions(struct v4l2_ctrl *ctrl,
>  	unsigned int elems = 1;
>  	unsigned int i;
>  	void *p_array;
> +	unsigned int bytes;
>  
>  	lockdep_assert_held(ctrl->handler->lock);
>  
> @@ -996,7 +997,12 @@ int __v4l2_ctrl_modify_dimensions(struct v4l2_ctrl *ctrl,
>  		elems *= dims[i];
>  	if (elems == 0)
>  		return -EINVAL;
> -	p_array = kvzalloc(2 * elems * ctrl->elem_size, GFP_KERNEL);
> +
> +	bytes = 2 * elems * ctrl->elem_size;
> +	if (unlikely(bytes > INT_MAX))
> +		return -EINVAL;
> +
> +	p_array = kvzalloc(bytes, GFP_KERNEL);
>  	if (!p_array)
>  		return -ENOMEM;
>  	kvfree(ctrl->p_array);
> 
> 


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

end of thread, other threads:[~2024-09-03 10:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-02 18:57 [syzbot] [media?] WARNING in __v4l2_ctrl_modify_dimensions syzbot
2024-09-03  2:57 ` Edward Adam Davis
2024-09-03  3:18   ` syzbot
2024-09-03 10:24   ` Hans Verkuil

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