Skip to contentSkip to conversation

WARNING in mntput_no_expire (3)

syzbot syzbot 2 participants 10 messages May 17, 2022 – May 18, 2022 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

syzbot

author syzbot
#1 lore raw
In reply to a message not in the archive

Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING in mntput_no_expire

------------[ cut here ]------------
WARNING: CPU: 1 PID: 4486 at fs/namespace.c:1285 mntput_no_expire+0x985/0xfe0 fs/namespace.c:1285
Modules linked in:

CPU: 1 PID: 4486 Comm: syz-executor.3 Not tainted 5.18.0-rc6-syzkaller-00009-gfeb9c5e19e91-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
RIP: 0010:mntput_no_expire+0x985/0xfe0 fs/namespace.c:1285
Code: 00 00 00 bf 08 00 00 00 48 c7 c2 60 fe f0 8b e8 91 0b 72 ff e9 01 f9 ff ff e8 d7 bd 9d ff 0f 0b e9 b6 f8 ff ff e8 cb bd 9d ff <0f> 0b e9 aa f8 ff ff e8 bf bd 9d ff e8 aa dd 91 07 31 ff 89 c3 89
RSP: 0018:ffffc90004857d78 EFLAGS: 00010293
RAX: 0000000000000000 RBX: 00000000ffffffff RCX: 0000000000000000
RDX: ffff888018b80000 RSI: ffffffff81db8365 RDI: 0000000000000003
RBP: 0000000000000008 R08: 0000000000000000 R09: 0000000000000001
R10: ffffffff81db7c0e R11: 0000000000000000 R12: 0000000000000002
R13: ffff88801d671e00 R14: dffffc0000000000 R15: ffffed1003ace3ca
FS:  0000555555fbb400(0000) GS:ffff8880b9c00000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000555556f3e848 CR3: 000000001f615000 CR4: 00000000003506f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 <TASK>
 mntput+0x67/0x90 fs/namespace.c:1347
 __fput+0x3ba/0x9d0 fs/file_table.c:333
 task_work_run+0xdd/0x1a0 kernel/task_work.c:164
 resume_user_mode_work include/linux/resume_user_mode.h:49 [inline]
 exit_to_user_mode_loop kernel/entry/common.c:169 [inline]
 exit_to_user_mode_prepare+0x23c/0x250 kernel/entry/common.c:201
 __syscall_exit_to_user_mode_work kernel/entry/common.c:283 [inline]
 syscall_exit_to_user_mode+0x19/0x60 kernel/entry/common.c:294
 do_syscall_64+0x42/0xb0 arch/x86/entry/common.c:86
 entry_SYSCALL_64_after_hwframe+0x44/0xae
RIP: 0033:0x7f3b7a03bd2b
Code: 0f 05 48 3d 00 f0 ff ff 77 45 c3 0f 1f 40 00 48 83 ec 18 89 7c 24 0c e8 63 fc ff ff 8b 7c 24 0c 41 89 c0 b8 03 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 35 44 89 c7 89 44 24 0c e8 a1 fc ff ff 8b 44
RSP: 002b:00007ffe9eb268b0 EFLAGS: 00000293 ORIG_RAX: 0000000000000003
RAX: 0000000000000000 RBX: 0000000000000004 RCX: 00007f3b7a03bd2b
RDX: 0000001b2ff20000 RSI: 0000000000000000 RDI: 0000000000000003
RBP: 00007f3b7a19d960 R08: 0000000000000000 R09: 00007ffe9ebbf080
R10: 00007ffe9ebbf090 R11: 0000000000000293 R12: 00000000000181f5
R13: 00007ffe9eb269b0 R14: 00007ffe9eb269d0 R15: 0000000000000032
 </TASK>

Tested on:

commit:         feb9c5e1 Merge tag 'for_linus' of git://git.kernel.org..
git tree:       https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
console output: https://syzkaller.appspot.com/x/log.txt?x=15ee4759f00000
kernel config:  https://syzkaller.appspot.com/x/.config?x=79caa0035f59d385
dashboard link: https://syzkaller.appspot.com/bug?extid=5b1e53987f858500ec00
compiler:       gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
patch:          https://syzkaller.appspot.com/x/patch.diff?x=1108ae3af00000
#2 lore raw
Quoted 4 lines · syzbot

Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING in mntput_no_expire

Obvious question: which filesystem it is?

Quoted 22 lines
 entry_SYSCALL_64_after_hwframe+0x44/0xae
RIP: 0033:0x7f3b7a03bd2b
Code: 0f 05 48 3d 00 f0 ff ff 77 45 c3 0f 1f 40 00 48 83 ec 18 89 7c 24 0c e8 63 fc ff ff 8b 7c 24 0c 41 89 c0 b8 03 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 35 44 89 c7 89 44 24 0c e8 a1 fc ff ff 8b 44
RSP: 002b:00007ffe9eb268b0 EFLAGS: 00000293 ORIG_RAX: 0000000000000003
RAX: 0000000000000000 RBX: 0000000000000004 RCX: 00007f3b7a03bd2b
RDX: 0000001b2ff20000 RSI: 0000000000000000 RDI: 0000000000000003
RBP: 00007f3b7a19d960 R08: 0000000000000000 R09: 00007ffe9ebbf080
R10: 00007ffe9ebbf090 R11: 0000000000000293 R12: 00000000000181f5
R13: 00007ffe9eb269b0 R14: 00007ffe9eb269d0 R15: 0000000000000032
 </TASK>

