2021-07-14 18:58:13

by syzbot

[permalink] [raw]
Subject: [syzbot] WARNING in internal_create_group

Hello,

syzbot found the following issue on:

HEAD commit: 5d52c906f059 Merge git://git.kernel.org/pub/scm/linux/kern..
git tree: net
console output: https://syzkaller.appspot.com/x/log.txt?x=16acf1e2300000
kernel config: https://syzkaller.appspot.com/x/.config?x=51ea6c9df4ed04c4
dashboard link: https://syzkaller.appspot.com/bug?extid=9937dc42271cd87d4b98

Unfortunately, I don't have any reproducer for this issue yet.

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: [email protected]

------------[ cut here ]------------
WARNING: CPU: 1 PID: 9350 at fs/sysfs/group.c:116 internal_create_group+0x911/0xb20 fs/sysfs/group.c:116
Modules linked in:
CPU: 1 PID: 9350 Comm: syz-executor.4 Not tainted 5.13.0-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
RIP: 0010:internal_create_group+0x911/0xb20 fs/sysfs/group.c:116
Code: 0f 85 e8 f7 ff ff 41 bd ea ff ff ff e9 34 fd ff ff e8 33 bc 82 ff 48 8b 7c 24 08 e8 89 11 ff ff e9 20 fd ff ff e8 1f bc 82 ff <0f> 0b 41 bd ea ff ff ff e9 0e fd ff ff e8 0d bc 82 ff 48 8b 14 24
RSP: 0018:ffffc9000181f2b0 EFLAGS: 00010246
RAX: 0000000000040000 RBX: 0000000000000000 RCX: ffffc90012931000
RDX: 0000000000040000 RSI: ffffffff81f2c5f1 RDI: 0000000000000003
RBP: ffff8880706b9d08 R08: 0000000000000000 R09: ffff8880706b9d0f
R10: ffffffff81f2bd9e R11: 0000000000000000 R12: 0000000000000000
R13: ffff88809a948070 R14: 0000000000000000 R15: ffff88809a94807c
FS: 00007feaac597700(0000) GS:ffff8880b9c00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000006f6c CR3: 000000009d5fa000 CR4: 00000000001506f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
blk_register_queue+0xda/0x570 block/blk-sysfs.c:871
__device_add_disk+0x7b5/0xd10 block/genhd.c:529
add_disk include/linux/genhd.h:217 [inline]
nbd_dev_add+0x712/0x900 drivers/block/nbd.c:1709
nbd_genl_connect+0x551/0x1660 drivers/block/nbd.c:1817
genl_family_rcv_msg_doit+0x228/0x320 net/netlink/genetlink.c:739
genl_family_rcv_msg net/netlink/genetlink.c:783 [inline]
genl_rcv_msg+0x328/0x580 net/netlink/genetlink.c:800
netlink_rcv_skb+0x153/0x420 net/netlink/af_netlink.c:2504
genl_rcv+0x24/0x40 net/netlink/genetlink.c:811
netlink_unicast_kernel net/netlink/af_netlink.c:1314 [inline]
netlink_unicast+0x533/0x7d0 net/netlink/af_netlink.c:1340
netlink_sendmsg+0x85b/0xda0 net/netlink/af_netlink.c:1929
sock_sendmsg_nosec net/socket.c:703 [inline]
sock_sendmsg+0xcf/0x120 net/socket.c:723
____sys_sendmsg+0x6e8/0x810 net/socket.c:2392
___sys_sendmsg+0xf3/0x170 net/socket.c:2446
__sys_sendmsg+0xe5/0x1b0 net/socket.c:2475
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0xae
RIP: 0033:0x4665d9
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 bc ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007feaac597188 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 000000000056bf80 RCX: 00000000004665d9
RDX: 0000000000000000 RSI: 0000000020000540 RDI: 0000000000000008
RBP: 00000000004bfcb9 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 000000000056bf80
R13: 00007ffe11ff566f R14: 00007feaac597300 R15: 0000000000022000


---
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 [email protected].

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


2021-07-20 18:55:52

by syzbot

[permalink] [raw]
Subject: Re: [syzbot] WARNING in internal_create_group

syzbot has found a reproducer for the following issue on:

HEAD commit: 8cae8cd89f05 seq_file: disallow extremely large seq buffer..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=116f92ec300000
kernel config: https://syzkaller.appspot.com/x/.config?x=7273c75708b55890
dashboard link: https://syzkaller.appspot.com/bug?extid=9937dc42271cd87d4b98
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=15fc287c300000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=178cbf6a300000

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: [email protected]

