[syzbot] possible deadlock in ext4_xattr_get

20 views
Skip to first unread message

syzbot

unread,
Aug 7, 2022, 9:08:26 AM8/7/22
to adilger...@dilger.ca, linux...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com, ty...@mit.edu
Hello,

syzbot found the following issue on:

HEAD commit: cb71b93c2dc3 Add linux-next specific files for 20220628
git tree: linux-next
console+strace: https://syzkaller.appspot.com/x/log.txt?x=10bdcf3c080000
kernel config: https://syzkaller.appspot.com/x/.config?x=badbc1adb2d582eb
dashboard link: https://syzkaller.appspot.com/bug?extid=62120febbd1ee3c3c860
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=10256c61080000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=11f3c832080000

Bisection is inconclusive: the issue happens on the oldest tested release.

bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=12420fe2080000
final oops: https://syzkaller.appspot.com/x/report.txt?x=11420fe2080000
console output: https://syzkaller.appspot.com/x/log.txt?x=16420fe2080000

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

loop0: detected capacity change from 0 to 512
EXT4-fs (loop0): mounted filesystem without journal. Quota mode: none.
======================================================
WARNING: possible circular locking dependency detected
5.19.0-rc4-next-20220628-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor246/3601 is trying to acquire lock:
ffff888075af28e8 (&ei->xattr_sem){++++}-{3:3}, at: ext4_xattr_get+0x14e/0xa10 fs/ext4/xattr.c:650