Tested on:

commit:         feb9c5e1 Merge tag 'for_linus' of git://git.kernel.org..
git tree:       https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
console output: https://syzkaller.appspot.com/x/log.txt?x=15ee4759f00000
kernel config:  https://syzkaller.appspot.com/x/.config?x=79caa0035f59d385
dashboard link: https://syzkaller.appspot.com/bug?extid=5b1e53987f858500ec00
compiler:       gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
patch:          https://syzkaller.appspot.com/x/patch.diff?x=1108ae3af00000
#3 lore raw
Quoted 7 lines · Al Viro
Quoted 4 lines · syzbot

Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING in mntput_no_expire

Obvious question: which filesystem it is?

FWIW, can't reproduce here - at least not with C reproducer + -rc7^ kernel + .config from report + debian kvm image (bullseye, with systemd shite replaced with sysvinit, which might be relevant).

In case systemd-specific braindamage is needed to reproduce it... Hell knows; at least mount --make-rshared / doesn't seem to suffice.

#4 lore raw
Quoted 7 lines · Al Viro
Quoted 6 lines · Al Viro
Quoted 4 lines · syzbot

Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING in mntput_no_expire

Quoted 8 lines
Quoted 1 line

Obvious question: which filesystem it is?

FWIW, can't reproduce here - at least not with C reproducer + -rc7^ kernel + .config from report + debian kvm image (bullseye, with systemd shite replaced with sysvinit, which might be relevant).

In case systemd-specific braindamage is needed to reproduce it... Hell knows; at least mount --make-rshared / doesn't seem to suffice.

... doesn't reproduce with genuine systemd either. FWIW, 4-way SMP setup here.

#5 lore raw
Quoted 14 lines · Al Viro
Quoted 13 lines · Al Viro
Quoted 7 lines · Al Viro
Quoted 4 lines · syzbot

Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING in mntput_no_expire

Obvious question: which filesystem it is?

FWIW, can't reproduce here - at least not with C reproducer + -rc7^ kernel + .config from report + debian kvm image (bullseye, with systemd shite replaced with sysvinit, which might be relevant).

Quoted 5 lines
Quoted 2 lines

In case systemd-specific braindamage is needed to reproduce it... Hell knows; at least mount --make-rshared / doesn't seem to suffice.

... doesn't reproduce with genuine systemd either. FWIW, 4-way SMP setup here.

OK, reproduced...

#6 lore raw
Quoted 15 lines · Al Viro
Quoted 14 lines · Al Viro
Quoted 13 lines · Al Viro
Quoted 7 lines · Al Viro
Quoted 4 lines · syzbot

Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING in mntput_no_expire

Obvious question: which filesystem it is?

FWIW, can't reproduce here - at least not with C reproducer + -rc7^ kernel + .config from report + debian kvm image (bullseye, with systemd shite replaced with sysvinit, which might be relevant).

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

In case systemd-specific braindamage is needed to reproduce it... Hell knows; at least mount --make-rshared / doesn't seem to suffice.

... doesn't reproduce with genuine systemd either. FWIW, 4-way SMP setup here.

OK, reproduced...

FWIW, it smells like something (cgroup?) fucking up percpu allocation/freeing. Note that struct mount has both refcount and writers count held in percpu; replacing the refcount with atomic_t gets rid of seeing negative refcount in mntput_no_expire(), but leaves negative writers count caught in cleanup_mnt(); turn that from WARN_ON into printk and we get past that, only to see

	percpu ref (css_release) <= 0 (-4294967294)

immediately afterwards.

IOW, it looks like we are getting not messed refcounting on either side, but same refcount physically shared by unrelated objects.

#7 lore raw
Quoted 30 lines · Al Viro
Quoted 15 lines · Al Viro
Quoted 14 lines · Al Viro
Quoted 13 lines · Al Viro
Quoted 7 lines · Al Viro
Quoted 4 lines · syzbot

Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING in mntput_no_expire

Obvious question: which filesystem it is?

FWIW, can't reproduce here - at least not with C reproducer + -rc7^ kernel + .config from report + debian kvm image (bullseye, with systemd shite replaced with sysvinit, which might be relevant).

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

In case systemd-specific braindamage is needed to reproduce it... Hell knows; at least mount --make-rshared / doesn't seem to suffice.

... doesn't reproduce with genuine systemd either. FWIW, 4-way SMP setup here.

OK, reproduced...

FWIW, it smells like something (cgroup?) fucking up percpu allocation/freeing. Note that struct mount has both refcount and writers count held in percpu; replacing the refcount with atomic_t gets rid of seeing negative refcount in mntput_no_expire(), but leaves negative writers count caught in cleanup_mnt(); turn that from WARN_ON into printk and we get past that, only to see