RSP: 002b:00007ffd8de69d18 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 00000000004004a0 RCX: 000000000043fa49
RDX: 0000000000000000 RSI: 00000000200002c0 RDI: 0000000000000004
RBP: 00000000004034b0 R08: 0000000000000000 R09: 00000000004004a0
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000403540
R13: 0000000000000000 R14: 00000000004ad018 R15: 00000000004004a0
------------[ cut here ]------------
WARNING: CPU: 0 PID: 8435 at fs/sysfs/group.c:116 internal_create_group+0x911/0xb20 fs/sysfs/group.c:116
Modules linked in:
CPU: 0 PID: 8435 Comm: syz-executor570 Not tainted 5.14.0-rc2-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
RIP: 0010:internal_create_group+0x911/0xb20 fs/sysfs/group.c:116
Code: 0f 85 e8 f7 ff ff 41 bd ea ff ff ff e9 34 fd ff ff e8 53 3b 82 ff 48 8b 7c 24 08 e8 89 11 ff ff e9 20 fd ff ff e8 3f 3b 82 ff <0f> 0b 41 bd ea ff ff ff e9 0e fd ff ff e8 2d 3b 82 ff 48 8b 14 24
RSP: 0018:ffffc900010ff2a8 EFLAGS: 00010293
RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
RDX: ffff8880284f0000 RSI: ffffffff81f34d91 RDI: 0000000000000003
RBP: ffff88801fd7b9a8 R08: 0000000000000000 R09: ffff88801fd7b9af
R10: ffffffff81f3453e R11: 0000000000000000 R12: 0000000000000000
R13: ffff8881455db770 R14: 0000000000000000 R15: ffff8881455db77c
FS: 0000000000990300(0000) GS:ffff8880b9c00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f56bbe93740 CR3: 000000001dd48000 CR4: 0000000000350ef0
Call Trace:
blk_register_queue+0xda/0x570 block/blk-sysfs.c:871
__device_add_disk+0x7b5/0xd10 block/genhd.c:529
add_disk include/linux/genhd.h:217 [inline]
nbd_dev_add+0x73f/0x940 drivers/block/nbd.c:1733
nbd_genl_connect+0x551/0x1820 drivers/block/nbd.c:1842
genl_family_rcv_msg_doit+0x228/0x320 net/netlink/genetlink.c:739
genl_family_rcv_msg net/netlink/genetlink.c:783 [inline]
genl_rcv_msg+0x328/0x580 net/netlink/genetlink.c:800
netlink_rcv_skb+0x153/0x420 net/netlink/af_netlink.c:2504
genl_rcv+0x24/0x40 net/netlink/genetlink.c:811
netlink_unicast_kernel net/netlink/af_netlink.c:1314 [inline]
netlink_unicast+0x533/0x7d0 net/netlink/af_netlink.c:1340
netlink_sendmsg+0x86d/0xdb0 net/netlink/af_netlink.c:1929
sock_sendmsg_nosec net/socket.c:703 [inline]
sock_sendmsg+0xcf/0x120 net/socket.c:723
____sys_sendmsg+0x6e8/0x810 net/socket.c:2392
___sys_sendmsg+0xf3/0x170 net/socket.c:2446
__sys_sendmsg+0xe5/0x1b0 net/socket.c:2475
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0xae
RIP: 0033:0x43fa49
Code: 28 c3 e8 5a 14 00 00 66 2e 0f 1f 84 00 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 c0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd8de69d18 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 00000000004004a0 RCX: 000000000043fa49
RDX: 0000000000000000 RSI: 00000000200002c0 RDI: 0000000000000004
RBP: 00000000004034b0 R08: 0000000000000000 R09: 00000000004004a0
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000403540
R13: 0000000000000000 R14: 00000000004ad018 R15: 00000000004004a0

2021-07-21 04:34:34

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [syzbot] WARNING in internal_create_group

On Wed, Jul 21, 2021 at 11:37:03AM +0800, Hillf Danton wrote:
> On Tue, 20 Jul 2021 11:53:27 -0700
> >syzbot has found a reproducer for the following issue on:
> >
> >HEAD commit: 8cae8cd89f05 seq_file: disallow extremely large seq buffer..
> >git tree: upstream
> >console output: https://syzkaller.appspot.com/x/log.txt?x=116f92ec300000
> >kernel config: https://syzkaller.appspot.com/x/.config?x=7273c75708b55890
> >dashboard link: https://syzkaller.appspot.com/bug?extid=9937dc42271cd87d4b98
> >syz repro: https://syzkaller.appspot.com/x/repro.syz?x=15fc287c300000
> >C reproducer: https://syzkaller.appspot.com/x/repro.c?x=178cbf6a300000

<snip>

> >WARNING: CPU: 0 PID: 8435 at fs/sysfs/group.c:116 internal_create_group+0x911/0xb20 fs/sysfs/group.c:116

<snip>