but task is already holding lock:
ffff888075af2c20 (&ea_inode->i_rwsem#9/1){+.+.}-{3:3}, at: inode_lock include/linux/fs.h:761 [inline]
ffff888075af2c20 (&ea_inode->i_rwsem#9/1){+.+.}-{3:3}, at: chown_common+0x364/0x710 fs/open.c:727

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #1 (&ea_inode->i_rwsem#9/1){+.+.}-{3:3}:
down_write+0x90/0x150 kernel/locking/rwsem.c:1542
inode_lock include/linux/fs.h:761 [inline]
ext4_xattr_inode_create fs/ext4/xattr.c:1445 [inline]
ext4_xattr_inode_lookup_create fs/ext4/xattr.c:1528 [inline]
ext4_xattr_set_entry+0x2ab3/0x3850 fs/ext4/xattr.c:1656
ext4_xattr_ibody_set+0x78/0x2b0 fs/ext4/xattr.c:2209
ext4_xattr_set_handle+0x964/0x1500 fs/ext4/xattr.c:2366
ext4_xattr_set+0x13a/0x340 fs/ext4/xattr.c:2479
__vfs_setxattr+0x115/0x180 fs/xattr.c:182
__vfs_setxattr_noperm+0x125/0x5f0 fs/xattr.c:216
__vfs_setxattr_locked+0x1cf/0x260 fs/xattr.c:277
vfs_setxattr+0x13f/0x330 fs/xattr.c:303
setxattr+0x146/0x160 fs/xattr.c:611
path_setxattr+0x197/0x1c0 fs/xattr.c:630
__do_sys_setxattr fs/xattr.c:646 [inline]
__se_sys_setxattr fs/xattr.c:642 [inline]
__x64_sys_setxattr+0xc0/0x160 fs/xattr.c:642
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+0x46/0xb0

-> #0 (&ei->xattr_sem){++++}-{3:3}:
check_prev_add kernel/locking/lockdep.c:3095 [inline]
check_prevs_add kernel/locking/lockdep.c:3214 [inline]
validate_chain kernel/locking/lockdep.c:3829 [inline]
__lock_acquire+0x2abe/0x5660 kernel/locking/lockdep.c:5053
lock_acquire kernel/locking/lockdep.c:5665 [inline]
lock_acquire+0x1ab/0x570 kernel/locking/lockdep.c:5630
down_read+0x98/0x440 kernel/locking/rwsem.c:1489
ext4_xattr_get+0x14e/0xa10 fs/ext4/xattr.c:650
__vfs_getxattr+0xd9/0x140 fs/xattr.c:401
cap_inode_need_killpriv+0x3c/0x60 security/commoncap.c:301
security_inode_need_killpriv+0x40/0x90 security/security.c:1420
notify_change+0x6e7/0x1440 fs/attr.c:351
chown_common+0x61b/0x710 fs/open.c:734
do_fchownat+0x126/0x1e0 fs/open.c:765
__do_sys_fchownat fs/open.c:780 [inline]
__se_sys_fchownat fs/open.c:777 [inline]
__x64_sys_fchownat+0xba/0x150 fs/open.c:777
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+0x46/0xb0

other info that might help us debug this:

Possible unsafe locking scenario:

CPU0 CPU1
---- ----
lock(&ea_inode->i_rwsem#9/1);
lock(&ei->xattr_sem);
lock(&ea_inode->i_rwsem#9/1);
lock(&ei->xattr_sem);

*** DEADLOCK ***

2 locks held by syz-executor246/3601:
#0: ffff88801d65e460 (sb_writers#4){.+.+}-{0:0}, at: do_fchownat+0x101/0x1e0 fs/open.c:762
#1: ffff888075af2c20 (&ea_inode->i_rwsem#9/1){+.+.}-{3:3}, at: inode_lock include/linux/fs.h:761 [inline]
#1: ffff888075af2c20 (&ea_inode->i_rwsem#9/1){+.+.}-{3:3}, at: chown_common+0x364/0x710 fs/open.c:727

stack backtrace:
CPU: 0 PID: 3601 Comm: syz-executor246 Not tainted 5.19.0-rc4-next-20220628-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/22/2022
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
check_noncircular+0x25f/0x2e0 kernel/locking/lockdep.c:2175
check_prev_add kernel/locking/lockdep.c:3095 [inline]
check_prevs_add kernel/locking/lockdep.c:3214 [inline]
validate_chain kernel/locking/lockdep.c:3829 [inline]
__lock_acquire+0x2abe/0x5660 kernel/locking/lockdep.c:5053
lock_acquire kernel/locking/lockdep.c:5665 [inline]
lock_acquire+0x1ab/0x570 kernel/locking/lockdep.c:5630
down_read+0x98/0x440 kernel/locking/rwsem.c:1489
ext4_xattr_get+0x14e/0xa10 fs/ext4/xattr.c:650
__vfs_getxattr+0xd9/0x140 fs/xattr.c:401
cap_inode_need_killpriv+0x3c/0x60 security/commoncap.c:301
security_inode_need_killpriv+0x40/0x90 security/security.c:1420
notify_change+0x6e7/0x1440 fs/attr.c:351
chown_common+0x61b/0x710 fs/open.c:734
do_fchownat+0x126/0x1e0 fs/open.c:765
__do_sys_fchownat fs/open.c:780 [inline]
__se_sys_fchownat fs/open.c:777 [inline]
__x64_sys_fchownat+0xba/0x150 fs/open.c:777
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+0x46/0xb0
RIP: 0033:0x7ff813f7d0e9
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 c0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffc815d6a78 EFLAGS: 00000246 ORIG_RAX: 0000000000000104
RAX: ffffffffffffffda RBX:


---
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 syzk...@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
For information about bisection process see: https://goo.gl/tpsmEJ#bisection
syzbot can test patches for this issue, for details see:
https://goo.gl/tpsmEJ#testing-patches

Hillf Danton

unread,
Aug 8, 2022, 7:14:51 AM8/8/22
to syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Sun, 07 Aug 2022 06:08:25 -0700
> syzbot found the following issue on:
>
> HEAD commit: cb71b93c2dc3 Add linux-next specific files for 20220628
> git tree: linux-next
> console+strace: https://syzkaller.appspot.com/x/log.txt?x=10bdcf3c080000
> kernel config: https://syzkaller.appspot.com/x/.config?x=badbc1adb2d582eb
> dashboard link: https://syzkaller.appspot.com/bug?extid=62120febbd1ee3c3c860
> compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=10256c61080000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=11f3c832080000
>
Set NOQUOTA flag when initing inode to avoid acquiring inode lock.

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git cb71b93c2dc3

diff -pur a/fs/ext4/ext4.h b/fs/ext4/ext4.h
--- a/fs/ext4/ext4.h 2022-08-08 18:33:25.799893400 +0800
+++ b/fs/ext4/ext4.h 2022-08-08 18:40:22.348551400 +0800
@@ -441,6 +441,7 @@ struct flex_groups {
#define EXT4_VERITY_FL 0x00100000 /* Verity protected inode */
#define EXT4_EA_INODE_FL 0x00200000 /* Inode used for large EA */
/* 0x00400000 was formerly EXT4_EOFBLOCKS_FL */
+#define EXT4_EA_NOQUOTA_FL 0x00800000 /* Create inode with S_NOQUOTA set */

#define EXT4_DAX_FL 0x02000000 /* Inode is DAX */

diff -pur a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
--- a/fs/ext4/ialloc.c 2022-08-08 18:33:45.089849400 +0800
+++ b/fs/ext4/ialloc.c 2022-08-08 18:44:05.175154200 +0800
@@ -962,6 +962,8 @@ struct inode *__ext4_new_inode(struct us
return ERR_PTR(-ENOMEM);
ei = EXT4_I(inode);

+ if (i_flags & EXT4_EA_NOQUOTA_FL)
+ inode->i_flags |= S_NOQUOTA;
/*
* Initialize owners and quota early so that we don't have to account
* for quota initialization worst case in standard inode creating
diff -pur a/fs/ext4/xattr.c b/fs/ext4/xattr.c
--- a/fs/ext4/xattr.c 2022-08-08 18:33:07.849816600 +0800
+++ b/fs/ext4/xattr.c 2022-08-08 18:57:36.782235000 +0800
@@ -1419,7 +1419,7 @@ static struct inode *ext4_xattr_inode_cr
*/
ea_inode = ext4_new_inode(handle, inode->i_sb->s_root->d_inode,
S_IFREG | 0600, NULL, inode->i_ino + 1, owner,
- EXT4_EA_INODE_FL);
+ EXT4_EA_INODE_FL | EXT4_EA_NOQUOTA_FL);
if (!IS_ERR(ea_inode)) {
ea_inode->i_op = &ext4_file_inode_operations;
ea_inode->i_fop = &ext4_file_operations;
@@ -1442,9 +1442,6 @@ static struct inode *ext4_xattr_inode_cr
*/
dquot_free_inode(ea_inode);
dquot_drop(ea_inode);
- inode_lock(ea_inode);
- ea_inode->i_flags |= S_NOQUOTA;
- inode_unlock(ea_inode);
}

return ea_inode;
--

syzbot

unread,
Aug 8, 2022, 7:26:16 AM8/8/22
to hda...@sina.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
possible deadlock in ext4_xattr_get

loop0: detected capacity change from 0 to 512
EXT4-fs (loop0): mounted filesystem without journal. Quota mode: none.
======================================================
WARNING: possible circular locking dependency detected
5.19.0-rc4-next-20220628-syzkaller-dirty #0 Not tainted
------------------------------------------------------
syz-executor.0/4081 is trying to acquire lock:
ffff888073393cf8 (&ei->xattr_sem){++++}-{3:3}, at: ext4_xattr_get+0x14e/0xa10 fs/ext4/xattr.c:650

but task is already holding lock:
ffff888073394030 (&ea_inode->i_rwsem#9/1){+.+.}-{3:3}, at: inode_lock include/linux/fs.h:761 [inline]
ffff888073394030 (&ea_inode->i_rwsem#9/1){+.+.}-{3:3}, at: chown_common+0x364/0x710 fs/open.c:727

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #1 (&ea_inode->i_rwsem#9/1){+.+.}-{3:3}:
down_write+0x90/0x150 kernel/locking/rwsem.c:1542
inode_lock include/linux/fs.h:761 [inline]
ext4_xattr_inode_write fs/ext4/xattr.c:1391 [inline]
ext4_xattr_inode_lookup_create fs/ext4/xattr.c:1529 [inline]
ext4_xattr_set_entry+0x2ec5/0x3800 fs/ext4/xattr.c:1653
ext4_xattr_ibody_set+0x78/0x2b0 fs/ext4/xattr.c:2206
ext4_xattr_set_handle+0x964/0x1500 fs/ext4/xattr.c:2363
ext4_xattr_set+0x13a/0x340 fs/ext4/xattr.c:2476
2 locks held by syz-executor.0/4081:
#0: ffff88807a612460 (sb_writers#4){.+.+}-{0:0}, at: do_fchownat+0x101/0x1e0 fs/open.c:762
#1: ffff888073394030 (&ea_inode->i_rwsem#9/1){+.+.}-{3:3}, at: inode_lock include/linux/fs.h:761 [inline]
#1: ffff888073394030 (&ea_inode->i_rwsem#9/1){+.+.}-{3:3}, at: chown_common+0x364/0x710 fs/open.c:727

stack backtrace:
CPU: 0 PID: 4081 Comm: syz-executor.0 Not tainted 5.19.0-rc4-next-20220628-syzkaller-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/22/2022
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
check_noncircular+0x25f/0x2e0 kernel/locking/lockdep.c:2175
check_prev_add kernel/locking/lockdep.c:3095 [inline]
check_prevs_add kernel/locking/lockdep.c:3214 [inline]
validate_chain kernel/locking/lockdep.c:3829 [inline]
__lock_acquire+0x2abe/0x5660 kernel/locking/lockdep.c:5053
lock_acquire kernel/locking/lockdep.c:5665 [inline]
lock_acquire+0x1ab/0x570 kernel/locking/lockdep.c:5630
down_read+0x98/0x440 kernel/locking/rwsem.c:1489
ext4_xattr_get+0x14e/0xa10 fs/ext4/xattr.c:650
__vfs_getxattr+0xd9/0x140 fs/xattr.c:401
cap_inode_need_killpriv+0x3c/0x60 security/commoncap.c:301
security_inode_need_killpriv+0x40/0x90 security/security.c:1420
notify_change+0x6e7/0x1440 fs/attr.c:351
chown_common+0x61b/0x710 fs/open.c:734
do_fchownat+0x126/0x1e0 fs/open.c:765
__do_sys_fchownat fs/open.c:780 [inline]
__se_sys_fchownat fs/open.c:777 [inline]
__x64_sys_fchownat+0xba/0x150 fs/open.c:777
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+0x46/0xb0
RIP: 0033:0x7febbbc89209
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 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007febbcdc0168 EFLAGS: 00000246 ORIG_RAX: 0000000000000104
RAX: ffffffffffffffda RBX: 00007febbbd9bf60 RCX: 00007febbbc89209
RDX: 0000000000000000 RSI: 00000000200000c0 RDI: 0000000000000005
RBP: 00007febbbce3161 R08: 0000000000001000 R09: 0000000000000000
R10: 000000000000ee01 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffd5bc171ff R14: 00007febbcdc0300 R15: 0000000000022000
</TASK>


Tested on:

commit: cb71b93c Add linux-next specific files for 20220628
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
console output: https://syzkaller.appspot.com/x/log.txt?x=13ec5671080000
kernel config: https://syzkaller.appspot.com/x/.config?x=badbc1adb2d582eb
dashboard link: https://syzkaller.appspot.com/bug?extid=62120febbd1ee3c3c860
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=162cf612080000

Hillf Danton

unread,
Aug 8, 2022, 8:11:01 AM8/8/22
to syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Sun, 07 Aug 2022 06:08:25 -0700
> syzbot found the following issue on:
>
> HEAD commit: cb71b93c2dc3 Add linux-next specific files for 20220628
> git tree: linux-next
> console+strace: https://syzkaller.appspot.com/x/log.txt?x=10bdcf3c080000
> kernel config: https://syzkaller.appspot.com/x/.config?x=badbc1adb2d582eb
> dashboard link: https://syzkaller.appspot.com/bug?extid=62120febbd1ee3c3c860
> compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=10256c61080000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=11f3c832080000
>
Set NOQUOTA flag when initing inode to avoid acquiring inode lock.

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git cb71b93c2dc3

diff -pur a/fs/ext4/ext4.h b/fs/ext4/ext4.h
--- a/fs/ext4/ext4.h 2022-08-08 18:33:25.799893400 +0800
+++ b/fs/ext4/ext4.h 2022-08-08 18:40:22.348551400 +0800
@@ -441,6 +441,7 @@ struct flex_groups {
#define EXT4_VERITY_FL 0x00100000 /* Verity protected inode */
#define EXT4_EA_INODE_FL 0x00200000 /* Inode used for large EA */
/* 0x00400000 was formerly EXT4_EOFBLOCKS_FL */
+#define EXT4_EA_NOQUOTA_FL 0x00800000 /* Create inode with S__NOQUOTA set */

#define EXT4_DAX_FL 0x02000000 /* Inode is DAX */

diff -pur a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
--- a/fs/ext4/ialloc.c 2022-08-08 18:33:45.089849400 +0800
+++ b/fs/ext4/ialloc.c 2022-08-08 18:44:05.175154200 +0800
@@ -962,6 +962,8 @@ struct inode *__ext4_new_inode(struct us
return ERR_PTR(-ENOMEM);
ei = EXT4_I(inode);

+ if (i_flags & EXT4_EA_NOQUOTA_FL)
+ inode->i_flags |= S_NOQUOTA;
/*
* Initialize owners and quota early so that we don't have to account
* for quota initialization worst case in standard inode creating
diff -pur a/fs/ext4/xattr.c b/fs/ext4/xattr.c
--- a/fs/ext4/xattr.c 2022-08-08 18:33:07.849816600 +0800
+++ b/fs/ext4/xattr.c 2022-08-08 20:05:53.296977000 +0800
@@ -647,7 +647,8 @@ ext4_xattr_get(struct inode *inode, int
if (strlen(name) > 255)
return -ERANGE;

- down_read(&EXT4_I(inode)->xattr_sem);
+ if (!down_read_trylock(&EXT4_I(inode)->xattr_sem))
+ return -EDEADLK;
error = ext4_xattr_ibody_get(inode, name_index, name, buffer,
buffer_size);
if (error == -ENODATA)
@@ -1419,7 +1420,7 @@ static struct inode *ext4_xattr_inode_cr
*/
ea_inode = ext4_new_inode(handle, inode->i_sb->s_root->d_inode,
S_IFREG | 0600, NULL, inode->i_ino + 1, owner,
- EXT4_EA_INODE_FL);
+ EXT4_EA_INODE_FL | EXT4_EA_NOQUOTA_FL);
if (!IS_ERR(ea_inode)) {
ea_inode->i_op = &ext4_file_inode_operations;
ea_inode->i_fop = &ext4_file_operations;
@@ -1442,9 +1443,6 @@ static struct inode *ext4_xattr_inode_cr

syzbot

unread,
Aug 8, 2022, 8:21:17 AM8/8/22
to hda...@sina.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
possible deadlock in ext4_setattr

loop0: detected capacity change from 0 to 512
EXT4-fs (loop0): mounted filesystem without journal. Quota mode: none.
======================================================
WARNING: possible circular locking dependency detected
5.19.0-rc4-next-20220628-syzkaller-dirty #0 Not tainted
------------------------------------------------------
syz-executor.0/4082 is trying to acquire lock:
ffff8880727814d8 (&ei->xattr_sem){++++}-{3:3}, at: ext4_setattr+0x6ef/0x2c60 fs/ext4/inode.c:5378

but task is already holding lock:
ffff888072781810 (&ea_inode->i_rwsem#9/1){+.+.}-{3:3}, at: inode_lock include/linux/fs.h:761 [inline]
ffff888072781810 (&ea_inode->i_rwsem#9/1){+.+.}-{3:3}, at: chown_common+0x364/0x710 fs/open.c:727

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #1 (&ea_inode->i_rwsem#9/1){+.+.}-{3:3}:
down_write+0x90/0x150 kernel/locking/rwsem.c:1542
inode_lock include/linux/fs.h:761 [inline]
ext4_xattr_inode_write fs/ext4/xattr.c:1392 [inline]
ext4_xattr_inode_lookup_create fs/ext4/xattr.c:1530 [inline]
ext4_xattr_set_entry+0x2ec5/0x3800 fs/ext4/xattr.c:1654
ext4_xattr_ibody_set+0x78/0x2b0 fs/ext4/xattr.c:2207
ext4_xattr_set_handle+0x964/0x1500 fs/ext4/xattr.c:2364
ext4_xattr_set+0x13a/0x340 fs/ext4/xattr.c:2477
__vfs_setxattr+0x115/0x180 fs/xattr.c:182
__vfs_setxattr_noperm+0x125/0x5f0 fs/xattr.c:216
__vfs_setxattr_locked+0x1cf/0x260 fs/xattr.c:277
vfs_setxattr+0x13f/0x330 fs/xattr.c:303
setxattr+0x146/0x160 fs/xattr.c:611
path_setxattr+0x197/0x1c0 fs/xattr.c:630
__do_sys_setxattr fs/xattr.c:646 [inline]
__se_sys_setxattr fs/xattr.c:642 [inline]
__x64_sys_setxattr+0xc0/0x160 fs/xattr.c:642
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+0x46/0xb0

-> #0 (&ei->xattr_sem){++++}-{3:3}:
check_prev_add kernel/locking/lockdep.c:3095 [inline]
check_prevs_add kernel/locking/lockdep.c:3214 [inline]
validate_chain kernel/locking/lockdep.c:3829 [inline]
__lock_acquire+0x2abe/0x5660 kernel/locking/lockdep.c:5053
lock_acquire kernel/locking/lockdep.c:5665 [inline]
lock_acquire+0x1ab/0x570 kernel/locking/lockdep.c:5630
down_read+0x98/0x440 kernel/locking/rwsem.c:1489
ext4_setattr+0x6ef/0x2c60 fs/ext4/inode.c:5378
notify_change+0xcd0/0x1440 fs/attr.c:418
chown_common+0x61b/0x710 fs/open.c:734
do_fchownat+0x126/0x1e0 fs/open.c:765
__do_sys_fchownat fs/open.c:780 [inline]
__se_sys_fchownat fs/open.c:777 [inline]
__x64_sys_fchownat+0xba/0x150 fs/open.c:777
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+0x46/0xb0

other info that might help us debug this:

Possible unsafe locking scenario:

CPU0 CPU1
---- ----
lock(&ea_inode->i_rwsem#9/1);
lock(&ei->xattr_sem);
lock(&ea_inode->i_rwsem#9/1);
lock(&ei->xattr_sem);

*** DEADLOCK ***

2 locks held by syz-executor.0/4082:
#0: ffff8880218da460 (sb_writers#4){.+.+}-{0:0}, at: do_fchownat+0x101/0x1e0 fs/open.c:762
#1: ffff888072781810 (&ea_inode->i_rwsem#9/1){+.+.}-{3:3}, at: inode_lock include/linux/fs.h:761 [inline]
#1: ffff888072781810 (&ea_inode->i_rwsem#9/1){+.+.}-{3:3}, at: chown_common+0x364/0x710 fs/open.c:727

stack backtrace:
CPU: 1 PID: 4082 Comm: syz-executor.0 Not tainted 5.19.0-rc4-next-20220628-syzkaller-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/22/2022
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
check_noncircular+0x25f/0x2e0 kernel/locking/lockdep.c:2175
check_prev_add kernel/locking/lockdep.c:3095 [inline]
check_prevs_add kernel/locking/lockdep.c:3214 [inline]
validate_chain kernel/locking/lockdep.c:3829 [inline]
__lock_acquire+0x2abe/0x5660 kernel/locking/lockdep.c:5053
lock_acquire kernel/locking/lockdep.c:5665 [inline]
lock_acquire+0x1ab/0x570 kernel/locking/lockdep.c:5630
down_read+0x98/0x440 kernel/locking/rwsem.c:1489
ext4_setattr+0x6ef/0x2c60 fs/ext4/inode.c:5378
notify_change+0xcd0/0x1440 fs/attr.c:418
chown_common+0x61b/0x710 fs/open.c:734
do_fchownat+0x126/0x1e0 fs/open.c:765
__do_sys_fchownat fs/open.c:780 [inline]
__se_sys_fchownat fs/open.c:777 [inline]
__x64_sys_fchownat+0xba/0x150 fs/open.c:777
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+0x46/0xb0
RIP: 0033:0x7fa069489209
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 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fa06a629168 EFLAGS: 00000246 ORIG_RAX: 0000000000000104
RAX: ffffffffffffffda RBX: 00007fa06959bf60 RCX: 00007fa069489209
RDX: 0000000000000000 RSI: 00000000200000c0 RDI: 0000000000000005
RBP: 00007fa0694e3161 R08: 0000000000001000 R09: 0000000000000000
R10: 000000000000ee01 R11: 0000000000000246 R12: 0000000000000000
R13: 00007fff974f8cff R14: 00007fa06a629300 R15: 0000000000022000
</TASK>


Tested on:

commit: cb71b93c Add linux-next specific files for 20220628
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
console output: https://syzkaller.appspot.com/x/log.txt?x=1144f671080000
kernel config: https://syzkaller.appspot.com/x/.config?x=badbc1adb2d582eb
dashboard link: https://syzkaller.appspot.com/bug?extid=62120febbd1ee3c3c860
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=11e377b6080000

Hillf Danton

unread,
Aug 8, 2022, 9:32:32 AM8/8/22
to syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Sun, 07 Aug 2022 06:08:25 -0700
> syzbot found the following issue on:
>
> HEAD commit: cb71b93c2dc3 Add linux-next specific files for 20220628
> git tree: linux-next
> console+strace: https://syzkaller.appspot.com/x/log.txt?x=10bdcf3c080000
> kernel config: https://syzkaller.appspot.com/x/.config?x=badbc1adb2d582eb
> dashboard link: https://syzkaller.appspot.com/bug?extid=62120febbd1ee3c3c860
> compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=10256c61080000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=11f3c832080000
>
Set NOQUOTA flag when initing inode to avoid acquiring inode lock.

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git cb71b93c2dc3

diff -pur a/fs/ext4/ext4.h b/fs/ext4/ext4.h
--- a/fs/ext4/ext4.h 2022-08-08 18:33:25.799893400 +0800
+++ b/fs/ext4/ext4.h 2022-08-08 18:40:22.348551400 +0800
@@ -441,6 +441,7 @@ struct flex_groups {
#define EXT4_VERITY_FL 0x00100000 /* Verity protected inode */
#define EXT4_EA_INODE_FL 0x00200000 /* Inode used for large EA */
/* 0x00400000 was formerly EXT4_EOFBLOCKS_FL */
+#define EXT4_EA_NOQUOTA_FL 0x00800000 /* Create inode with S__NOQUOTA set */

#define EXT4_DAX_FL 0x02000000 /* Inode is DAX */

diff -pur a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
--- a/fs/ext4/ialloc.c 2022-08-08 18:33:45.089849400 +0800
+++ b/fs/ext4/ialloc.c 2022-08-08 18:44:05.175154200 +0800
@@ -962,6 +962,8 @@ struct inode *__ext4_new_inode(struct us
return ERR_PTR(-ENOMEM);
ei = EXT4_I(inode);

+ if (i_flags & EXT4_EA_NOQUOTA_FL)
+ inode->i_flags |= S_NOQUOTA;
/*
* Initialize owners and quota early so that we don't have to account
* for quota initialization worst case in standard inode creating
diff -pur a/fs/ext4/xattr.c b/fs/ext4/xattr.c
--- a/fs/ext4/xattr.c 2022-08-08 18:33:07.849816600 +0800
+++ b/fs/ext4/xattr.c 2022-08-08 21:25:55.872674700 +0800
@@ -647,7 +647,8 @@ ext4_xattr_get(struct inode *inode, int
if (strlen(name) > 255)
return -ERANGE;

- down_read(&EXT4_I(inode)->xattr_sem);
+ if (!down_read_trylock(&EXT4_I(inode)->xattr_sem))
+ return -EDEADLK;
error = ext4_xattr_ibody_get(inode, name_index, name, buffer,
buffer_size);
if (error == -ENODATA)
@@ -1388,7 +1389,10 @@ retry:
block += 1;
}

- inode_lock(ea_inode);
+ if (!inode_trylock(ea_inode)) {
+ ret = -EDEADLK;
+ goto out;
+ }
i_size_write(ea_inode, wsize);
ext4_update_i_disksize(ea_inode, wsize);
inode_unlock(ea_inode);
@@ -1419,7 +1423,7 @@ static struct inode *ext4_xattr_inode_cr
*/
ea_inode = ext4_new_inode(handle, inode->i_sb->s_root->d_inode,
S_IFREG | 0600, NULL, inode->i_ino + 1, owner,
- EXT4_EA_INODE_FL);
+ EXT4_EA_INODE_FL | EXT4_EA_NOQUOTA_FL);
if (!IS_ERR(ea_inode)) {
ea_inode->i_op = &ext4_file_inode_operations;
ea_inode->i_fop = &ext4_file_operations;
@@ -1442,9 +1446,6 @@ static struct inode *ext4_xattr_inode_cr

syzbot

unread,
Aug 8, 2022, 9:03:13 PM8/8/22
to hda...@sina.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

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

Reported-and-tested-by: syzbot+62120f...@syzkaller.appspotmail.com

Tested on:

commit: cb71b93c Add linux-next specific files for 20220628
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
console output: https://syzkaller.appspot.com/x/log.txt?x=12afd10e080000
kernel config: https://syzkaller.appspot.com/x/.config?x=badbc1adb2d582eb
dashboard link: https://syzkaller.appspot.com/bug?extid=62120febbd1ee3c3c860
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=104ed896080000

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

Theodore Ts'o

unread,
Aug 8, 2022, 9:48:13 PM8/8/22
to syzbot, hda...@sina.com, linux-...@vger.kernel.org, linux...@vger.kernel.org, syzkall...@googlegroups.com
Hi Hillf,

Thanks for looking at this. For some reason, your e-mails with the
patch are available on the syzkaller-bugs google groups archive. For
example:

https://groups.google.com/g/syzkaller-bugs/c/NgC9hA3GX_Q/m/vVqsx8KTBQAJ

But even though your messages appear to be cc'ed to linux-kernel, I'm
not seeing your messages on lore.kernel.org's mail archives. (wWith
apologies to Lewis Caroll) "Curiouser and curiouser...."

This makes me worried that somehow some or all of your messages to
linux-ext4@ or linux-kernel@ on this matter are somehow getting lost.
We see syzkaller's reply to your messages, and anything that you've
cc'ed to syzkall...@googlegroups.com is available archived on
Google Groups. However, if there were any other messages that you
have sent, they may have been unseed by anyone else. :-(

If you could send a patch with a full description and the appropriate
Fixes: and CC: stable tags, could you make sure that you explicitly Cc
me, just in case something is funny going on with your e-mails to
mailing lists at vger.kernel.org?

Many thanks!

- Ted
Reply all
Reply to author
Forward
0 new messages