Quoted 5 lines
	percpu ref (css_release) <= 0 (-4294967294)

immediately afterwards.

IOW, it looks like we are getting not messed refcounting on either side, but same refcount physically shared by unrelated objects.

Gotcha.
percpu_ref_init():

        ref->percpu_count_ptr = (unsigned long)
                __alloc_percpu_gfp(sizeof(unsigned long), align, gfp);
        if (!ref->percpu_count_ptr)
                return -ENOMEM;
        data = kzalloc(sizeof(*ref->data), gfp);
        if (!data) {
                free_percpu((void __percpu *)ref->percpu_count_ptr);
                return -ENOMEM;
        }

cgroup_create():

        err = percpu_ref_init(&css->refcnt, css_release, 0, GFP_KERNEL);
        if (err)
                goto err_free_css;

        err = cgroup_idr_alloc(&ss->css_idr, NULL, 2, 0, GFP_KERNEL);
        if (err < 0)
                goto err_free_css;

Now note that we end up hitting the same path in case of successful and failed percpu_ref_init(). With no way to tell if css->refcnt.percpu_count_ptr is an already freed object or needs to be freed. And sure enough, we have

err_free_css:

        list_del_rcu(&css->rstat_css_node);
        INIT_RCU_WORK(&css->destroy_rwork, css_free_rwork_fn);
        queue_rcu_work(cgroup_destroy_wq, &css->destroy_rwork);

with css_free_rwork_fn() starting with

        percpu_ref_exit(&css->refcnt);

which will give that double free. That might be not the only cause of trouble, but this looks like a bug and a plausible source of the symptoms observed here. Let's see if this helps:

lib/percpu-refcount.c +1 -0
index af9302141bcf..e5c5315da274 100644
@@ -76,6 +76,7 @@ int percpu_ref_init(struct percpu_ref *ref, percpu_ref_func_t *release,
 	data = kzalloc(sizeof(*ref->data), gfp);
 	if (!data) {
 		free_percpu((void __percpu *)ref->percpu_count_ptr);
+		ref->percpu_count_ptr = 0;
 		return -ENOMEM;
 	}
 
#8 lore raw
Quoted 42 lines · Al Viro

Gotcha.
percpu_ref_init():

        ref->percpu_count_ptr = (unsigned long)
                __alloc_percpu_gfp(sizeof(unsigned long), align, gfp);
        if (!ref->percpu_count_ptr)
                return -ENOMEM;
        data = kzalloc(sizeof(*ref->data), gfp);
        if (!data) {
                free_percpu((void __percpu *)ref->percpu_count_ptr);
                return -ENOMEM;
        }

cgroup_create():

        err = percpu_ref_init(&css->refcnt, css_release, 0, GFP_KERNEL);
        if (err)
                goto err_free_css;

        err = cgroup_idr_alloc(&ss->css_idr, NULL, 2, 0, GFP_KERNEL);
        if (err < 0)
                goto err_free_css;

Now note that we end up hitting the same path in case of successful and failed percpu_ref_init(). With no way to tell if css->refcnt.percpu_count_ptr is an already freed object or needs to be freed. And sure enough, we have

err_free_css:

        list_del_rcu(&css->rstat_css_node);
        INIT_RCU_WORK(&css->destroy_rwork, css_free_rwork_fn);
        queue_rcu_work(cgroup_destroy_wq, &css->destroy_rwork);

with css_free_rwork_fn() starting with

        percpu_ref_exit(&css->refcnt);

which will give that double free. That might be not the only cause of trouble, but this looks like a bug and a plausible source of the symptoms observed here. Let's see if this helps:

lib/percpu-refcount.c +0 -0
index af9302141bcf..e5c5315da274 100644

lib/percpu-refcount.c int percpu_ref_init(struct percpu_ref *ref, percpu_ref_func_t *release, · line 82

Quoted 7 lines
lib/percpu-refcount.c +1 -0
@@ -76,6 +76,7 @@ int percpu_ref_init(struct percpu_ref *ref, percpu_ref_func_t *release,
 	data = kzalloc(sizeof(*ref->data), gfp);
 	if (!data) {
 		free_percpu((void __percpu *)ref->percpu_count_ptr);
+		ref->percpu_count_ptr = 0;
 		return -ENOMEM;
 	}
 

... and it appears to fix the damn thing. 10 minutes and still running; without that it usually fails within a few seconds.

#9 lore raw

#syz test git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git proposed-fix

author syzbot
#10 lore raw
syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Hello,

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

Reported-and-tested-by [email protected]

Tested on:

commit:         a9171431 percpu_ref_init(): clean ->percpu_count_ref o..
git tree:       git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git proposed-fix
kernel config:  https://syzkaller.appspot.com/x/.config?x=79caa0035f59d385
dashboard link: https://syzkaller.appspot.com/bug?extid=5b1e53987f858500ec00
compiler:       gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2

Note: no patches were applied.
Note: testing is done by a robot and is best-effort only.