> The device_add(ddev) in register_disk() may fail but it proceeds to register
> block queue even at the failure ... this falls in the class of known issue
> given the comment line.
>
> * FIXME: error handling
> */
> static void __device_add_disk(struct device *parent, struct gendisk *disk,

Yes, Luis is working on actually fixing this - but it requires changes
to every single block driver. How does a cap on the seq_buf size
propagate here, though?

2021-08-11 21:38:52

by Pavel Skripkin

[permalink] [raw]
Subject: Re: [syzbot] WARNING in internal_create_group

On 7/21/21 7:30 AM, Christoph Hellwig wrote:
> On Wed, Jul 21, 2021 at 11:37:03AM +0800, Hillf Danton wrote:
>> On Tue, 20 Jul 2021 11:53:27 -0700
>> >syzbot has found a reproducer for the following issue on:
>> >
>> >HEAD commit: 8cae8cd89f05 seq_file: disallow extremely large seq buffer..
>> >git tree: upstream
>> >console output: https://syzkaller.appspot.com/x/log.txt?x=116f92ec300000
>> >kernel config: https://syzkaller.appspot.com/x/.config?x=7273c75708b55890
>> >dashboard link: https://syzkaller.appspot.com/bug?extid=9937dc42271cd87d4b98
>> >syz repro: https://syzkaller.appspot.com/x/repro.syz?x=15fc287c300000
>> >C reproducer: https://syzkaller.appspot.com/x/repro.c?x=178cbf6a300000
>
> <snip>
>
>> >WARNING: CPU: 0 PID: 8435 at fs/sysfs/group.c:116 internal_create_group+0x911/0xb20 fs/sysfs/group.c:116
>
> <snip>
>
>> The device_add(ddev) in register_disk() may fail but it proceeds to register
>> block queue even at the failure ... this falls in the class of known issue
>> given the comment line.
>>
>> * FIXME: error handling
>> */
>> static void __device_add_disk(struct device *parent, struct gendisk *disk,
>
> Yes, Luis is working on actually fixing this - but it requires changes
> to every single block driver. How does a cap on the seq_buf size
> propagate here, though?
>

Hi!

I've looked into this, and, I think, we can add sanity check for
first_minor. If user will pass too big index (syzbot's repro passes
1048576) this value will be shifted to part_shift and then truncated to
byte in __device_add_disk() and assigned to dev->devt. User may be
confused about why he passed 1048576, but sysfs warns about duplicate
creation of /dev/block/43:0

So, these type of errors can be handled before passing wrong values to
sysfs API like this:

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index c38317979f74..600e9bab5d43 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1725,7 +1725,17 @@ static int nbd_dev_add(int index)
refcount_set(&nbd->refs, 1);
INIT_LIST_HEAD(&nbd->list);
disk->major = NBD_MAJOR;
+
+ /* Too big first_minor can cause duplicate creation of
+ * sysfs files/links, since first_minor will be truncated to
+ * byte in __device_add_disk().
+ */
disk->first_minor = index << part_shift;
+ if (disk->first_minor > 0xff) {
+ err = -EINVAL;
+ goto out_free_idr;
+ }
+
disk->minors = 1 << part_shift;
disk->fops = &nbd_fops;
disk->private_data = nbd;


What to do you think about it?


With regards,
Pavel Skripkin

2021-08-12 07:37:09

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [syzbot] WARNING in internal_create_group

On Thu, Aug 12, 2021 at 12:37:08AM +0300, Pavel Skripkin wrote:
> --- a/drivers/block/nbd.c
> +++ b/drivers/block/nbd.c
> @@ -1725,7 +1725,17 @@ static int nbd_dev_add(int index)
> refcount_set(&nbd->refs, 1);
> INIT_LIST_HEAD(&nbd->list);
> disk->major = NBD_MAJOR;
> +
> + /* Too big first_minor can cause duplicate creation of
> + * sysfs files/links, since first_minor will be truncated to
> + * byte in __device_add_disk().
> + */
> disk->first_minor = index << part_shift;
> + if (disk->first_minor > 0xff) {
> + err = -EINVAL;
> + goto out_free_idr;
> + }
> +
> disk->minors = 1 << part_shift;
> disk->fops = &nbd_fops;
> disk->private_data = nbd;
>
>
> What to do you think about it?

This sounds reasonable and looks good to me.

2021-09-16 06:59:21

by Joel Stanley

[permalink] [raw]
Subject: Re: [syzbot] WARNING in internal_create_group

On Wed, 11 Aug 2021 at 21:39, Pavel Skripkin <[email protected]> wrote:
>
> On 7/21/21 7:30 AM, Christoph Hellwig wrote:
> > On Wed, Jul 21, 2021 at 11:37:03AM +0800, Hillf Danton wrote:
> >> On Tue, 20 Jul 2021 11:53:27 -0700
> >> >syzbot has found a reproducer for the following issue on:
> >> >
> >> >HEAD commit: 8cae8cd89f05 seq_file: disallow extremely large seq buffer..
> >> >git tree: upstream
> >> >console output: https://syzkaller.appspot.com/x/log.txt?x=116f92ec300000
> >> >kernel config: https://syzkaller.appspot.com/x/.config?x=7273c75708b55890
> >> >dashboard link: https://syzkaller.appspot.com/bug?extid=9937dc42271cd87d4b98
> >> >syz repro: https://syzkaller.appspot.com/x/repro.syz?x=15fc287c300000
> >> >C reproducer: https://syzkaller.appspot.com/x/repro.c?x=178cbf6a300000
> >
> > <snip>
> >
> >> >WARNING: CPU: 0 PID: 8435 at fs/sysfs/group.c:116 internal_create_group+0x911/0xb20 fs/sysfs/group.c:116
> >
> > <snip>
> >
> >> The device_add(ddev) in register_disk() may fail but it proceeds to register
> >> block queue even at the failure ... this falls in the class of known issue
> >> given the comment line.
> >>
> >> * FIXME: error handling
> >> */
> >> static void __device_add_disk(struct device *parent, struct gendisk *disk,
> >
> > Yes, Luis is working on actually fixing this - but it requires changes
> > to every single block driver. How does a cap on the seq_buf size
> > propagate here, though?
> >
>
> Hi!
>
> I've looked into this, and, I think, we can add sanity check for
> first_minor. If user will pass too big index (syzbot's repro passes
> 1048576) this value will be shifted to part_shift and then truncated to
> byte in __device_add_disk() and assigned to dev->devt. User may be
> confused about why he passed 1048576, but sysfs warns about duplicate
> creation of /dev/block/43:0
>
> So, these type of errors can be handled before passing wrong values to
> sysfs API like this:
>
> diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
> index c38317979f74..600e9bab5d43 100644
> --- a/drivers/block/nbd.c
> +++ b/drivers/block/nbd.c
> @@ -1725,7 +1725,17 @@ static int nbd_dev_add(int index)
> refcount_set(&nbd->refs, 1);
> INIT_LIST_HEAD(&nbd->list);
> disk->major = NBD_MAJOR;
> +
> + /* Too big first_minor can cause duplicate creation of
> + * sysfs files/links, since first_minor will be truncated to
> + * byte in __device_add_disk().
> + */
> disk->first_minor = index << part_shift;
> + if (disk->first_minor > 0xff) {
> + err = -EINVAL;
> + goto out_free_idr;
> + }
> +
> disk->minors = 1 << part_shift;
> disk->fops = &nbd_fops;
> disk->private_data = nbd;
>

This one got backported to v5.10.65, and causes a warning on boot:

[ 7.114976] ------------[ cut here ]------------
[ 7.116811] WARNING: CPU: 0 PID: 1 at block/blk-mq.c:3045
blk_mq_release+0x84/0x114
[ 7.117510] Modules linked in:
[ 7.118593] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.10.65 #196
[ 7.118691] Hardware name: Generic DT based system
[ 7.119088] Backtrace:
[ 7.119675] [<8093aff0>] (dump_backtrace) from [<8093b294>]
(show_stack+0x20/0x24)
[ 7.120052] r7:00000009 r6:60000153 r5:00000000 r4:80e75938
[ 7.120223] [<8093b274>] (show_stack) from [<80940938>]
(dump_stack+0xc8/0xe4)
[ 7.120298] [<80940870>] (dump_stack) from [<80123174>] (__warn+0xe8/0x154)
[ 7.120355] r7:00000009 r6:00000be5 r5:804bc594 r4:80b53c80
[ 7.120415] [<8012308c>] (__warn) from [<8093b9b4>]
(warn_slowpath_fmt+0x6c/0xe4)
[ 7.120465] r7:00000009 r6:00000be5 r5:80b53c80 r4:00000000
[ 7.120537] [<8093b94c>] (warn_slowpath_fmt) from [<804bc594>]
(blk_mq_release+0x84/0x114)
[ 7.120594] r8:80b53c80 r7:857b7390 r6:00000001 r5:80ea6efd r4:00000000
[ 7.120656] [<804bc510>] (blk_mq_release) from [<804ad65c>]
(blk_release_queue+0xb8/0x128)
[ 7.120756] r9:00000001 r8:80eee400 r7:00000000 r6:857b7390
r5:00000001 r4:857b73d8
[ 7.120836] [<804ad5a4>] (blk_release_queue) from [<8052f87c>]
(kobject_put+0xc8/0x210)
[ 7.120891] r7:00000000 r6:00000000 r5:80e751bc r4:857b73d8
[ 7.120948] [<8052f7b4>] (kobject_put) from [<804a9b00>]
(blk_put_queue+0x1c/0x20)
[ 7.120998] r7:00000000 r6:857b3800 r5:00000000 r4:857b3860
[ 7.121055] [<804a9ae4>] (blk_put_queue) from [<804c2784>]
(disk_release+0xb0/0x118)
[ 7.121118] [<804c26d4>] (disk_release) from [<805f717c>]
(device_release+0x40/0xb4)
[ 7.121168] r7:00000000 r6:00000000 r5:00000000 r4:857b3860
[ 7.121224] [<805f713c>] (device_release) from [<8052f87c>]
(kobject_put+0xc8/0x210)
[ 7.121265] r5:80e81154 r4:857b3860
[ 7.121318] [<8052f7b4>] (kobject_put) from [<804c1c74>] (put_disk+0x24/0x28)
[ 7.121368] r7:ffffffea r6:00000008 r5:857b3800 r4:857bca00
[ 7.121440] [<804c1c50>] (put_disk) from [<806286f4>]
(nbd_dev_add+0x214/0x27c)
[ 7.121670] [<806284e0>] (nbd_dev_add) from [<80d22f80>]
(nbd_init+0xec/0x120)
[ 7.121740] r10:80ec7000 r9:80c06b34 r8:80d39834 r7:00000000
r6:80e82aa8 r5:00000009
[ 7.121777] r4:00000000
[ 7.121842] [<80d22e94>] (nbd_init) from [<80102364>]
(do_one_initcall+0x50/0x274)
[ 7.121893] r7:00000000 r6:00000007 r5:8116d180 r4:80d22e94
[ 7.121956] [<80102314>] (do_one_initcall) from [<80d012e8>]
(kernel_init_freeable+0x1b8/0x240)
[ 7.122005] r7:80d39854 r6:00000007 r5:8116d180 r4:80d5e788
[ 7.122067] [<80d01130>] (kernel_init_freeable) from [<80947bac>]
(kernel_init+0x18/0x130)
[ 7.122126] r10:00000000 r9:00000000 r8:00000000 r7:00000000
r6:00000000 r5:80947b94
[ 7.122161] r4:00000000
[ 7.122218] [<80947b94>] (kernel_init) from [<80100168>]
(ret_from_fork+0x14/0x2c)
[ 7.122413] Exception stack(0x810b7fb0 to 0x810b7ff8)
[ 7.122936] 7fa0: 00000000
00000000 00000000 00000000
[ 7.123287] 7fc0: 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000
[ 7.123545] 7fe0: 00000000 00000000 00000000 00000000 00000013 00000000
[ 7.123728] r5:80947b94 r4:00000000
[ 7.124011] ---[ end trace d69e5842dc8c9352 ]---

There's been a bit going on in this driver since v5.10, so I assume
it's missing some dependent changes.

Cheers,

Joel

2021-09-16 08:06:33

by Greg KH

[permalink] [raw]
Subject: Re: [syzbot] WARNING in internal_create_group

On Thu, Sep 16, 2021 at 06:55:13AM +0000, Joel Stanley wrote:
> On Wed, 11 Aug 2021 at 21:39, Pavel Skripkin <[email protected]> wrote:
> >
> > On 7/21/21 7:30 AM, Christoph Hellwig wrote:
> > > On Wed, Jul 21, 2021 at 11:37:03AM +0800, Hillf Danton wrote:
> > >> On Tue, 20 Jul 2021 11:53:27 -0700
> > >> >syzbot has found a reproducer for the following issue on:
> > >> >
> > >> >HEAD commit: 8cae8cd89f05 seq_file: disallow extremely large seq buffer..
> > >> >git tree: upstream
> > >> >console output: https://syzkaller.appspot.com/x/log.txt?x=116f92ec300000
> > >> >kernel config: https://syzkaller.appspot.com/x/.config?x=7273c75708b55890
> > >> >dashboard link: https://syzkaller.appspot.com/bug?extid=9937dc42271cd87d4b98
> > >> >syz repro: https://syzkaller.appspot.com/x/repro.syz?x=15fc287c300000
> > >> >C reproducer: https://syzkaller.appspot.com/x/repro.c?x=178cbf6a300000
> > >
> > > <snip>
> > >
> > >> >WARNING: CPU: 0 PID: 8435 at fs/sysfs/group.c:116 internal_create_group+0x911/0xb20 fs/sysfs/group.c:116
> > >
> > > <snip>
> > >
> > >> The device_add(ddev) in register_disk() may fail but it proceeds to register
> > >> block queue even at the failure ... this falls in the class of known issue
> > >> given the comment line.
> > >>
> > >> * FIXME: error handling
> > >> */
> > >> static void __device_add_disk(struct device *parent, struct gendisk *disk,
> > >
> > > Yes, Luis is working on actually fixing this - but it requires changes
> > > to every single block driver. How does a cap on the seq_buf size
> > > propagate here, though?
> > >
> >
> > Hi!
> >
> > I've looked into this, and, I think, we can add sanity check for
> > first_minor. If user will pass too big index (syzbot's repro passes
> > 1048576) this value will be shifted to part_shift and then truncated to
> > byte in __device_add_disk() and assigned to dev->devt. User may be
> > confused about why he passed 1048576, but sysfs warns about duplicate
> > creation of /dev/block/43:0
> >
> > So, these type of errors can be handled before passing wrong values to
> > sysfs API like this:
> >
> > diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
> > index c38317979f74..600e9bab5d43 100644
> > --- a/drivers/block/nbd.c
> > +++ b/drivers/block/nbd.c
> > @@ -1725,7 +1725,17 @@ static int nbd_dev_add(int index)
> > refcount_set(&nbd->refs, 1);
> > INIT_LIST_HEAD(&nbd->list);
> > disk->major = NBD_MAJOR;
> > +
> > + /* Too big first_minor can cause duplicate creation of
> > + * sysfs files/links, since first_minor will be truncated to
> > + * byte in __device_add_disk().
> > + */
> > disk->first_minor = index << part_shift;
> > + if (disk->first_minor > 0xff) {
> > + err = -EINVAL;
> > + goto out_free_idr;
> > + }
> > +
> > disk->minors = 1 << part_shift;
> > disk->fops = &nbd_fops;
> > disk->private_data = nbd;
> >
>
> This one got backported to v5.10.65, and causes a warning on boot:
>
> [ 7.114976] ------------[ cut here ]------------
> [ 7.116811] WARNING: CPU: 0 PID: 1 at block/blk-mq.c:3045
> blk_mq_release+0x84/0x114
> [ 7.117510] Modules linked in:
> [ 7.118593] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.10.65 #196
> [ 7.118691] Hardware name: Generic DT based system
> [ 7.119088] Backtrace:
> [ 7.119675] [<8093aff0>] (dump_backtrace) from [<8093b294>]
> (show_stack+0x20/0x24)
> [ 7.120052] r7:00000009 r6:60000153 r5:00000000 r4:80e75938
> [ 7.120223] [<8093b274>] (show_stack) from [<80940938>]
> (dump_stack+0xc8/0xe4)
> [ 7.120298] [<80940870>] (dump_stack) from [<80123174>] (__warn+0xe8/0x154)
> [ 7.120355] r7:00000009 r6:00000be5 r5:804bc594 r4:80b53c80
> [ 7.120415] [<8012308c>] (__warn) from [<8093b9b4>]
> (warn_slowpath_fmt+0x6c/0xe4)
> [ 7.120465] r7:00000009 r6:00000be5 r5:80b53c80 r4:00000000
> [ 7.120537] [<8093b94c>] (warn_slowpath_fmt) from [<804bc594>]
> (blk_mq_release+0x84/0x114)
> [ 7.120594] r8:80b53c80 r7:857b7390 r6:00000001 r5:80ea6efd r4:00000000
> [ 7.120656] [<804bc510>] (blk_mq_release) from [<804ad65c>]
> (blk_release_queue+0xb8/0x128)
> [ 7.120756] r9:00000001 r8:80eee400 r7:00000000 r6:857b7390
> r5:00000001 r4:857b73d8
> [ 7.120836] [<804ad5a4>] (blk_release_queue) from [<8052f87c>]
> (kobject_put+0xc8/0x210)
> [ 7.120891] r7:00000000 r6:00000000 r5:80e751bc r4:857b73d8
> [ 7.120948] [<8052f7b4>] (kobject_put) from [<804a9b00>]
> (blk_put_queue+0x1c/0x20)
> [ 7.120998] r7:00000000 r6:857b3800 r5:00000000 r4:857b3860
> [ 7.121055] [<804a9ae4>] (blk_put_queue) from [<804c2784>]
> (disk_release+0xb0/0x118)
> [ 7.121118] [<804c26d4>] (disk_release) from [<805f717c>]
> (device_release+0x40/0xb4)
> [ 7.121168] r7:00000000 r6:00000000 r5:00000000 r4:857b3860
> [ 7.121224] [<805f713c>] (device_release) from [<8052f87c>]
> (kobject_put+0xc8/0x210)
> [ 7.121265] r5:80e81154 r4:857b3860
> [ 7.121318] [<8052f7b4>] (kobject_put) from [<804c1c74>] (put_disk+0x24/0x28)
> [ 7.121368] r7:ffffffea r6:00000008 r5:857b3800 r4:857bca00
> [ 7.121440] [<804c1c50>] (put_disk) from [<806286f4>]
> (nbd_dev_add+0x214/0x27c)
> [ 7.121670] [<806284e0>] (nbd_dev_add) from [<80d22f80>]
> (nbd_init+0xec/0x120)
> [ 7.121740] r10:80ec7000 r9:80c06b34 r8:80d39834 r7:00000000
> r6:80e82aa8 r5:00000009
> [ 7.121777] r4:00000000
> [ 7.121842] [<80d22e94>] (nbd_init) from [<80102364>]
> (do_one_initcall+0x50/0x274)
> [ 7.121893] r7:00000000 r6:00000007 r5:8116d180 r4:80d22e94
> [ 7.121956] [<80102314>] (do_one_initcall) from [<80d012e8>]
> (kernel_init_freeable+0x1b8/0x240)
> [ 7.122005] r7:80d39854 r6:00000007 r5:8116d180 r4:80d5e788
> [ 7.122067] [<80d01130>] (kernel_init_freeable) from [<80947bac>]
> (kernel_init+0x18/0x130)
> [ 7.122126] r10:00000000 r9:00000000 r8:00000000 r7:00000000
> r6:00000000 r5:80947b94
> [ 7.122161] r4:00000000
> [ 7.122218] [<80947b94>] (kernel_init) from [<80100168>]
> (ret_from_fork+0x14/0x2c)
> [ 7.122413] Exception stack(0x810b7fb0 to 0x810b7ff8)
> [ 7.122936] 7fa0: 00000000
> 00000000 00000000 00000000
> [ 7.123287] 7fc0: 00000000 00000000 00000000 00000000 00000000
> 00000000 00000000 00000000
> [ 7.123545] 7fe0: 00000000 00000000 00000000 00000000 00000013 00000000
> [ 7.123728] r5:80947b94 r4:00000000
> [ 7.124011] ---[ end trace d69e5842dc8c9352 ]---
>
> There's been a bit going on in this driver since v5.10, so I assume
> it's missing some dependent changes.

Ugh, ok, I'll just go revert this for now in here, and in 5.4.y to be
safe.

thanks,

greg k-h

2021-09-16 10:57:08

by Pavel Skripkin

[permalink] [raw]
Subject: Re: [syzbot] WARNING in internal_create_group

On 9/16/21 09:55, Joel Stanley wrote:
> On Wed, 11 Aug 2021 at 21:39, Pavel Skripkin <[email protected]> wrote:
>>
>> On 7/21/21 7:30 AM, Christoph Hellwig wrote:
>> > On Wed, Jul 21, 2021 at 11:37:03AM +0800, Hillf Danton wrote:
>> >> On Tue, 20 Jul 2021 11:53:27 -0700
>> >> >syzbot has found a reproducer for the following issue on:
>> >> >
>> >> >HEAD commit: 8cae8cd89f05 seq_file: disallow extremely large seq buffer..
>> >> >git tree: upstream
>> >> >console output: https://syzkaller.appspot.com/x/log.txt?x=116f92ec300000
>> >> >kernel config: https://syzkaller.appspot.com/x/.config?x=7273c75708b55890
>> >> >dashboard link: https://syzkaller.appspot.com/bug?extid=9937dc42271cd87d4b98
>> >> >syz repro: https://syzkaller.appspot.com/x/repro.syz?x=15fc287c300000
>> >> >C reproducer: https://syzkaller.appspot.com/x/repro.c?x=178cbf6a300000
>> >
>> > <snip>
>> >
>> >> >WARNING: CPU: 0 PID: 8435 at fs/sysfs/group.c:116 internal_create_group+0x911/0xb20 fs/sysfs/group.c:116
>> >
>> > <snip>
>> >
>> >> The device_add(ddev) in register_disk() may fail but it proceeds to register
>> >> block queue even at the failure ... this falls in the class of known issue
>> >> given the comment line.
>> >>
>> >> * FIXME: error handling
>> >> */
>> >> static void __device_add_disk(struct device *parent, struct gendisk *disk,
>> >
>> > Yes, Luis is working on actually fixing this - but it requires changes
>> > to every single block driver. How does a cap on the seq_buf size
>> > propagate here, though?
>> >
>>
>> Hi!
>>
>> I've looked into this, and, I think, we can add sanity check for
>> first_minor. If user will pass too big index (syzbot's repro passes
>> 1048576) this value will be shifted to part_shift and then truncated to
>> byte in __device_add_disk() and assigned to dev->devt. User may be
>> confused about why he passed 1048576, but sysfs warns about duplicate
>> creation of /dev/block/43:0
>>
>> So, these type of errors can be handled before passing wrong values to
>> sysfs API like this:
>>
>> diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
>> index c38317979f74..600e9bab5d43 100644
>> --- a/drivers/block/nbd.c
>> +++ b/drivers/block/nbd.c
>> @@ -1725,7 +1725,17 @@ static int nbd_dev_add(int index)
>> refcount_set(&nbd->refs, 1);
>> INIT_LIST_HEAD(&nbd->list);
>> disk->major = NBD_MAJOR;
>> +
>> + /* Too big first_minor can cause duplicate creation of
>> + * sysfs files/links, since first_minor will be truncated to
>> + * byte in __device_add_disk().
>> + */
>> disk->first_minor = index << part_shift;
>> + if (disk->first_minor > 0xff) {
>> + err = -EINVAL;
>> + goto out_free_idr;
>> + }
>> +
>> disk->minors = 1 << part_shift;
>> disk->fops = &nbd_fops;
>> disk->private_data = nbd;
>>
>
> This one got backported to v5.10.65, and causes a warning on boot:
>
> [ 7.114976] ------------[ cut here ]------------
> [ 7.116811] WARNING: CPU: 0 PID: 1 at block/blk-mq.c:3045
> blk_mq_release+0x84/0x114
> [ 7.117510] Modules linked in:
> [ 7.118593] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.10.65 #196
> [ 7.118691] Hardware name: Generic DT based system
> [ 7.119088] Backtrace:
> [ 7.119675] [<8093aff0>] (dump_backtrace) from [<8093b294>]
> (show_stack+0x20/0x24)
> [ 7.120052] r7:00000009 r6:60000153 r5:00000000 r4:80e75938
> [ 7.120223] [<8093b274>] (show_stack) from [<80940938>]
> (dump_stack+0xc8/0xe4)
> [ 7.120298] [<80940870>] (dump_stack) from [<80123174>] (__warn+0xe8/0x154)
> [ 7.120355] r7:00000009 r6:00000be5 r5:804bc594 r4:80b53c80
> [ 7.120415] [<8012308c>] (__warn) from [<8093b9b4>]
> (warn_slowpath_fmt+0x6c/0xe4)
> [ 7.120465] r7:00000009 r6:00000be5 r5:80b53c80 r4:00000000
> [ 7.120537] [<8093b94c>] (warn_slowpath_fmt) from [<804bc594>]
> (blk_mq_release+0x84/0x114)
> [ 7.120594] r8:80b53c80 r7:857b7390 r6:00000001 r5:80ea6efd r4:00000000
> [ 7.120656] [<804bc510>] (blk_mq_release) from [<804ad65c>]
> (blk_release_queue+0xb8/0x128)
> [ 7.120756] r9:00000001 r8:80eee400 r7:00000000 r6:857b7390
> r5:00000001 r4:857b73d8
> [ 7.120836] [<804ad5a4>] (blk_release_queue) from [<8052f87c>]
> (kobject_put+0xc8/0x210)
> [ 7.120891] r7:00000000 r6:00000000 r5:80e751bc r4:857b73d8
> [ 7.120948] [<8052f7b4>] (kobject_put) from [<804a9b00>]
> (blk_put_queue+0x1c/0x20)
> [ 7.120998] r7:00000000 r6:857b3800 r5:00000000 r4:857b3860
> [ 7.121055] [<804a9ae4>] (blk_put_queue) from [<804c2784>]
> (disk_release+0xb0/0x118)
> [ 7.121118] [<804c26d4>] (disk_release) from [<805f717c>]
> (device_release+0x40/0xb4)
> [ 7.121168] r7:00000000 r6:00000000 r5:00000000 r4:857b3860
> [ 7.121224] [<805f713c>] (device_release) from [<8052f87c>]
> (kobject_put+0xc8/0x210)
> [ 7.121265] r5:80e81154 r4:857b3860
> [ 7.121318] [<8052f7b4>] (kobject_put) from [<804c1c74>] (put_disk+0x24/0x28)
> [ 7.121368] r7:ffffffea r6:00000008 r5:857b3800 r4:857bca00
> [ 7.121440] [<804c1c50>] (put_disk) from [<806286f4>]
> (nbd_dev_add+0x214/0x27c)
> [ 7.121670] [<806284e0>] (nbd_dev_add) from [<80d22f80>]
> (nbd_init+0xec/0x120)
> [ 7.121740] r10:80ec7000 r9:80c06b34 r8:80d39834 r7:00000000
> r6:80e82aa8 r5:00000009
> [ 7.121777] r4:00000000
> [ 7.121842] [<80d22e94>] (nbd_init) from [<80102364>]
> (do_one_initcall+0x50/0x274)
> [ 7.121893] r7:00000000 r6:00000007 r5:8116d180 r4:80d22e94
> [ 7.121956] [<80102314>] (do_one_initcall) from [<80d012e8>]
> (kernel_init_freeable+0x1b8/0x240)
> [ 7.122005] r7:80d39854 r6:00000007 r5:8116d180 r4:80d5e788
> [ 7.122067] [<80d01130>] (kernel_init_freeable) from [<80947bac>]
> (kernel_init+0x18/0x130)
> [ 7.122126] r10:00000000 r9:00000000 r8:00000000 r7:00000000
> r6:00000000 r5:80947b94
> [ 7.122161] r4:00000000
> [ 7.122218] [<80947b94>] (kernel_init) from [<80100168>]
> (ret_from_fork+0x14/0x2c)
> [ 7.122413] Exception stack(0x810b7fb0 to 0x810b7ff8)
> [ 7.122936] 7fa0: 00000000
> 00000000 00000000 00000000
> [ 7.123287] 7fc0: 00000000 00000000 00000000 00000000 00000000
> 00000000 00000000 00000000
> [ 7.123545] 7fe0: 00000000 00000000 00000000 00000000 00000013 00000000
> [ 7.123728] r5:80947b94 r4:00000000
> [ 7.124011] ---[ end trace d69e5842dc8c9352 ]---
>
> There's been a bit going on in this driver since v5.10, so I assume
> it's missing some dependent changes.
>

Hi, Joel,

Thank you for report!

Did reverting my commit remove this warning? I don't get how sanity
check could cause this warning, but I might be missing something.



With regards,
Pavel Skripkin