* [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
@ 2023-04-24 7:58 syzbot
2023-04-24 8:26 ` Dmitry Vyukov
` (7 more replies)
0 siblings, 8 replies; 30+ messages in thread
From: syzbot @ 2023-04-24 7:58 UTC (permalink / raw)
To: akpm, hughd, linux-kernel, linux-mm, syzkaller-bugs
Hello,
syzbot found the following issue on:
HEAD commit: 457391b03803 Linux 6.3
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=13226cf0280000
kernel config: https://syzkaller.appspot.com/x/.config?x=8c81c9a3d360ebcf
dashboard link: https://syzkaller.appspot.com/bug?extid=702361cf7e3d95758761
compiler: Debian clang version 15.0.7, GNU ld (GNU Binutils for Debian) 2.35.2
Unfortunately, I don't have any reproducer for this issue yet.
Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/6438dcb1c42d/disk-457391b0.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/20596c249e47/vmlinux-457391b0.xz
kernel image: https://storage.googleapis.com/syzbot-assets/cb715366a3e5/bzImage-457391b0.xz
IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+702361cf7e3d95758761@syzkaller.appspotmail.com
==================================================================
BUG: KCSAN: data-race in generic_fillattr / shmem_mknod
read-write to 0xffff8881049a9408 of 8 bytes by task 3383 on cpu 0:
shmem_mknod+0xdd/0x180 mm/shmem.c:2942
shmem_create+0x34/0x40 mm/shmem.c:2994
lookup_open fs/namei.c:3416 [inline]
open_last_lookups fs/namei.c:3484 [inline]
path_openat+0xd96/0x1d00 fs/namei.c:3712
do_filp_open+0xf6/0x200 fs/namei.c:3742
do_sys_openat2+0xb5/0x2a0 fs/open.c:1348
do_sys_open fs/open.c:1364 [inline]
__do_sys_openat fs/open.c:1380 [inline]
__se_sys_openat fs/open.c:1375 [inline]
__x64_sys_openat+0xf3/0x120 fs/open.c:1375
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
read to 0xffff8881049a9408 of 8 bytes by task 4291 on cpu 1:
i_size_read include/linux/fs.h:866 [inline]
generic_fillattr+0x13f/0x1e0 fs/stat.c:58
shmem_getattr+0x32a/0x3b0 mm/shmem.c:1068
vfs_getattr_nosec+0x1e3/0x3c0 fs/stat.c:133
vfs_getattr fs/stat.c:170 [inline]
vfs_statx+0x156/0x300 fs/stat.c:242
vfs_fstatat fs/stat.c:276 [inline]
__do_sys_newfstatat fs/stat.c:446 [inline]
__se_sys_newfstatat+0x8a/0x2a0 fs/stat.c:440
__x64_sys_newfstatat+0x55/0x60 fs/stat.c:440
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
value changed: 0x0000000000001644 -> 0x0000000000001658
Reported by Kernel Concurrency Sanitizer on:
CPU: 1 PID: 4291 Comm: udevd Not tainted 6.3.0-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/14/2023
==================================================================
---
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.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2023-04-24 7:58 syzbot
@ 2023-04-24 8:26 ` Dmitry Vyukov
2023-05-01 5:15 ` Tetsuo Handa
2024-01-12 12:15 ` syzbot
` (6 subsequent siblings)
7 siblings, 1 reply; 30+ messages in thread
From: Dmitry Vyukov @ 2023-04-24 8:26 UTC (permalink / raw)
To: syzbot; +Cc: akpm, hughd, linux-kernel, linux-mm, syzkaller-bugs
On Mon, 24 Apr 2023 at 09:58, syzbot
<syzbot+702361cf7e3d95758761@syzkaller.appspotmail.com> wrote:
>
> Hello,
>
> syzbot found the following issue on:
>
> HEAD commit: 457391b03803 Linux 6.3
> git tree: upstream
> console output: https://syzkaller.appspot.com/x/log.txt?x=13226cf0280000
> kernel config: https://syzkaller.appspot.com/x/.config?x=8c81c9a3d360ebcf
> dashboard link: https://syzkaller.appspot.com/bug?extid=702361cf7e3d95758761
> compiler: Debian clang version 15.0.7, GNU ld (GNU Binutils for Debian) 2.35.2
>
> Unfortunately, I don't have any reproducer for this issue yet.
>
> Downloadable assets:
> disk image: https://storage.googleapis.com/syzbot-assets/6438dcb1c42d/disk-457391b0.raw.xz
> vmlinux: https://storage.googleapis.com/syzbot-assets/20596c249e47/vmlinux-457391b0.xz
> kernel image: https://storage.googleapis.com/syzbot-assets/cb715366a3e5/bzImage-457391b0.xz
>
> IMPORTANT: if you fix the issue, please add the following tag to the commit:
> Reported-by: syzbot+702361cf7e3d95758761@syzkaller.appspotmail.com
I think shmem_mknod() needs to use i_size_write() to update the size.
Writes to i_size are not assumed to be atomic throughout the kernel
code.
> ==================================================================
> BUG: KCSAN: data-race in generic_fillattr / shmem_mknod
>
> read-write to 0xffff8881049a9408 of 8 bytes by task 3383 on cpu 0:
> shmem_mknod+0xdd/0x180 mm/shmem.c:2942
> shmem_create+0x34/0x40 mm/shmem.c:2994
> lookup_open fs/namei.c:3416 [inline]
> open_last_lookups fs/namei.c:3484 [inline]
> path_openat+0xd96/0x1d00 fs/namei.c:3712
> do_filp_open+0xf6/0x200 fs/namei.c:3742
> do_sys_openat2+0xb5/0x2a0 fs/open.c:1348
> do_sys_open fs/open.c:1364 [inline]
> __do_sys_openat fs/open.c:1380 [inline]
> __se_sys_openat fs/open.c:1375 [inline]
> __x64_sys_openat+0xf3/0x120 fs/open.c:1375
> do_syscall_x64 arch/x86/entry/common.c:50 [inline]
> do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
> entry_SYSCALL_64_after_hwframe+0x63/0xcd
>
> read to 0xffff8881049a9408 of 8 bytes by task 4291 on cpu 1:
> i_size_read include/linux/fs.h:866 [inline]
> generic_fillattr+0x13f/0x1e0 fs/stat.c:58
> shmem_getattr+0x32a/0x3b0 mm/shmem.c:1068
> vfs_getattr_nosec+0x1e3/0x3c0 fs/stat.c:133
> vfs_getattr fs/stat.c:170 [inline]
> vfs_statx+0x156/0x300 fs/stat.c:242
> vfs_fstatat fs/stat.c:276 [inline]
> __do_sys_newfstatat fs/stat.c:446 [inline]
> __se_sys_newfstatat+0x8a/0x2a0 fs/stat.c:440
> __x64_sys_newfstatat+0x55/0x60 fs/stat.c:440
> do_syscall_x64 arch/x86/entry/common.c:50 [inline]
> do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
> entry_SYSCALL_64_after_hwframe+0x63/0xcd
>
> value changed: 0x0000000000001644 -> 0x0000000000001658
>
> Reported by Kernel Concurrency Sanitizer on:
> CPU: 1 PID: 4291 Comm: udevd Not tainted 6.3.0-syzkaller #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/14/2023
> ==================================================================
>
>
> ---
> 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.
>
> --
> You received this message because you are subscribed to the Google Groups "syzkaller-bugs" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to syzkaller-bugs+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/syzkaller-bugs/0000000000007337c705fa1060e2%40google.com.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2023-04-24 8:26 ` Dmitry Vyukov
@ 2023-05-01 5:15 ` Tetsuo Handa
2023-05-01 14:05 ` Tetsuo Handa
2023-05-02 6:13 ` Dmitry Vyukov
0 siblings, 2 replies; 30+ messages in thread
From: Tetsuo Handa @ 2023-05-01 5:15 UTC (permalink / raw)
To: linux-fsdevel, Alexander Viro
Cc: akpm, hughd, linux-kernel, linux-mm, syzkaller-bugs, syzbot,
Dmitry Vyukov
On 2023/04/24 17:26, Dmitry Vyukov wrote:
>> HEAD commit: 457391b03803 Linux 6.3
>> git tree: upstream
>> console output: https://syzkaller.appspot.com/x/log.txt?x=13226cf0280000
>> kernel config: https://syzkaller.appspot.com/x/.config?x=8c81c9a3d360ebcf
>> dashboard link: https://syzkaller.appspot.com/bug?extid=702361cf7e3d95758761
>> compiler: Debian clang version 15.0.7, GNU ld (GNU Binutils for Debian) 2.35.2
>
> I think shmem_mknod() needs to use i_size_write() to update the size.
> Writes to i_size are not assumed to be atomic throughout the kernel
> code.
>
I don't think that using i_size_{read,write}() alone is sufficient,
for I think that i_size_{read,write}() needs data_race() annotation.
include/linux/fs.h | 13 +++++++++++--
mm/shmem.c | 12 ++++++------
2 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 21a981680856..0d067bbe3ee9 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -860,6 +860,13 @@ void filemap_invalidate_unlock_two(struct address_space *mapping1,
* the read or for example on x86 they can be still implemented as a
* cmpxchg8b without the need of the lock prefix). For SMP compiles
* and 64bit archs it makes no difference if preempt is enabled or not.
+ *
+ * However, when KCSAN is enabled, CPU being capable of reading/updating
+ * naturally aligned 8 bytes of memory atomically is not sufficient for
+ * avoiding KCSAN warning, for KCSAN checks whether value has changed between
+ * before and after of a read operation. But since we don't want to introduce
+ * seqcount overhead only for suppressing KCSAN warning, tell KCSAN that data
+ * race on accessing i_size field is acceptable.
*/
static inline loff_t i_size_read(const struct inode *inode)
{
@@ -880,7 +887,8 @@ static inline loff_t i_size_read(const struct inode *inode)
preempt_enable();
return i_size;
#else
- return inode->i_size;
+ /* See comment above. */
+ return data_race(inode->i_size);
#endif
}
@@ -902,7 +910,8 @@ static inline void i_size_write(struct inode *inode, loff_t i_size)
inode->i_size = i_size;
preempt_enable();
#else
- inode->i_size = i_size;
+ /* See comment above. */
+ data_race(inode->i_size = i_size);
#endif
}
diff --git a/mm/shmem.c b/mm/shmem.c
index e40a08c5c6d7..a2f20297fb59 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2951,7 +2951,7 @@ shmem_mknod(struct mnt_idmap *idmap, struct inode *dir,
goto out_iput;
error = 0;
- dir->i_size += BOGO_DIRENT_SIZE;
+ i_size_write(dir, i_size_read(dir) + BOGO_DIRENT_SIZE);
dir->i_ctime = dir->i_mtime = current_time(dir);
inode_inc_iversion(dir);
d_instantiate(dentry, inode);
@@ -3027,7 +3027,7 @@ static int shmem_link(struct dentry *old_dentry, struct inode *dir, struct dentr
goto out;
}
- dir->i_size += BOGO_DIRENT_SIZE;
+ i_size_write(dir, i_size_read(dir) + BOGO_DIRENT_SIZE);
inode->i_ctime = dir->i_ctime = dir->i_mtime = current_time(inode);
inode_inc_iversion(dir);
inc_nlink(inode);
@@ -3045,7 +3045,7 @@ static int shmem_unlink(struct inode *dir, struct dentry *dentry)
if (inode->i_nlink > 1 && !S_ISDIR(inode->i_mode))
shmem_free_inode(inode->i_sb);
- dir->i_size -= BOGO_DIRENT_SIZE;
+ i_size_write(dir, i_size_read(dir) - BOGO_DIRENT_SIZE);
inode->i_ctime = dir->i_ctime = dir->i_mtime = current_time(inode);
inode_inc_iversion(dir);
drop_nlink(inode);
@@ -3132,8 +3132,8 @@ static int shmem_rename2(struct mnt_idmap *idmap,
inc_nlink(new_dir);
}
- old_dir->i_size -= BOGO_DIRENT_SIZE;
- new_dir->i_size += BOGO_DIRENT_SIZE;
+ i_size_write(old_dir, i_size_read(old_dir) - BOGO_DIRENT_SIZE);
+ i_size_write(new_dir, i_size_read(new_dir) + BOGO_DIRENT_SIZE);
old_dir->i_ctime = old_dir->i_mtime =
new_dir->i_ctime = new_dir->i_mtime =
inode->i_ctime = current_time(old_dir);
@@ -3189,7 +3189,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,
folio_unlock(folio);
folio_put(folio);
}
- dir->i_size += BOGO_DIRENT_SIZE;
+ i_size_write(dir, i_size_read(dir) + BOGO_DIRENT_SIZE);
dir->i_ctime = dir->i_mtime = current_time(dir);
inode_inc_iversion(dir);
d_instantiate(dentry, inode);
Maybe we want i_size_add() ?
Also, there was a similar report on updating i_{ctime,mtime} to current_time()
which means that i_size is not the only field that is causing data race.
https://syzkaller.appspot.com/bug?id=067d40ab9ab23a6fa0a8156857ed54e295062a29
Hmm, where is the serialization that avoids concurrent
shmem_mknod()/shmem_mknod() or shmem_mknod()/shmem_unlink() ?
i_size_write() says "need locking around it (normally i_mutex)"...
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2023-05-01 5:15 ` Tetsuo Handa
@ 2023-05-01 14:05 ` Tetsuo Handa
2023-05-02 10:13 ` Tetsuo Handa
2023-05-02 6:13 ` Dmitry Vyukov
1 sibling, 1 reply; 30+ messages in thread
From: Tetsuo Handa @ 2023-05-01 14:05 UTC (permalink / raw)
To: linux-fsdevel, Alexander Viro
Cc: akpm, hughd, linux-kernel, linux-mm, syzkaller-bugs, syzbot,
Dmitry Vyukov
On 2023/05/01 14:15, Tetsuo Handa wrote:
> Hmm, where is the serialization that avoids concurrent
> shmem_mknod()/shmem_mknod() or shmem_mknod()/shmem_unlink() ?
> i_size_write() says "need locking around it (normally i_mutex)"...
>
Since filename_create() calls inode_lock_nested(path->dentry->d_inode, I_MUTEX_PARENT)
and done_path_create() calls inode_unlock(path->dentry->d_inode), serialization looks OK.
Just the name is no longer i_mutex ?
> Also, there was a similar report on updating i_{ctime,mtime} to current_time()
> which means that i_size is not the only field that is causing data race.
> https://syzkaller.appspot.com/bug?id=067d40ab9ab23a6fa0a8156857ed54e295062a29
Do we want to as well wrap i_{ctime,mtime} using data_race() ?
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2023-05-01 5:15 ` Tetsuo Handa
2023-05-01 14:05 ` Tetsuo Handa
@ 2023-05-02 6:13 ` Dmitry Vyukov
1 sibling, 0 replies; 30+ messages in thread
From: Dmitry Vyukov @ 2023-05-02 6:13 UTC (permalink / raw)
To: Tetsuo Handa
Cc: linux-fsdevel, Alexander Viro, akpm, hughd, linux-kernel,
linux-mm, syzkaller-bugs, syzbot
On Mon, 1 May 2023 at 07:16, Tetsuo Handa
<penguin-kernel@i-love.sakura.ne.jp> wrote:
>
> On 2023/04/24 17:26, Dmitry Vyukov wrote:
> >> HEAD commit: 457391b03803 Linux 6.3
> >> git tree: upstream
> >> console output: https://syzkaller.appspot.com/x/log.txt?x=13226cf0280000
> >> kernel config: https://syzkaller.appspot.com/x/.config?x=8c81c9a3d360ebcf
> >> dashboard link: https://syzkaller.appspot.com/bug?extid=702361cf7e3d95758761
> >> compiler: Debian clang version 15.0.7, GNU ld (GNU Binutils for Debian) 2.35.2
> >
> > I think shmem_mknod() needs to use i_size_write() to update the size.
> > Writes to i_size are not assumed to be atomic throughout the kernel
> > code.
> >
>
> I don't think that using i_size_{read,write}() alone is sufficient,
> for I think that i_size_{read,write}() needs data_race() annotation.
Agree. Or better proper READ/WRITE_ONCE.
data_race() is just an annotation, it does not fix the actual data
race bug that is present there.
I see there are lots of uses of i_size_read() in complex scenarios
that involve comparisons of the size. All such racy uses are subject
to the TOCTOU bug at least.
> include/linux/fs.h | 13 +++++++++++--
> mm/shmem.c | 12 ++++++------
> 2 files changed, 17 insertions(+), 8 deletions(-)
>
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 21a981680856..0d067bbe3ee9 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -860,6 +860,13 @@ void filemap_invalidate_unlock_two(struct address_space *mapping1,
> * the read or for example on x86 they can be still implemented as a
> * cmpxchg8b without the need of the lock prefix). For SMP compiles
> * and 64bit archs it makes no difference if preempt is enabled or not.
> + *
> + * However, when KCSAN is enabled, CPU being capable of reading/updating
> + * naturally aligned 8 bytes of memory atomically is not sufficient for
> + * avoiding KCSAN warning, for KCSAN checks whether value has changed between
> + * before and after of a read operation. But since we don't want to introduce
> + * seqcount overhead only for suppressing KCSAN warning, tell KCSAN that data
> + * race on accessing i_size field is acceptable.
> */
> static inline loff_t i_size_read(const struct inode *inode)
> {
> @@ -880,7 +887,8 @@ static inline loff_t i_size_read(const struct inode *inode)
> preempt_enable();
> return i_size;
> #else
> - return inode->i_size;
> + /* See comment above. */
> + return data_race(inode->i_size);
> #endif
> }
>
> @@ -902,7 +910,8 @@ static inline void i_size_write(struct inode *inode, loff_t i_size)
> inode->i_size = i_size;
> preempt_enable();
> #else
> - inode->i_size = i_size;
> + /* See comment above. */
> + data_race(inode->i_size = i_size);
> #endif
> }
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> index e40a08c5c6d7..a2f20297fb59 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -2951,7 +2951,7 @@ shmem_mknod(struct mnt_idmap *idmap, struct inode *dir,
> goto out_iput;
>
> error = 0;
> - dir->i_size += BOGO_DIRENT_SIZE;
> + i_size_write(dir, i_size_read(dir) + BOGO_DIRENT_SIZE);
> dir->i_ctime = dir->i_mtime = current_time(dir);
> inode_inc_iversion(dir);
> d_instantiate(dentry, inode);
> @@ -3027,7 +3027,7 @@ static int shmem_link(struct dentry *old_dentry, struct inode *dir, struct dentr
> goto out;
> }
>
> - dir->i_size += BOGO_DIRENT_SIZE;
> + i_size_write(dir, i_size_read(dir) + BOGO_DIRENT_SIZE);
> inode->i_ctime = dir->i_ctime = dir->i_mtime = current_time(inode);
> inode_inc_iversion(dir);
> inc_nlink(inode);
> @@ -3045,7 +3045,7 @@ static int shmem_unlink(struct inode *dir, struct dentry *dentry)
> if (inode->i_nlink > 1 && !S_ISDIR(inode->i_mode))
> shmem_free_inode(inode->i_sb);
>
> - dir->i_size -= BOGO_DIRENT_SIZE;
> + i_size_write(dir, i_size_read(dir) - BOGO_DIRENT_SIZE);
> inode->i_ctime = dir->i_ctime = dir->i_mtime = current_time(inode);
> inode_inc_iversion(dir);
> drop_nlink(inode);
> @@ -3132,8 +3132,8 @@ static int shmem_rename2(struct mnt_idmap *idmap,
> inc_nlink(new_dir);
> }
>
> - old_dir->i_size -= BOGO_DIRENT_SIZE;
> - new_dir->i_size += BOGO_DIRENT_SIZE;
> + i_size_write(old_dir, i_size_read(old_dir) - BOGO_DIRENT_SIZE);
> + i_size_write(new_dir, i_size_read(new_dir) + BOGO_DIRENT_SIZE);
> old_dir->i_ctime = old_dir->i_mtime =
> new_dir->i_ctime = new_dir->i_mtime =
> inode->i_ctime = current_time(old_dir);
> @@ -3189,7 +3189,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,
> folio_unlock(folio);
> folio_put(folio);
> }
> - dir->i_size += BOGO_DIRENT_SIZE;
> + i_size_write(dir, i_size_read(dir) + BOGO_DIRENT_SIZE);
> dir->i_ctime = dir->i_mtime = current_time(dir);
> inode_inc_iversion(dir);
> d_instantiate(dentry, inode);
>
> Maybe we want i_size_add() ?
>
> Also, there was a similar report on updating i_{ctime,mtime} to current_time()
> which means that i_size is not the only field that is causing data race.
> https://syzkaller.appspot.com/bug?id=067d40ab9ab23a6fa0a8156857ed54e295062a29
>
> Hmm, where is the serialization that avoids concurrent
> shmem_mknod()/shmem_mknod() or shmem_mknod()/shmem_unlink() ?
> i_size_write() says "need locking around it (normally i_mutex)"...
>
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2023-05-01 14:05 ` Tetsuo Handa
@ 2023-05-02 10:13 ` Tetsuo Handa
0 siblings, 0 replies; 30+ messages in thread
From: Tetsuo Handa @ 2023-05-02 10:13 UTC (permalink / raw)
To: linux-fsdevel, Alexander Viro
Cc: akpm, hughd, linux-kernel, linux-mm, syzkaller-bugs, syzbot,
Dmitry Vyukov
On 2023/05/01 23:05, Tetsuo Handa wrote:
>> Also, there was a similar report on updating i_{ctime,mtime} to current_time()
>> which means that i_size is not the only field that is causing data race.
>> https://syzkaller.appspot.com/bug?id=067d40ab9ab23a6fa0a8156857ed54e295062a29
>
> Do we want to as well wrap i_{ctime,mtime} using data_race() ?
>
I think we need to use inode_lock_shared()/inode_unlock_shared() when calling
generic_fillattr(), for i_{ctime,mtime} (128bits) are too large to copy atomically.
Is it safe to call inode_lock_shared()/inode_unlock_shared() from generic_fillattr()?
Is some filesystem already holding inode lock before calling generic_fillattr()?
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2023-04-24 7:58 syzbot
2023-04-24 8:26 ` Dmitry Vyukov
@ 2024-01-12 12:15 ` syzbot
2024-09-18 4:03 ` Jeongjun Park
` (5 subsequent siblings)
7 siblings, 0 replies; 30+ messages in thread
From: syzbot @ 2024-01-12 12:15 UTC (permalink / raw)
To: akpm, dvyukov, hughd, linux-fsdevel, linux-kernel, linux-mm,
penguin-kernel, syzkaller-bugs, viro
syzbot has found a reproducer for the following issue on:
HEAD commit: 70d201a40823 Merge tag 'f2fs-for-6.8-rc1' of git://git.ker..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=16e391f5e80000
kernel config: https://syzkaller.appspot.com/x/.config?x=31b069fcee8f481d
dashboard link: https://syzkaller.appspot.com/bug?extid=702361cf7e3d95758761
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=147a56a3e80000
Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/4446464b507c/disk-70d201a4.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/578f39e16cac/vmlinux-70d201a4.xz
kernel image: https://storage.googleapis.com/syzbot-assets/5fffd404e095/bzImage-70d201a4.xz
IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+702361cf7e3d95758761@syzkaller.appspotmail.com
==================================================================
BUG: KCSAN: data-race in generic_fillattr / shmem_mknod
write to 0xffff88810427aa10 of 8 bytes by task 3467 on cpu 1:
inode_set_mtime_to_ts include/linux/fs.h:1571 [inline]
shmem_mknod+0x132/0x180 mm/shmem.c:3259
shmem_create+0x34/0x40 mm/shmem.c:3313
lookup_open fs/namei.c:3486 [inline]
open_last_lookups fs/namei.c:3555 [inline]
path_openat+0xdc2/0x1d30 fs/namei.c:3785
do_filp_open+0xf6/0x200 fs/namei.c:3815
do_sys_openat2+0xab/0x110 fs/open.c:1404
do_sys_open fs/open.c:1419 [inline]
__do_sys_openat fs/open.c:1435 [inline]
__se_sys_openat fs/open.c:1430 [inline]
__x64_sys_openat+0xf3/0x120 fs/open.c:1430
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x59/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b
read to 0xffff88810427aa10 of 8 bytes by task 3068 on cpu 0:
inode_get_mtime include/linux/fs.h:1565 [inline]
generic_fillattr+0x1a6/0x2f0 fs/stat.c:61
shmem_getattr+0x17b/0x200 mm/shmem.c:1139
vfs_getattr_nosec fs/stat.c:135 [inline]
vfs_getattr+0x198/0x1e0 fs/stat.c:176
vfs_statx+0x140/0x320 fs/stat.c:248
vfs_fstatat+0xcd/0x100 fs/stat.c:304
__do_sys_newfstatat fs/stat.c:468 [inline]
__se_sys_newfstatat+0x58/0x260 fs/stat.c:462
__x64_sys_newfstatat+0x55/0x60 fs/stat.c:462
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x59/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b
value changed: 0x00000000366f1c62 -> 0x000000003707b2e3
Reported by Kernel Concurrency Sanitizer on:
CPU: 0 PID: 3068 Comm: udevd Not tainted 6.7.0-syzkaller-06264-g70d201a40823 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/17/2023
==================================================================
---
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.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2024-09-08 5:23 Jeongjun Park
@ 2024-09-08 5:39 ` syzbot
0 siblings, 0 replies; 30+ messages in thread
From: syzbot @ 2024-09-08 5:39 UTC (permalink / raw)
To: aha310510, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KCSAN: data-race in ext4_free_inodes_count / ext4_free_inodes_set
==================================================================
BUG: KCSAN: data-race in ext4_free_inodes_count / ext4_free_inodes_set
write to 0xffff888103fc500e of 2 bytes by task 13551 on cpu 0:
ext4_free_inodes_set+0x1f/0x80 fs/ext4/super.c:405
__ext4_new_inode+0x15ca/0x2200 fs/ext4/ialloc.c:1216
ext4_symlink+0x242/0x5a0 fs/ext4/namei.c:3391
vfs_symlink+0xca/0x1d0 fs/namei.c:4568
do_symlinkat+0xe3/0x340 fs/namei.c:4594
__do_sys_symlinkat fs/namei.c:4610 [inline]
__se_sys_symlinkat fs/namei.c:4607 [inline]
__x64_sys_symlinkat+0x5e/0x70 fs/namei.c:4607
x64_sys_call+0x1dda/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:267
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x76/0x7e
read to 0xffff888103fc500e of 2 bytes by task 13552 on cpu 1:
ext4_free_inodes_count+0x1c/0x80 fs/ext4/super.c:349
find_group_other fs/ext4/ialloc.c:594 [inline]
__ext4_new_inode+0x6ec/0x2200 fs/ext4/ialloc.c:1017
ext4_symlink+0x242/0x5a0 fs/ext4/namei.c:3391
vfs_symlink+0xca/0x1d0 fs/namei.c:4568
do_symlinkat+0xe3/0x340 fs/namei.c:4594
__do_sys_symlinkat fs/namei.c:4610 [inline]
__se_sys_symlinkat fs/namei.c:4607 [inline]
__x64_sys_symlinkat+0x5e/0x70 fs/namei.c:4607
x64_sys_call+0x1dda/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:267
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x76/0x7e
value changed: 0x185c -> 0x185b
Reported by Kernel Concurrency Sanitizer on:
CPU: 1 UID: 0 PID: 13552 Comm: syz-executor.1 Not tainted 6.11.0-rc6-syzkaller-00326-gd1f2d51b711a-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
==================================================================
Tested on:
commit: d1f2d51b Merge tag 'clk-fixes-for-linus' of git://git...
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=17ffef29980000
kernel config: https://syzkaller.appspot.com/x/.config?x=e81d40b0108ea8fe
dashboard link: https://syzkaller.appspot.com/bug?extid=702361cf7e3d95758761
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=17d10e00580000
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2024-09-08 6:09 Jeongjun Park
@ 2024-09-08 6:49 ` syzbot
0 siblings, 0 replies; 30+ messages in thread
From: syzbot @ 2024-09-08 6:49 UTC (permalink / raw)
To: aha310510, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KCSAN: data-race in ext4_fill_raw_inode / ext4_orphan_del
==================================================================
BUG: KCSAN: data-race in ext4_fill_raw_inode / ext4_orphan_del
write to 0xffff8881054ccdd4 of 4 bytes by task 3372 on cpu 1:
ext4_orphan_del+0x54d/0x6e0 fs/ext4/orphan.c:296
ext4_evict_inode+0xac3/0xdc0 fs/ext4/inode.c:289
evict+0x2d7/0x560 fs/inode.c:704
iput_final fs/inode.c:1838 [inline]
iput+0x432/0x5c0 fs/inode.c:1864
d_delete_notify include/linux/fsnotify.h:332 [inline]
vfs_rmdir+0x29f/0x320 fs/namei.c:4306
do_rmdir+0x194/0x320 fs/namei.c:4352
__do_sys_unlinkat fs/namei.c:4528 [inline]
__se_sys_unlinkat fs/namei.c:4522 [inline]
__x64_sys_unlinkat+0xa2/0xb0 fs/namei.c:4522
x64_sys_call+0x25fd/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:264
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x76/0x7e
read to 0xffff8881054ccdd4 of 4 bytes by task 3392 on cpu 0:
ext4_fill_raw_inode+0x64b/0xe80 fs/ext4/inode.c:4348
ext4_do_update_inode fs/ext4/inode.c:5151 [inline]
ext4_mark_iloc_dirty+0x2e9/0xe10 fs/ext4/inode.c:5781
__ext4_mark_inode_dirty+0x314/0x440 fs/ext4/inode.c:5985
__ext4_ext_dirty fs/ext4/extents.c:202 [inline]
ext4_ext_remove_space+0x28ca/0x2c80 fs/ext4/extents.c:3038
ext4_ext_truncate+0xc4/0x150 fs/ext4/extents.c:4441
ext4_truncate+0x773/0xb10 fs/ext4/inode.c:4218
ext4_evict_inode+0x8b4/0xdc0 fs/ext4/inode.c:258
evict+0x2d7/0x560 fs/inode.c:704
iput_final fs/inode.c:1838 [inline]
iput+0x432/0x5c0 fs/inode.c:1864
d_delete_notify include/linux/fsnotify.h:332 [inline]
vfs_rmdir+0x29f/0x320 fs/namei.c:4306
do_rmdir+0x194/0x320 fs/namei.c:4352
__do_sys_unlinkat fs/namei.c:4528 [inline]
__se_sys_unlinkat fs/namei.c:4522 [inline]
__x64_sys_unlinkat+0xa2/0xb0 fs/namei.c:4522
x64_sys_call+0x25fd/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:264
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x76/0x7e
value changed: 0x0000079a -> 0x0000078b
Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 3392 Comm: syz-executor.1 Not tainted 6.11.0-rc6-syzkaller-00326-gd1f2d51b711a #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
==================================================================
Tested on:
commit: d1f2d51b Merge tag 'clk-fixes-for-linus' of git://git...
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=151e1ffb980000
kernel config: https://syzkaller.appspot.com/x/.config?x=e81d40b0108ea8fe
dashboard link: https://syzkaller.appspot.com/bug?extid=702361cf7e3d95758761
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
Note: no patches were applied.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2024-09-08 6:27 Jeongjun Park
@ 2024-09-08 6:59 ` syzbot
0 siblings, 0 replies; 30+ messages in thread
From: syzbot @ 2024-09-08 6:59 UTC (permalink / raw)
To: aha310510, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KCSAN: data-race in ext4_fill_raw_inode / ext4_orphan_del
==================================================================
BUG: KCSAN: data-race in ext4_fill_raw_inode / ext4_orphan_del
write to 0xffff88810fc69b6c of 4 bytes by task 3364 on cpu 0:
ext4_orphan_del+0x54d/0x6e0 fs/ext4/orphan.c:296
ext4_evict_inode+0xac3/0xdc0 fs/ext4/inode.c:289
evict+0x2d7/0x560 fs/inode.c:704
iput_final fs/inode.c:1838 [inline]
iput+0x432/0x5c0 fs/inode.c:1864
d_delete_notify include/linux/fsnotify.h:332 [inline]
vfs_rmdir+0x29f/0x320 fs/namei.c:4306
do_rmdir+0x194/0x320 fs/namei.c:4352
__do_sys_unlinkat fs/namei.c:4528 [inline]
__se_sys_unlinkat fs/namei.c:4522 [inline]
__x64_sys_unlinkat+0xa2/0xb0 fs/namei.c:4522
x64_sys_call+0x25fd/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:264
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x76/0x7e
read to 0xffff88810fc69b6c of 4 bytes by task 3413 on cpu 1:
ext4_fill_raw_inode+0x64b/0xe80 fs/ext4/inode.c:4348
ext4_do_update_inode fs/ext4/inode.c:5151 [inline]
ext4_mark_iloc_dirty+0x2e9/0xe10 fs/ext4/inode.c:5781
__ext4_mark_inode_dirty+0x314/0x440 fs/ext4/inode.c:5985
ext4_dirty_inode+0x91/0xb0 fs/ext4/inode.c:6014
__mark_inode_dirty+0x16d/0x7d0 fs/fs-writeback.c:2486
mark_inode_dirty_sync include/linux/fs.h:2437 [inline]
dquot_free_space include/linux/quotaops.h:380 [inline]
dquot_free_block include/linux/quotaops.h:390 [inline]
ext4_mb_clear_bb fs/ext4/mballoc.c:6534 [inline]
ext4_free_blocks+0xe8b/0x14b0 fs/ext4/mballoc.c:6653
ext4_remove_blocks fs/ext4/extents.c:2521 [inline]
ext4_ext_rm_leaf fs/ext4/extents.c:2686 [inline]
ext4_ext_remove_space+0x16ba/0x2c80 fs/ext4/extents.c:2934
ext4_ext_truncate+0xc4/0x150 fs/ext4/extents.c:4441
ext4_truncate+0x773/0xb10 fs/ext4/inode.c:4218
ext4_evict_inode+0x8b4/0xdc0 fs/ext4/inode.c:258
evict+0x2d7/0x560 fs/inode.c:704
iput_final fs/inode.c:1838 [inline]
iput+0x432/0x5c0 fs/inode.c:1864
d_delete_notify include/linux/fsnotify.h:332 [inline]
vfs_rmdir+0x29f/0x320 fs/namei.c:4306
do_rmdir+0x194/0x320 fs/namei.c:4352
__do_sys_unlinkat fs/namei.c:4528 [inline]
__se_sys_unlinkat fs/namei.c:4522 [inline]
__x64_sys_unlinkat+0xa2/0xb0 fs/namei.c:4522
x64_sys_call+0x25fd/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:264
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x76/0x7e
value changed: 0x0000079b -> 0x00000000
Reported by Kernel Concurrency Sanitizer on:
CPU: 1 UID: 0 PID: 3413 Comm: syz-executor.5 Not tainted 6.11.0-rc6-syzkaller-00326-gd1f2d51b711a-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
==================================================================
Tested on:
commit: d1f2d51b Merge tag 'clk-fixes-for-linus' of git://git...
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=1400589f980000
kernel config: https://syzkaller.appspot.com/x/.config?x=e81d40b0108ea8fe
dashboard link: https://syzkaller.appspot.com/bug?extid=702361cf7e3d95758761
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=10a50e00580000
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2024-09-08 7:47 Jeongjun Park
@ 2024-09-08 8:01 ` syzbot
0 siblings, 0 replies; 30+ messages in thread
From: syzbot @ 2024-09-08 8:01 UTC (permalink / raw)
To: aha310510, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KCSAN: data-race in pcpu_alloc_noprof / pcpu_free_area
==================================================================
BUG: KCSAN: data-race in pcpu_alloc_noprof / pcpu_free_area
read-write to 0xffffffff883f872c of 4 bytes by task 3378 on cpu 0:
pcpu_update_empty_pages mm/percpu.c:602 [inline]
pcpu_block_update_hint_free mm/percpu.c:1044 [inline]
pcpu_free_area+0x4dc/0x570 mm/percpu.c:1302
free_percpu+0x1c6/0xb30 mm/percpu.c:2277
xt_percpu_counter_free+0x63/0x80 net/netfilter/x_tables.c:1951
cleanup_entry+0x195/0x1c0 net/ipv6/netfilter/ip6_tables.c:671
__do_replace+0x470/0x580 net/ipv6/netfilter/ip6_tables.c:1099
do_replace net/ipv6/netfilter/ip6_tables.c:1158 [inline]
do_ip6t_set_ctl+0x820/0x8c0 net/ipv6/netfilter/ip6_tables.c:1644
nf_setsockopt+0x195/0x1b0 net/netfilter/nf_sockopt.c:101
ipv6_setsockopt+0x126/0x140 net/ipv6/ipv6_sockglue.c:998
tcp_setsockopt+0x93/0xb0 net/ipv4/tcp.c:3768
sock_common_setsockopt+0x64/0x80 net/core/sock.c:3735
do_sock_setsockopt net/socket.c:2324 [inline]
__sys_setsockopt+0x1d8/0x250 net/socket.c:2347
__do_sys_setsockopt net/socket.c:2356 [inline]
__se_sys_setsockopt net/socket.c:2353 [inline]
__x64_sys_setsockopt+0x66/0x80 net/socket.c:2353
x64_sys_call+0x278d/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:55
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x76/0x7e
read to 0xffffffff883f872c of 4 bytes by task 3374 on cpu 1:
pcpu_alloc_noprof+0x9a5/0x10c0 mm/percpu.c:1894
xt_percpu_counter_alloc+0x79/0x110 net/netfilter/x_tables.c:1931
find_check_entry net/ipv4/netfilter/ip_tables.c:526 [inline]
translate_table+0x921/0xf70 net/ipv4/netfilter/ip_tables.c:716
do_replace net/ipv4/netfilter/ip_tables.c:1137 [inline]
do_ipt_set_ctl+0x7bd/0x8b0 net/ipv4/netfilter/ip_tables.c:1635
nf_setsockopt+0x195/0x1b0 net/netfilter/nf_sockopt.c:101
ip_setsockopt+0xea/0x100 net/ipv4/ip_sockglue.c:1424
tcp_setsockopt+0x93/0xb0 net/ipv4/tcp.c:3768
sock_common_setsockopt+0x64/0x80 net/core/sock.c:3735
do_sock_setsockopt net/socket.c:2324 [inline]
__sys_setsockopt+0x1d8/0x250 net/socket.c:2347
__do_sys_setsockopt net/socket.c:2356 [inline]
__se_sys_setsockopt net/socket.c:2353 [inline]
__x64_sys_setsockopt+0x66/0x80 net/socket.c:2353
x64_sys_call+0x278d/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:55
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x76/0x7e
value changed: 0x00000005 -> 0x00000006
Reported by Kernel Concurrency Sanitizer on:
CPU: 1 UID: 0 PID: 3374 Comm: syz-executor.3 Not tainted 6.11.0-rc6-syzkaller-00326-gd1f2d51b711a-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
==================================================================
Tested on:
commit: d1f2d51b Merge tag 'clk-fixes-for-linus' of git://git...
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=10691ffb980000
kernel config: https://syzkaller.appspot.com/x/.config?x=e81d40b0108ea8fe
dashboard link: https://syzkaller.appspot.com/bug?extid=702361cf7e3d95758761
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=117d8877980000
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2024-09-08 8:16 Jeongjun Park
@ 2024-09-08 9:31 ` syzbot
0 siblings, 0 replies; 30+ messages in thread
From: syzbot @ 2024-09-08 9:31 UTC (permalink / raw)
To: aha310510, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KCSAN: data-race in jbd2_journal_dirty_metadata / jbd2_journal_dirty_metadata
==================================================================
BUG: KCSAN: data-race in jbd2_journal_dirty_metadata / jbd2_journal_dirty_metadata
write to 0xffff88810062608c of 4 bytes by task 7571 on cpu 1:
jbd2_journal_dirty_metadata+0x346/0x6d0 fs/jbd2/transaction.c:1560
__ext4_handle_dirty_metadata+0xe6/0x470 fs/ext4/ext4_jbd2.c:354
__ext4_new_inode+0x11fd/0x2200 fs/ext4/ialloc.c:1124
ext4_create+0x172/0x2f0 fs/ext4/namei.c:2832
lookup_open fs/namei.c:3578 [inline]
open_last_lookups fs/namei.c:3647 [inline]
path_openat+0xdbc/0x1f00 fs/namei.c:3883
do_filp_open+0xf7/0x200 fs/namei.c:3913
do_sys_openat2+0xab/0x120 fs/open.c:1416
do_sys_open fs/open.c:1431 [inline]
__do_sys_open fs/open.c:1439 [inline]
__se_sys_open fs/open.c:1435 [inline]
__x64_sys_open+0xe6/0x110 fs/open.c:1435
x64_sys_call+0x1321/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:3
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x76/0x7e
read to 0xffff88810062608c of 4 bytes by task 7575 on cpu 0:
jbd2_journal_dirty_metadata+0xff/0x6d0 fs/jbd2/transaction.c:1516
__ext4_handle_dirty_metadata+0xe6/0x470 fs/ext4/ext4_jbd2.c:354
__ext4_new_inode+0x11fd/0x2200 fs/ext4/ialloc.c:1124
ext4_symlink+0x242/0x5a0 fs/ext4/namei.c:3391
vfs_symlink+0xca/0x1d0 fs/namei.c:4568
do_symlinkat+0xe3/0x340 fs/namei.c:4594
__do_sys_symlinkat fs/namei.c:4610 [inline]
__se_sys_symlinkat fs/namei.c:4607 [inline]
__x64_sys_symlinkat+0x5e/0x70 fs/namei.c:4607
x64_sys_call+0x1dda/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:267
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x76/0x7e
value changed: 0x00000000 -> 0x00000001
Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 7575 Comm: syz-executor.5 Not tainted 6.11.0-rc6-syzkaller-00326-gd1f2d51b711a-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
==================================================================
Tested on:
commit: d1f2d51b Merge tag 'clk-fixes-for-linus' of git://git...
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=134f8877980000
kernel config: https://syzkaller.appspot.com/x/.config?x=e81d40b0108ea8fe
dashboard link: https://syzkaller.appspot.com/bug?extid=702361cf7e3d95758761
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=15538877980000
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2024-09-08 8:34 Jeongjun Park
@ 2024-09-08 9:45 ` syzbot
0 siblings, 0 replies; 30+ messages in thread
From: syzbot @ 2024-09-08 9:45 UTC (permalink / raw)
To: aha310510, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KCSAN: data-race in generic_fillattr / inode_set_ctime_current
==================================================================
BUG: KCSAN: data-race in generic_fillattr / inode_set_ctime_current
write to 0xffff888102eb3260 of 4 bytes by task 6565 on cpu 1:
inode_set_ctime_to_ts include/linux/fs.h:1638 [inline]
inode_set_ctime_current+0x169/0x1d0 fs/inode.c:2626
shmem_mknod+0x117/0x180 mm/shmem.c:3443
shmem_create+0x34/0x40 mm/shmem.c:3497
lookup_open fs/namei.c:3578 [inline]
open_last_lookups fs/namei.c:3647 [inline]
path_openat+0xdbc/0x1f00 fs/namei.c:3883
do_filp_open+0xf7/0x200 fs/namei.c:3913
do_sys_openat2+0xab/0x120 fs/open.c:1416
do_sys_open fs/open.c:1431 [inline]
__do_sys_openat fs/open.c:1447 [inline]
__se_sys_openat fs/open.c:1442 [inline]
__x64_sys_openat+0xf3/0x120 fs/open.c:1442
x64_sys_call+0x1025/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:258
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x76/0x7e
read to 0xffff888102eb3260 of 4 bytes by task 3498 on cpu 0:
inode_get_ctime_nsec include/linux/fs.h:1623 [inline]
inode_get_ctime include/linux/fs.h:1629 [inline]
generic_fillattr+0x1dd/0x2f0 fs/stat.c:62
shmem_getattr+0x17b/0x200 mm/shmem.c:1157
vfs_getattr_nosec fs/stat.c:166 [inline]
vfs_getattr+0x19b/0x1e0 fs/stat.c:207
vfs_statx_path fs/stat.c:251 [inline]
vfs_statx+0x134/0x2f0 fs/stat.c:315
vfs_fstatat+0xec/0x110 fs/stat.c:341
__do_sys_newfstatat fs/stat.c:505 [inline]
__se_sys_newfstatat+0x58/0x260 fs/stat.c:499
__x64_sys_newfstatat+0x55/0x70 fs/stat.c:499
x64_sys_call+0x141f/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:263
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x76/0x7e
value changed: 0x2755ae53 -> 0x27ee44d3
Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 3498 Comm: udevd Not tainted 6.11.0-rc6-syzkaller-00326-gd1f2d51b711a-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
==================================================================
Tested on:
commit: d1f2d51b Merge tag 'clk-fixes-for-linus' of git://git...
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=165f8877980000
kernel config: https://syzkaller.appspot.com/x/.config?x=e81d40b0108ea8fe
dashboard link: https://syzkaller.appspot.com/bug?extid=702361cf7e3d95758761
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=1363abc7980000
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2024-09-08 10:27 Jeongjun Park
@ 2024-09-08 10:44 ` syzbot
0 siblings, 0 replies; 30+ messages in thread
From: syzbot @ 2024-09-08 10:44 UTC (permalink / raw)
To: aha310510, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KCSAN: data-race in __fsnotify_parent / fsnotify_put_mark
==================================================================
BUG: KCSAN: data-race in __fsnotify_parent / fsnotify_put_mark
write to 0xffff888101229cf0 of 4 bytes by task 3493 on cpu 0:
fsnotify_detach_connector_from_object fs/notify/mark.c:330 [inline]
fsnotify_put_mark+0x2db/0x5d0 fs/notify/mark.c:393
__do_sys_inotify_rm_watch fs/notify/inotify/inotify_user.c:819 [inline]
__se_sys_inotify_rm_watch+0x105/0x180 fs/notify/inotify/inotify_user.c:793
__x64_sys_inotify_rm_watch+0x31/0x40 fs/notify/inotify/inotify_user.c:793
x64_sys_call+0x1ae0/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:256
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x76/0x7e
read to 0xffff888101229cf0 of 4 bytes by task 3339 on cpu 1:
fsnotify_object_watched fs/notify/fsnotify.c:198 [inline]
__fsnotify_parent+0xd4/0x380 fs/notify/fsnotify.c:228
fsnotify_parent include/linux/fsnotify.h:96 [inline]
fsnotify_file include/linux/fsnotify.h:131 [inline]
fsnotify_open include/linux/fsnotify.h:401 [inline]
vfs_open+0x1be/0x1f0 fs/open.c:1096
do_open fs/namei.c:3727 [inline]
path_openat+0x1a1e/0x1f00 fs/namei.c:3886
do_filp_open+0xf7/0x200 fs/namei.c:3913
do_sys_openat2+0xab/0x120 fs/open.c:1416
do_sys_open fs/open.c:1431 [inline]
__do_sys_openat fs/open.c:1447 [inline]
__se_sys_openat fs/open.c:1442 [inline]
__x64_sys_openat+0xf3/0x120 fs/open.c:1442
x64_sys_call+0x1025/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:258
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x76/0x7e
value changed: 0x00002008 -> 0x00000000
Reported by Kernel Concurrency Sanitizer on:
CPU: 1 UID: 0 PID: 3339 Comm: syz-executor.2 Not tainted 6.11.0-rc6-syzkaller-00326-gd1f2d51b711a-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
==================================================================
Tested on:
commit: d1f2d51b Merge tag 'clk-fixes-for-linus' of git://git...
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=169a589f980000
kernel config: https://syzkaller.appspot.com/x/.config?x=e81d40b0108ea8fe
dashboard link: https://syzkaller.appspot.com/bug?extid=702361cf7e3d95758761
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=142a589f980000
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
@ 2024-09-08 11:33 Jeongjun Park
2024-09-08 11:49 ` syzbot
0 siblings, 1 reply; 30+ messages in thread
From: Jeongjun Park @ 2024-09-08 11:33 UTC (permalink / raw)
To: syzbot+702361cf7e3d95758761; +Cc: linux-kernel, syzkaller-bugs
#syz test git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
---
fs/ext4/orphan.c | 2 +-
fs/ext4/super.c | 4 ++--
mm/percpu.c | 5 ++---
mm/shmem.c | 12 +++++++-----
4 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/fs/ext4/orphan.c b/fs/ext4/orphan.c
index e5b47dda3317..08299b2a1b3b 100644
--- a/fs/ext4/orphan.c
+++ b/fs/ext4/orphan.c
@@ -293,7 +293,7 @@ int ext4_orphan_del(handle_t *handle, struct inode *inode)
mutex_unlock(&sbi->s_orphan_lock);
goto out_brelse;
}
- NEXT_ORPHAN(i_prev) = ino_next;
+ WRITE_ONCE(NEXT_ORPHAN(i_prev), ino_next);
err = ext4_mark_iloc_dirty(handle, i_prev, &iloc2);
mutex_unlock(&sbi->s_orphan_lock);
}
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index e72145c4ae5a..8cc5e19bfe78 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -346,7 +346,7 @@ __u32 ext4_free_group_clusters(struct super_block *sb,
__u32 ext4_free_inodes_count(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le16_to_cpu(bg->bg_free_inodes_count_lo) |
+ return le16_to_cpu(READ_ONCE(bg->bg_free_inodes_count_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
(__u32)le16_to_cpu(bg->bg_free_inodes_count_hi) << 16 : 0);
}
@@ -402,7 +402,7 @@ void ext4_free_group_clusters_set(struct super_block *sb,
void ext4_free_inodes_set(struct super_block *sb,
struct ext4_group_desc *bg, __u32 count)
{
- bg->bg_free_inodes_count_lo = cpu_to_le16((__u16)count);
+ WRITE_ONCE(bg->bg_free_inodes_count_lo, cpu_to_le16((__u16)count));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
bg->bg_free_inodes_count_hi = cpu_to_le16(count >> 16);
}
diff --git a/mm/percpu.c b/mm/percpu.c
index 20d91af8c033..5c958a54da51 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -1864,7 +1864,6 @@ void __percpu *pcpu_alloc_noprof(size_t size, size_t align, bool reserved,
area_found:
pcpu_stats_area_alloc(chunk, size);
- spin_unlock_irqrestore(&pcpu_lock, flags);
/* populate if not all pages are already there */
if (!is_atomic) {
@@ -1878,14 +1877,12 @@ void __percpu *pcpu_alloc_noprof(size_t size, size_t align, bool reserved,
ret = pcpu_populate_chunk(chunk, rs, re, pcpu_gfp);
- spin_lock_irqsave(&pcpu_lock, flags);
if (ret) {
pcpu_free_area(chunk, off);
err = "failed to populate";
goto fail_unlock;
}
pcpu_chunk_populated(chunk, rs, re);
- spin_unlock_irqrestore(&pcpu_lock, flags);
}
mutex_unlock(&pcpu_alloc_mutex);
@@ -1894,6 +1891,8 @@ void __percpu *pcpu_alloc_noprof(size_t size, size_t align, bool reserved,
if (pcpu_nr_empty_pop_pages < PCPU_EMPTY_POP_PAGES_LOW)
pcpu_schedule_balance_work();
+ spin_unlock_irqrestore(&pcpu_lock, flags);
+
/* clear the areas and return address relative to base address */
for_each_possible_cpu(cpu)
memset((void *)pcpu_chunk_addr(chunk, cpu, 0) + off, 0, size);
diff --git a/mm/shmem.c b/mm/shmem.c
index 5a77acf6ac6a..1595f6e7688c 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1154,7 +1154,9 @@ static int shmem_getattr(struct mnt_idmap *idmap,
stat->attributes_mask |= (STATX_ATTR_APPEND |
STATX_ATTR_IMMUTABLE |
STATX_ATTR_NODUMP);
+ inode_lock_shared(inode);
generic_fillattr(idmap, request_mask, inode, stat);
+ inode_unlock_shared(inode);
if (shmem_is_huge(inode, 0, false, NULL, 0))
stat->blksize = HPAGE_PMD_SIZE;
@@ -3439,7 +3441,7 @@ shmem_mknod(struct mnt_idmap *idmap, struct inode *dir,
if (error)
goto out_iput;
- dir->i_size += BOGO_DIRENT_SIZE;
+ i_size_write(dir, i_size_read(dir) + BOGO_DIRENT_SIZE);
inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
inode_inc_iversion(dir);
d_instantiate(dentry, inode);
@@ -3526,7 +3528,7 @@ static int shmem_link(struct dentry *old_dentry, struct inode *dir,
goto out;
}
- dir->i_size += BOGO_DIRENT_SIZE;
+ i_size_write(dir, i_size_read(dir) + BOGO_DIRENT_SIZE);
inode_set_mtime_to_ts(dir,
inode_set_ctime_to_ts(dir, inode_set_ctime_current(inode)));
inode_inc_iversion(dir);
@@ -3639,8 +3641,8 @@ static int shmem_rename2(struct mnt_idmap *idmap,
inc_nlink(new_dir);
}
- old_dir->i_size -= BOGO_DIRENT_SIZE;
- new_dir->i_size += BOGO_DIRENT_SIZE;
+ i_size_write(old_dir, i_size_read(old_dir) - BOGO_DIRENT_SIZE);
+ i_size_write(new_dir, i_size_read(new_dir) + BOGO_DIRENT_SIZE);
simple_rename_timestamp(old_dir, old_dentry, new_dir, new_dentry);
inode_inc_iversion(old_dir);
inode_inc_iversion(new_dir);
@@ -3694,7 +3696,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,
folio_unlock(folio);
folio_put(folio);
}
- dir->i_size += BOGO_DIRENT_SIZE;
+ i_size_write(dir, i_size_read(dir) + BOGO_DIRENT_SIZE);
inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
inode_inc_iversion(dir);
d_instantiate(dentry, inode);
--
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
@ 2024-09-08 11:33 Jeongjun Park
2024-09-08 12:08 ` syzbot
0 siblings, 1 reply; 30+ messages in thread
From: Jeongjun Park @ 2024-09-08 11:33 UTC (permalink / raw)
To: syzbot+702361cf7e3d95758761; +Cc: linux-kernel, syzkaller-bugs
#syz test git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
---
fs/ext4/orphan.c | 2 +-
fs/ext4/super.c | 4 ++--
mm/percpu.c | 5 ++---
mm/shmem.c | 12 +++++++-----
4 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/fs/ext4/orphan.c b/fs/ext4/orphan.c
index e5b47dda3317..08299b2a1b3b 100644
--- a/fs/ext4/orphan.c
+++ b/fs/ext4/orphan.c
@@ -293,7 +293,7 @@ int ext4_orphan_del(handle_t *handle, struct inode *inode)
mutex_unlock(&sbi->s_orphan_lock);
goto out_brelse;
}
- NEXT_ORPHAN(i_prev) = ino_next;
+ WRITE_ONCE(NEXT_ORPHAN(i_prev), ino_next);
err = ext4_mark_iloc_dirty(handle, i_prev, &iloc2);
mutex_unlock(&sbi->s_orphan_lock);
}
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index e72145c4ae5a..8cc5e19bfe78 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -346,7 +346,7 @@ __u32 ext4_free_group_clusters(struct super_block *sb,
__u32 ext4_free_inodes_count(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le16_to_cpu(bg->bg_free_inodes_count_lo) |
+ return le16_to_cpu(READ_ONCE(bg->bg_free_inodes_count_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
(__u32)le16_to_cpu(bg->bg_free_inodes_count_hi) << 16 : 0);
}
@@ -402,7 +402,7 @@ void ext4_free_group_clusters_set(struct super_block *sb,
void ext4_free_inodes_set(struct super_block *sb,
struct ext4_group_desc *bg, __u32 count)
{
- bg->bg_free_inodes_count_lo = cpu_to_le16((__u16)count);
+ WRITE_ONCE(bg->bg_free_inodes_count_lo, cpu_to_le16((__u16)count));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
bg->bg_free_inodes_count_hi = cpu_to_le16(count >> 16);
}
diff --git a/mm/percpu.c b/mm/percpu.c
index 20d91af8c033..5c958a54da51 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -1864,7 +1864,6 @@ void __percpu *pcpu_alloc_noprof(size_t size, size_t align, bool reserved,
area_found:
pcpu_stats_area_alloc(chunk, size);
- spin_unlock_irqrestore(&pcpu_lock, flags);
/* populate if not all pages are already there */
if (!is_atomic) {
@@ -1878,14 +1877,12 @@ void __percpu *pcpu_alloc_noprof(size_t size, size_t align, bool reserved,
ret = pcpu_populate_chunk(chunk, rs, re, pcpu_gfp);
- spin_lock_irqsave(&pcpu_lock, flags);
if (ret) {
pcpu_free_area(chunk, off);
err = "failed to populate";
goto fail_unlock;
}
pcpu_chunk_populated(chunk, rs, re);
- spin_unlock_irqrestore(&pcpu_lock, flags);
}
mutex_unlock(&pcpu_alloc_mutex);
@@ -1894,6 +1891,8 @@ void __percpu *pcpu_alloc_noprof(size_t size, size_t align, bool reserved,
if (pcpu_nr_empty_pop_pages < PCPU_EMPTY_POP_PAGES_LOW)
pcpu_schedule_balance_work();
+ spin_unlock_irqrestore(&pcpu_lock, flags);
+
/* clear the areas and return address relative to base address */
for_each_possible_cpu(cpu)
memset((void *)pcpu_chunk_addr(chunk, cpu, 0) + off, 0, size);
diff --git a/mm/shmem.c b/mm/shmem.c
index 5a77acf6ac6a..1595f6e7688c 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1154,7 +1154,9 @@ static int shmem_getattr(struct mnt_idmap *idmap,
stat->attributes_mask |= (STATX_ATTR_APPEND |
STATX_ATTR_IMMUTABLE |
STATX_ATTR_NODUMP);
+ inode_lock_shared(inode);
generic_fillattr(idmap, request_mask, inode, stat);
+ inode_unlock_shared(inode);
if (shmem_is_huge(inode, 0, false, NULL, 0))
stat->blksize = HPAGE_PMD_SIZE;
@@ -3439,7 +3441,7 @@ shmem_mknod(struct mnt_idmap *idmap, struct inode *dir,
if (error)
goto out_iput;
- dir->i_size += BOGO_DIRENT_SIZE;
+ i_size_write(dir, i_size_read(dir) + BOGO_DIRENT_SIZE);
inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
inode_inc_iversion(dir);
d_instantiate(dentry, inode);
@@ -3526,7 +3528,7 @@ static int shmem_link(struct dentry *old_dentry, struct inode *dir,
goto out;
}
- dir->i_size += BOGO_DIRENT_SIZE;
+ i_size_write(dir, i_size_read(dir) + BOGO_DIRENT_SIZE);
inode_set_mtime_to_ts(dir,
inode_set_ctime_to_ts(dir, inode_set_ctime_current(inode)));
inode_inc_iversion(dir);
@@ -3639,8 +3641,8 @@ static int shmem_rename2(struct mnt_idmap *idmap,
inc_nlink(new_dir);
}
- old_dir->i_size -= BOGO_DIRENT_SIZE;
- new_dir->i_size += BOGO_DIRENT_SIZE;
+ i_size_write(old_dir, i_size_read(old_dir) - BOGO_DIRENT_SIZE);
+ i_size_write(new_dir, i_size_read(new_dir) + BOGO_DIRENT_SIZE);
simple_rename_timestamp(old_dir, old_dentry, new_dir, new_dentry);
inode_inc_iversion(old_dir);
inode_inc_iversion(new_dir);
@@ -3694,7 +3696,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,
folio_unlock(folio);
folio_put(folio);
}
- dir->i_size += BOGO_DIRENT_SIZE;
+ i_size_write(dir, i_size_read(dir) + BOGO_DIRENT_SIZE);
inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
inode_inc_iversion(dir);
d_instantiate(dentry, inode);
--
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2024-09-08 11:33 Jeongjun Park
@ 2024-09-08 11:49 ` syzbot
0 siblings, 0 replies; 30+ messages in thread
From: syzbot @ 2024-09-08 11:49 UTC (permalink / raw)
To: aha310510, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Reported-by: syzbot+702361cf7e3d95758761@syzkaller.appspotmail.com
Tested-by: syzbot+702361cf7e3d95758761@syzkaller.appspotmail.com
Tested on:
commit: d1f2d51b Merge tag 'clk-fixes-for-linus' of git://git...
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=158e589f980000
kernel config: https://syzkaller.appspot.com/x/.config?x=e81d40b0108ea8fe
dashboard link: https://syzkaller.appspot.com/bug?extid=702361cf7e3d95758761
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=12b6589f980000
Note: testing is done by a robot and is best-effort only.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2024-09-08 11:33 [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2) Jeongjun Park
@ 2024-09-08 12:08 ` syzbot
0 siblings, 0 replies; 30+ messages in thread
From: syzbot @ 2024-09-08 12:08 UTC (permalink / raw)
To: aha310510, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Reported-by: syzbot+702361cf7e3d95758761@syzkaller.appspotmail.com
Tested-by: syzbot+702361cf7e3d95758761@syzkaller.appspotmail.com
Tested on:
commit: d1f2d51b Merge tag 'clk-fixes-for-linus' of git://git...
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=149e589f980000
kernel config: https://syzkaller.appspot.com/x/.config?x=e81d40b0108ea8fe
dashboard link: https://syzkaller.appspot.com/bug?extid=702361cf7e3d95758761
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=16b6589f980000
Note: testing is done by a robot and is best-effort only.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2023-04-24 7:58 syzbot
2023-04-24 8:26 ` Dmitry Vyukov
2024-01-12 12:15 ` syzbot
@ 2024-09-18 4:03 ` Jeongjun Park
2024-09-18 4:58 ` syzbot
2024-09-18 6:26 ` Jeongjun Park
` (4 subsequent siblings)
7 siblings, 1 reply; 30+ messages in thread
From: Jeongjun Park @ 2024-09-18 4:03 UTC (permalink / raw)
To: syzbot+702361cf7e3d95758761; +Cc: linux-kernel, syzkaller-bugs
#syz test git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
---
fs/ext4/super.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index e72145c4ae5a..466aece8518f 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -338,7 +338,7 @@ ext4_fsblk_t ext4_inode_table(struct super_block *sb,
__u32 ext4_free_group_clusters(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le16_to_cpu(bg->bg_free_blocks_count_lo) |
+ return le16_to_cpu(READ_ONCE(bg->bg_free_blocks_count_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
(__u32)le16_to_cpu(bg->bg_free_blocks_count_hi) << 16 : 0);
}
@@ -394,7 +394,7 @@ void ext4_inode_table_set(struct super_block *sb,
void ext4_free_group_clusters_set(struct super_block *sb,
struct ext4_group_desc *bg, __u32 count)
{
- bg->bg_free_blocks_count_lo = cpu_to_le16((__u16)count);
+ WRITE_ONCE(bg->bg_free_blocks_count_lo, cpu_to_le16((__u16)count));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
bg->bg_free_blocks_count_hi = cpu_to_le16(count >> 16);
}
--
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2024-09-18 4:03 ` Jeongjun Park
@ 2024-09-18 4:58 ` syzbot
0 siblings, 0 replies; 30+ messages in thread
From: syzbot @ 2024-09-18 4:58 UTC (permalink / raw)
To: aha310510, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KCSAN: data-race in ext4_free_inodes_count / ext4_free_inodes_set
==================================================================
BUG: KCSAN: data-race in ext4_free_inodes_count / ext4_free_inodes_set
write to 0xffff88810404300e of 2 bytes by task 6254 on cpu 1:
ext4_free_inodes_set+0x1f/0x80 fs/ext4/super.c:405
__ext4_new_inode+0x15ca/0x2200 fs/ext4/ialloc.c:1216
ext4_symlink+0x242/0x5a0 fs/ext4/namei.c:3391
vfs_symlink+0xca/0x1d0 fs/namei.c:4615
do_symlinkat+0xe3/0x340 fs/namei.c:4641
__do_sys_symlinkat fs/namei.c:4657 [inline]
__se_sys_symlinkat fs/namei.c:4654 [inline]
__x64_sys_symlinkat+0x5e/0x70 fs/namei.c:4654
x64_sys_call+0x1dda/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:267
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x76/0x7e
read to 0xffff88810404300e of 2 bytes by task 6257 on cpu 0:
ext4_free_inodes_count+0x1c/0x80 fs/ext4/super.c:349
find_group_other fs/ext4/ialloc.c:594 [inline]
__ext4_new_inode+0x6ec/0x2200 fs/ext4/ialloc.c:1017
ext4_symlink+0x242/0x5a0 fs/ext4/namei.c:3391
vfs_symlink+0xca/0x1d0 fs/namei.c:4615
do_symlinkat+0xe3/0x340 fs/namei.c:4641
__do_sys_symlinkat fs/namei.c:4657 [inline]
__se_sys_symlinkat fs/namei.c:4654 [inline]
__x64_sys_symlinkat+0x5e/0x70 fs/namei.c:4654
x64_sys_call+0x1dda/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:267
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x76/0x7e
value changed: 0x185c -> 0x185b
Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 6257 Comm: syz-executor.4 Not tainted 6.11.0-syzkaller-04557-g2f27fce67173-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
==================================================================
Tested on:
commit: 2f27fce6 Merge tag 'sound-6.12-rc1' of git://git.kerne..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=138f469f980000
kernel config: https://syzkaller.appspot.com/x/.config?x=dac6637d61966e53
dashboard link: https://syzkaller.appspot.com/bug?extid=702361cf7e3d95758761
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=16bc9207980000
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2023-04-24 7:58 syzbot
` (2 preceding siblings ...)
2024-09-18 4:03 ` Jeongjun Park
@ 2024-09-18 6:26 ` Jeongjun Park
2024-09-18 6:31 ` syzbot
2024-09-18 6:41 ` Jeongjun Park
` (3 subsequent siblings)
7 siblings, 1 reply; 30+ messages in thread
From: Jeongjun Park @ 2024-09-18 6:26 UTC (permalink / raw)
To: syzbot+702361cf7e3d95758761; +Cc: linux-kernel, syzkaller-bugs
#syz test git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
---
fs/ext4/super.c | 56 ++++++++++++++++++++++++-------------------------
1 file changed, 28 insertions(+), 28 deletions(-)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index e72145c4ae5a..af78b6271e4c 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -314,113 +314,113 @@ void ext4_superblock_csum_set(struct super_block *sb)
ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le32_to_cpu(bg->bg_block_bitmap_lo) |
+ return READ_ONCE(le32_to_cpu(bg->bg_block_bitmap_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
- (ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi) << 32 : 0);
+ READ_ONCE((ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi)) << 32 : 0);
}
ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le32_to_cpu(bg->bg_inode_bitmap_lo) |
+ return READ_ONCE(le32_to_cpu(bg->bg_inode_bitmap_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
- (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0);
+ READ_ONCE((ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi)) << 32 : 0);
}
ext4_fsblk_t ext4_inode_table(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le32_to_cpu(bg->bg_inode_table_lo) |
+ return READ_ONCE(le32_to_cpu(bg->bg_inode_table_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
- (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0);
+ READ_ONCE((ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi)) << 32 : 0);
}
__u32 ext4_free_group_clusters(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le16_to_cpu(bg->bg_free_blocks_count_lo) |
+ return READ_ONCE(le16_to_cpu(bg->bg_free_blocks_count_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
- (__u32)le16_to_cpu(bg->bg_free_blocks_count_hi) << 16 : 0);
+ READ_ONCE((__u32)le16_to_cpu(bg->bg_free_blocks_count_hi)) << 16 : 0);
}
__u32 ext4_free_inodes_count(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le16_to_cpu(bg->bg_free_inodes_count_lo) |
+ return READ_ONCE(le16_to_cpu(bg->bg_free_inodes_count_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
- (__u32)le16_to_cpu(bg->bg_free_inodes_count_hi) << 16 : 0);
+ READ_ONCE((__u32)le16_to_cpu(bg->bg_free_inodes_count_hi)) << 16 : 0);
}
__u32 ext4_used_dirs_count(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le16_to_cpu(bg->bg_used_dirs_count_lo) |
+ return READ_ONCE(le16_to_cpu(bg->bg_used_dirs_count_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
- (__u32)le16_to_cpu(bg->bg_used_dirs_count_hi) << 16 : 0);
+ READ_ONCE((__u32)le16_to_cpu(bg->bg_used_dirs_count_hi)) << 16 : 0);
}
__u32 ext4_itable_unused_count(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le16_to_cpu(bg->bg_itable_unused_lo) |
+ return READ_ONCE(le16_to_cpu(bg->bg_itable_unused_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
- (__u32)le16_to_cpu(bg->bg_itable_unused_hi) << 16 : 0);
+ READ_ONCE((__u32)le16_to_cpu(bg->bg_itable_unused_hi)) << 16 : 0);
}
void ext4_block_bitmap_set(struct super_block *sb,
struct ext4_group_desc *bg, ext4_fsblk_t blk)
{
- bg->bg_block_bitmap_lo = cpu_to_le32((u32)blk);
+ WRITE_ONCE(bg->bg_block_bitmap_lo, cpu_to_le32((u32)blk));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
- bg->bg_block_bitmap_hi = cpu_to_le32(blk >> 32);
+ WRITE_ONCE(bg->bg_block_bitmap_hi, cpu_to_le32(blk >> 32));
}
void ext4_inode_bitmap_set(struct super_block *sb,
struct ext4_group_desc *bg, ext4_fsblk_t blk)
{
- bg->bg_inode_bitmap_lo = cpu_to_le32((u32)blk);
+ WRITE_ONCE(bg->bg_inode_bitmap_lo, cpu_to_le32((u32)blk));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
- bg->bg_inode_bitmap_hi = cpu_to_le32(blk >> 32);
+ WRITE_ONCE(bg->bg_inode_bitmap_hi, cpu_to_le32(blk >> 32));
}
void ext4_inode_table_set(struct super_block *sb,
struct ext4_group_desc *bg, ext4_fsblk_t blk)
{
- bg->bg_inode_table_lo = cpu_to_le32((u32)blk);
+ WRITE_ONCE(bg->bg_inode_table_lo, cpu_to_le32((u32)blk));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
- bg->bg_inode_table_hi = cpu_to_le32(blk >> 32);
+ WRITE_ONCE(bg->bg_inode_table_hi, cpu_to_le32(blk >> 32));
}
void ext4_free_group_clusters_set(struct super_block *sb,
struct ext4_group_desc *bg, __u32 count)
{
- bg->bg_free_blocks_count_lo = cpu_to_le16((__u16)count);
+ WRITE_ONCE(bg->bg_free_blocks_count_lo, cpu_to_le16((__u16)count));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
- bg->bg_free_blocks_count_hi = cpu_to_le16(count >> 16);
+ WRITE_ONCE(bg->bg_free_blocks_count_hi, cpu_to_le16(count >> 16));
}
void ext4_free_inodes_set(struct super_block *sb,
struct ext4_group_desc *bg, __u32 count)
{
- bg->bg_free_inodes_count_lo = cpu_to_le16((__u16)count);
+ WRITE_ONCE(bg->bg_free_inodes_count_lo, cpu_to_le16((__u16)count));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
- bg->bg_free_inodes_count_hi = cpu_to_le16(count >> 16);
+ WRITE_ONCE(bg->bg_free_inodes_count_hi, cpu_to_le16(count >> 16));
}
void ext4_used_dirs_set(struct super_block *sb,
struct ext4_group_desc *bg, __u32 count)
{
- bg->bg_used_dirs_count_lo = cpu_to_le16((__u16)count);
+ WRITE_ONCE(bg->bg_used_dirs_count_lo, cpu_to_le16((__u16)count));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
- bg->bg_used_dirs_count_hi = cpu_to_le16(count >> 16);
+ WRITE_ONCE(bg->bg_used_dirs_count_hi, cpu_to_le16(count >> 16));
}
void ext4_itable_unused_set(struct super_block *sb,
struct ext4_group_desc *bg, __u32 count)
{
- bg->bg_itable_unused_lo = cpu_to_le16((__u16)count);
+ WRITE_ONCE(bg->bg_itable_unused_lo, cpu_to_le16((__u16)count));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
- bg->bg_itable_unused_hi = cpu_to_le16(count >> 16);
+ WRITE_ONCE(bg->bg_itable_unused_hi, cpu_to_le16(count >> 16));
}
static void __ext4_update_tstamp(__le32 *lo, __u8 *hi, time64_t now)
--
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2024-09-18 6:26 ` Jeongjun Park
@ 2024-09-18 6:31 ` syzbot
0 siblings, 0 replies; 30+ messages in thread
From: syzbot @ 2024-09-18 6:31 UTC (permalink / raw)
To: aha310510, linux-kernel, syzkaller-bugs
Hello,
syzbot tried to test the proposed patch but the build/boot failed:
fs/ext4/super.c:317:9: error: cannot take the address of an rvalue of type '__u32' (aka 'unsigned int')
fs/ext4/super.c:319:4: error: cannot take the address of an rvalue of type 'ext4_fsblk_t' (aka 'unsigned long long')
fs/ext4/super.c:325:9: error: cannot take the address of an rvalue of type '__u32' (aka 'unsigned int')
fs/ext4/super.c:327:4: error: cannot take the address of an rvalue of type 'ext4_fsblk_t' (aka 'unsigned long long')
fs/ext4/super.c:333:9: error: cannot take the address of an rvalue of type '__u32' (aka 'unsigned int')
fs/ext4/super.c:335:4: error: cannot take the address of an rvalue of type 'ext4_fsblk_t' (aka 'unsigned long long')
fs/ext4/super.c:341:9: error: cannot take the address of an rvalue of type '__u16' (aka 'unsigned short')
fs/ext4/super.c:343:4: error: cannot take the address of an rvalue of type '__u32' (aka 'unsigned int')
fs/ext4/super.c:349:9: error: cannot take the address of an rvalue of type '__u16' (aka 'unsigned short')
fs/ext4/super.c:351:4: error: cannot take the address of an rvalue of type '__u32' (aka 'unsigned int')
fs/ext4/super.c:357:9: error: cannot take the address of an rvalue of type '__u16' (aka 'unsigned short')
fs/ext4/super.c:359:4: error: cannot take the address of an rvalue of type '__u32' (aka 'unsigned int')
fs/ext4/super.c:365:9: error: cannot take the address of an rvalue of type '__u16' (aka 'unsigned short')
fs/ext4/super.c:367:4: error: cannot take the address of an rvalue of type '__u32' (aka 'unsigned int')
Tested on:
commit: 2f27fce6 Merge tag 'sound-6.12-rc1' of git://git.kerne..
git tree: upstream
kernel config: https://syzkaller.appspot.com/x/.config?x=31b069fcee8f481d
dashboard link: https://syzkaller.appspot.com/bug?extid=702361cf7e3d95758761
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=10fc7500580000
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2023-04-24 7:58 syzbot
` (3 preceding siblings ...)
2024-09-18 6:26 ` Jeongjun Park
@ 2024-09-18 6:41 ` Jeongjun Park
2024-09-18 7:37 ` syzbot
2024-09-18 7:46 ` Jeongjun Park
` (2 subsequent siblings)
7 siblings, 1 reply; 30+ messages in thread
From: Jeongjun Park @ 2024-09-18 6:41 UTC (permalink / raw)
To: syzbot+702361cf7e3d95758761; +Cc: linux-kernel, syzkaller-bugs
#syz test git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
---
fs/ext4/super.c | 56 ++++++++++++++++++++++++-------------------------
1 file changed, 28 insertions(+), 28 deletions(-)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index e72145c4ae5a..8cfd43c33480 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -314,113 +314,113 @@ void ext4_superblock_csum_set(struct super_block *sb)
ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le32_to_cpu(bg->bg_block_bitmap_lo) |
+ return le32_to_cpu(READ_ONCE(bg->bg_block_bitmap_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
- (ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi) << 32 : 0);
+ READ_ONCE((ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi)) << 32 : 0);
}
ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le32_to_cpu(bg->bg_inode_bitmap_lo) |
+ return le32_to_cpu(READ_ONCE(bg->bg_inode_bitmap_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
- (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0);
+ READ_ONCE((ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi)) << 32 : 0);
}
ext4_fsblk_t ext4_inode_table(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le32_to_cpu(bg->bg_inode_table_lo) |
+ return le32_to_cpu(READ_ONCE(bg->bg_inode_table_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
- (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0);
+ READ_ONCE((ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi)) << 32 : 0);
}
__u32 ext4_free_group_clusters(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le16_to_cpu(bg->bg_free_blocks_count_lo) |
+ return le16_to_cpu(READ_ONCE(bg->bg_free_blocks_count_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
- (__u32)le16_to_cpu(bg->bg_free_blocks_count_hi) << 16 : 0);
+ READ_ONCE((__u32)le16_to_cpu(bg->bg_free_blocks_count_hi)) << 16 : 0);
}
__u32 ext4_free_inodes_count(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le16_to_cpu(bg->bg_free_inodes_count_lo) |
+ return le16_to_cpu(READ_ONCE(bg->bg_free_inodes_count_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
- (__u32)le16_to_cpu(bg->bg_free_inodes_count_hi) << 16 : 0);
+ READ_ONCE((__u32)le16_to_cpu(bg->bg_free_inodes_count_hi)) << 16 : 0);
}
__u32 ext4_used_dirs_count(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le16_to_cpu(bg->bg_used_dirs_count_lo) |
+ return le16_to_cpu(READ_ONCE(bg->bg_used_dirs_count_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
- (__u32)le16_to_cpu(bg->bg_used_dirs_count_hi) << 16 : 0);
+ READ_ONCE((__u32)le16_to_cpu(bg->bg_used_dirs_count_hi)) << 16 : 0);
}
__u32 ext4_itable_unused_count(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le16_to_cpu(bg->bg_itable_unused_lo) |
+ return le16_to_cpu(READ_ONCE(bg->bg_itable_unused_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
- (__u32)le16_to_cpu(bg->bg_itable_unused_hi) << 16 : 0);
+ READ_ONCE((__u32)le16_to_cpu(bg->bg_itable_unused_hi)) << 16 : 0);
}
void ext4_block_bitmap_set(struct super_block *sb,
struct ext4_group_desc *bg, ext4_fsblk_t blk)
{
- bg->bg_block_bitmap_lo = cpu_to_le32((u32)blk);
+ WRITE_ONCE(bg->bg_block_bitmap_lo, cpu_to_le32((u32)blk));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
- bg->bg_block_bitmap_hi = cpu_to_le32(blk >> 32);
+ WRITE_ONCE(bg->bg_block_bitmap_hi, cpu_to_le32(blk >> 32));
}
void ext4_inode_bitmap_set(struct super_block *sb,
struct ext4_group_desc *bg, ext4_fsblk_t blk)
{
- bg->bg_inode_bitmap_lo = cpu_to_le32((u32)blk);
+ WRITE_ONCE(bg->bg_inode_bitmap_lo, cpu_to_le32((u32)blk));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
- bg->bg_inode_bitmap_hi = cpu_to_le32(blk >> 32);
+ WRITE_ONCE(bg->bg_inode_bitmap_hi, cpu_to_le32(blk >> 32));
}
void ext4_inode_table_set(struct super_block *sb,
struct ext4_group_desc *bg, ext4_fsblk_t blk)
{
- bg->bg_inode_table_lo = cpu_to_le32((u32)blk);
+ WRITE_ONCE(bg->bg_inode_table_lo, cpu_to_le32((u32)blk));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
- bg->bg_inode_table_hi = cpu_to_le32(blk >> 32);
+ WRITE_ONCE(bg->bg_inode_table_hi, cpu_to_le32(blk >> 32));
}
void ext4_free_group_clusters_set(struct super_block *sb,
struct ext4_group_desc *bg, __u32 count)
{
- bg->bg_free_blocks_count_lo = cpu_to_le16((__u16)count);
+ WRITE_ONCE(bg->bg_free_blocks_count_lo, cpu_to_le16((__u16)count));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
- bg->bg_free_blocks_count_hi = cpu_to_le16(count >> 16);
+ WRITE_ONCE(bg->bg_free_blocks_count_hi, cpu_to_le16(count >> 16));
}
void ext4_free_inodes_set(struct super_block *sb,
struct ext4_group_desc *bg, __u32 count)
{
- bg->bg_free_inodes_count_lo = cpu_to_le16((__u16)count);
+ WRITE_ONCE(bg->bg_free_inodes_count_lo, cpu_to_le16((__u16)count));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
- bg->bg_free_inodes_count_hi = cpu_to_le16(count >> 16);
+ WRITE_ONCE(bg->bg_free_inodes_count_hi, cpu_to_le16(count >> 16));
}
void ext4_used_dirs_set(struct super_block *sb,
struct ext4_group_desc *bg, __u32 count)
{
- bg->bg_used_dirs_count_lo = cpu_to_le16((__u16)count);
+ WRITE_ONCE(bg->bg_used_dirs_count_lo, cpu_to_le16((__u16)count));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
- bg->bg_used_dirs_count_hi = cpu_to_le16(count >> 16);
+ WRITE_ONCE(bg->bg_used_dirs_count_hi, cpu_to_le16(count >> 16));
}
void ext4_itable_unused_set(struct super_block *sb,
struct ext4_group_desc *bg, __u32 count)
{
- bg->bg_itable_unused_lo = cpu_to_le16((__u16)count);
+ WRITE_ONCE(bg->bg_itable_unused_lo, cpu_to_le16((__u16)count));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
- bg->bg_itable_unused_hi = cpu_to_le16(count >> 16);
+ WRITE_ONCE(bg->bg_itable_unused_hi, cpu_to_le16(count >> 16));
}
static void __ext4_update_tstamp(__le32 *lo, __u8 *hi, time64_t now)
--
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2024-09-18 6:41 ` Jeongjun Park
@ 2024-09-18 7:37 ` syzbot
0 siblings, 0 replies; 30+ messages in thread
From: syzbot @ 2024-09-18 7:37 UTC (permalink / raw)
To: aha310510, linux-kernel, syzkaller-bugs
Hello,
syzbot tried to test the proposed patch but the build/boot failed:
fs/ext4/super.c:319:4: error: cannot take the address of an rvalue of type 'ext4_fsblk_t' (aka 'unsigned long long')
fs/ext4/super.c:327:4: error: cannot take the address of an rvalue of type 'ext4_fsblk_t' (aka 'unsigned long long')
fs/ext4/super.c:335:4: error: cannot take the address of an rvalue of type 'ext4_fsblk_t' (aka 'unsigned long long')
fs/ext4/super.c:343:4: error: cannot take the address of an rvalue of type '__u32' (aka 'unsigned int')
fs/ext4/super.c:351:4: error: cannot take the address of an rvalue of type '__u32' (aka 'unsigned int')
fs/ext4/super.c:359:4: error: cannot take the address of an rvalue of type '__u32' (aka 'unsigned int')
fs/ext4/super.c:367:4: error: cannot take the address of an rvalue of type '__u32' (aka 'unsigned int')
Tested on:
commit: 2f27fce6 Merge tag 'sound-6.12-rc1' of git://git.kerne..
git tree: upstream
kernel config: https://syzkaller.appspot.com/x/.config?x=31b069fcee8f481d
dashboard link: https://syzkaller.appspot.com/bug?extid=702361cf7e3d95758761
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=1084c69f980000
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2023-04-24 7:58 syzbot
` (4 preceding siblings ...)
2024-09-18 6:41 ` Jeongjun Park
@ 2024-09-18 7:46 ` Jeongjun Park
2024-09-18 7:58 ` syzbot
2024-09-20 14:27 ` Jeongjun Park
2024-09-20 14:33 ` Jeongjun Park
7 siblings, 1 reply; 30+ messages in thread
From: Jeongjun Park @ 2024-09-18 7:46 UTC (permalink / raw)
To: syzbot+702361cf7e3d95758761; +Cc: linux-kernel, syzkaller-bugs
#syz test git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
---
fs/ext4/super.c | 56 ++++++++++++++++++++++++-------------------------
1 file changed, 28 insertions(+), 28 deletions(-)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index e72145c4ae5a..9c918cf2eb7e 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -314,113 +314,113 @@ void ext4_superblock_csum_set(struct super_block *sb)
ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le32_to_cpu(bg->bg_block_bitmap_lo) |
+ return le32_to_cpu(READ_ONCE(bg->bg_block_bitmap_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
- (ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi) << 32 : 0);
+ (ext4_fsblk_t)le32_to_cpu(READ_ONCE(bg->bg_block_bitmap_hi)) << 32 : 0);
}
ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le32_to_cpu(bg->bg_inode_bitmap_lo) |
+ return le32_to_cpu(READ_ONCE(bg->bg_inode_bitmap_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
- (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0);
+ (ext4_fsblk_t)le32_to_cpu(READ_ONCE(bg->bg_inode_bitmap_hi)) << 32 : 0);
}
ext4_fsblk_t ext4_inode_table(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le32_to_cpu(bg->bg_inode_table_lo) |
+ return le32_to_cpu(READ_ONCE(bg->bg_inode_table_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
- (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0);
+ (ext4_fsblk_t)le32_to_cpu(READ_ONCE(bg->bg_inode_table_hi)) << 32 : 0);
}
__u32 ext4_free_group_clusters(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le16_to_cpu(bg->bg_free_blocks_count_lo) |
+ return le16_to_cpu(READ_ONCE(bg->bg_free_blocks_count_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
- (__u32)le16_to_cpu(bg->bg_free_blocks_count_hi) << 16 : 0);
+ (__u32)le16_to_cpu(READ_ONCE(bg->bg_free_blocks_count_hi)) << 16 : 0);
}
__u32 ext4_free_inodes_count(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le16_to_cpu(bg->bg_free_inodes_count_lo) |
+ return le16_to_cpu(READ_ONCE(bg->bg_free_inodes_count_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
- (__u32)le16_to_cpu(bg->bg_free_inodes_count_hi) << 16 : 0);
+ (__u32)le16_to_cpu(READ_ONCE(bg->bg_free_inodes_count_hi)) << 16 : 0);
}
__u32 ext4_used_dirs_count(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le16_to_cpu(bg->bg_used_dirs_count_lo) |
+ return le16_to_cpu(READ_ONCE(bg->bg_used_dirs_count_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
- (__u32)le16_to_cpu(bg->bg_used_dirs_count_hi) << 16 : 0);
+ (__u32)le16_to_cpu(READ_ONCE(bg->bg_used_dirs_count_hi)) << 16 : 0);
}
__u32 ext4_itable_unused_count(struct super_block *sb,
struct ext4_group_desc *bg)
{
- return le16_to_cpu(bg->bg_itable_unused_lo) |
+ return le16_to_cpu(READ_ONCE(bg->bg_itable_unused_lo)) |
(EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
- (__u32)le16_to_cpu(bg->bg_itable_unused_hi) << 16 : 0);
+ (__u32)le16_to_cpu(READ_ONCE(bg->bg_itable_unused_hi)) << 16 : 0);
}
void ext4_block_bitmap_set(struct super_block *sb,
struct ext4_group_desc *bg, ext4_fsblk_t blk)
{
- bg->bg_block_bitmap_lo = cpu_to_le32((u32)blk);
+ WRITE_ONCE(bg->bg_block_bitmap_lo, cpu_to_le32((u32)blk));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
- bg->bg_block_bitmap_hi = cpu_to_le32(blk >> 32);
+ WRITE_ONCE(bg->bg_block_bitmap_hi, cpu_to_le32(blk >> 32));
}
void ext4_inode_bitmap_set(struct super_block *sb,
struct ext4_group_desc *bg, ext4_fsblk_t blk)
{
- bg->bg_inode_bitmap_lo = cpu_to_le32((u32)blk);
+ WRITE_ONCE(bg->bg_inode_bitmap_lo, cpu_to_le32((u32)blk));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
- bg->bg_inode_bitmap_hi = cpu_to_le32(blk >> 32);
+ WRITE_ONCE(bg->bg_inode_bitmap_hi, cpu_to_le32(blk >> 32));
}
void ext4_inode_table_set(struct super_block *sb,
struct ext4_group_desc *bg, ext4_fsblk_t blk)
{
- bg->bg_inode_table_lo = cpu_to_le32((u32)blk);
+ WRITE_ONCE(bg->bg_inode_table_lo, cpu_to_le32((u32)blk));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
- bg->bg_inode_table_hi = cpu_to_le32(blk >> 32);
+ WRITE_ONCE(bg->bg_inode_table_hi, cpu_to_le32(blk >> 32));
}
void ext4_free_group_clusters_set(struct super_block *sb,
struct ext4_group_desc *bg, __u32 count)
{
- bg->bg_free_blocks_count_lo = cpu_to_le16((__u16)count);
+ WRITE_ONCE(bg->bg_free_blocks_count_lo, cpu_to_le16((__u16)count));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
- bg->bg_free_blocks_count_hi = cpu_to_le16(count >> 16);
+ WRITE_ONCE(bg->bg_free_blocks_count_hi, cpu_to_le16(count >> 16));
}
void ext4_free_inodes_set(struct super_block *sb,
struct ext4_group_desc *bg, __u32 count)
{
- bg->bg_free_inodes_count_lo = cpu_to_le16((__u16)count);
+ WRITE_ONCE(bg->bg_free_inodes_count_lo, cpu_to_le16((__u16)count));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
- bg->bg_free_inodes_count_hi = cpu_to_le16(count >> 16);
+ WRITE_ONCE(bg->bg_free_inodes_count_hi, cpu_to_le16(count >> 16));
}
void ext4_used_dirs_set(struct super_block *sb,
struct ext4_group_desc *bg, __u32 count)
{
- bg->bg_used_dirs_count_lo = cpu_to_le16((__u16)count);
+ WRITE_ONCE(bg->bg_used_dirs_count_lo, cpu_to_le16((__u16)count));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
- bg->bg_used_dirs_count_hi = cpu_to_le16(count >> 16);
+ WRITE_ONCE(bg->bg_used_dirs_count_hi, cpu_to_le16(count >> 16));
}
void ext4_itable_unused_set(struct super_block *sb,
struct ext4_group_desc *bg, __u32 count)
{
- bg->bg_itable_unused_lo = cpu_to_le16((__u16)count);
+ WRITE_ONCE(bg->bg_itable_unused_lo, cpu_to_le16((__u16)count));
if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
- bg->bg_itable_unused_hi = cpu_to_le16(count >> 16);
+ WRITE_ONCE(bg->bg_itable_unused_hi, cpu_to_le16(count >> 16));
}
static void __ext4_update_tstamp(__le32 *lo, __u8 *hi, time64_t now)
--
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2024-09-18 7:46 ` Jeongjun Park
@ 2024-09-18 7:58 ` syzbot
0 siblings, 0 replies; 30+ messages in thread
From: syzbot @ 2024-09-18 7:58 UTC (permalink / raw)
To: aha310510, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KCSAN: data-race in ext4_mb_regular_allocator / mb_mark_used
==================================================================
BUG: KCSAN: data-race in ext4_mb_regular_allocator / mb_mark_used
read-write to 0xffff888100696014 of 4 bytes by task 3404 on cpu 0:
mb_mark_used+0x128/0xb40 fs/ext4/mballoc.c:2065
ext4_mb_use_best_found+0xf6/0x2a0 fs/ext4/mballoc.c:2147
ext4_mb_check_limits fs/ext4/mballoc.c:2211 [inline]
ext4_mb_complex_scan_group+0x7a7/0x800 fs/ext4/mballoc.c:2527
ext4_mb_regular_allocator+0x10d4/0x2590 fs/ext4/mballoc.c:2941
ext4_mb_new_blocks+0x801/0x2020 fs/ext4/mballoc.c:6219
ext4_ext_map_blocks+0x1070/0x3640 fs/ext4/extents.c:4318
ext4_map_blocks+0x72a/0xf50 fs/ext4/inode.c:652
ext4_getblk+0x112/0x500 fs/ext4/inode.c:862
ext4_bread+0x2c/0x110 fs/ext4/inode.c:918
ext4_append+0x164/0x2a0 fs/ext4/namei.c:83
ext4_init_new_dir+0x17b/0x510 fs/ext4/namei.c:2979
ext4_mkdir+0x313/0x740 fs/ext4/namei.c:3025
vfs_mkdir+0x1f4/0x320 fs/namei.c:4257
do_mkdirat+0x12f/0x2a0 fs/namei.c:4280
__do_sys_mkdirat fs/namei.c:4295 [inline]
__se_sys_mkdirat fs/namei.c:4293 [inline]
__x64_sys_mkdirat+0x4e/0x60 fs/namei.c:4293
x64_sys_call+0x2cd3/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:259
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x76/0x7e
read to 0xffff888100696014 of 4 bytes by task 3444 on cpu 1:
ext4_mb_good_group_nolock fs/ext4/mballoc.c:2666 [inline]
ext4_mb_regular_allocator+0x948/0x2590 fs/ext4/mballoc.c:2903
ext4_mb_new_blocks+0x801/0x2020 fs/ext4/mballoc.c:6219
ext4_ext_map_blocks+0x1070/0x3640 fs/ext4/extents.c:4318
ext4_map_blocks+0x72a/0xf50 fs/ext4/inode.c:652
ext4_getblk+0x112/0x500 fs/ext4/inode.c:862
ext4_bread+0x2c/0x110 fs/ext4/inode.c:918
ext4_append+0x164/0x2a0 fs/ext4/namei.c:83
ext4_init_new_dir+0x17b/0x510 fs/ext4/namei.c:2979
ext4_mkdir+0x313/0x740 fs/ext4/namei.c:3025
vfs_mkdir+0x1f4/0x320 fs/namei.c:4257
do_mkdirat+0x12f/0x2a0 fs/namei.c:4280
__do_sys_mkdirat fs/namei.c:4295 [inline]
__se_sys_mkdirat fs/namei.c:4293 [inline]
__x64_sys_mkdirat+0x4e/0x60 fs/namei.c:4293
x64_sys_call+0x2cd3/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:259
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x76/0x7e
value changed: 0x000005ca -> 0x000005c9
Reported by Kernel Concurrency Sanitizer on:
CPU: 1 UID: 0 PID: 3444 Comm: syz-executor.5 Not tainted 6.11.0-syzkaller-04557-g2f27fce67173-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
==================================================================
Tested on:
commit: 2f27fce6 Merge tag 'sound-6.12-rc1' of git://git.kerne..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=1353bfc7980000
kernel config: https://syzkaller.appspot.com/x/.config?x=dac6637d61966e53
dashboard link: https://syzkaller.appspot.com/bug?extid=702361cf7e3d95758761
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=14fcc69f980000
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2023-04-24 7:58 syzbot
` (5 preceding siblings ...)
2024-09-18 7:46 ` Jeongjun Park
@ 2024-09-20 14:27 ` Jeongjun Park
2024-09-20 14:32 ` syzbot
2024-09-20 14:33 ` Jeongjun Park
7 siblings, 1 reply; 30+ messages in thread
From: Jeongjun Park @ 2024-09-20 14:27 UTC (permalink / raw)
To: syzbot+702361cf7e3d95758761; +Cc: linux-kernel, syzkaller-bugs
#syz test git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
---
fs/ext4/ialloc.c | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index 9dfd768ed9f8..fec01c64443a 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -500,11 +500,14 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent,
for (i = 0; i < flex_size; i++) {
if (grp+i >= real_ngroups)
break;
+ ext4_lock_group(sb, grp+i);
desc = ext4_get_group_desc(sb, grp+i, NULL);
if (desc && ext4_free_inodes_count(sb, desc)) {
*group = grp+i;
+ ext4_unlock_group(sb, grp+i);
return 0;
}
+ ext4_unlock_group(sb, grp+i);
}
goto fallback;
}
@@ -544,14 +547,17 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent,
parent_group = EXT4_I(parent)->i_block_group;
for (i = 0; i < ngroups; i++) {
grp = (parent_group + i) % ngroups;
+ ext4_lock_group(sb, grp);
desc = ext4_get_group_desc(sb, grp, NULL);
if (desc) {
grp_free = ext4_free_inodes_count(sb, desc);
if (grp_free && grp_free >= avefreei) {
*group = grp;
+ ext4_unlock_group(sb, grp);
return 0;
}
}
+ ext4_unlock_group(sb, grp);
}
if (avefreei) {
@@ -590,11 +596,14 @@ static int find_group_other(struct super_block *sb, struct inode *parent,
if (last > ngroups)
last = ngroups;
for (i = parent_group; i < last; i++) {
+ ext4_lock_group(sb, i);
desc = ext4_get_group_desc(sb, i, NULL);
if (desc && ext4_free_inodes_count(sb, desc)) {
*group = i;
+ ext4_unlock_group(sb, i);
return 0;
}
+ ext4_unlock_group(sb, i);
}
if (!retry && EXT4_I(parent)->i_last_alloc_group != ~0) {
retry = 1;
@@ -616,10 +625,14 @@ static int find_group_other(struct super_block *sb, struct inode *parent,
* Try to place the inode in its parent directory
*/
*group = parent_group;
+ ext4_lock_group(sb, &group);
desc = ext4_get_group_desc(sb, *group, NULL);
if (desc && ext4_free_inodes_count(sb, desc) &&
- ext4_free_group_clusters(sb, desc))
+ ext4_free_group_clusters(sb, desc)) {
+ ext4_unlock_group(sb, *group);
return 0;
+ }
+ ext4_unlock_group(sb, *group);
/*
* We're going to place this inode in a different blockgroup from its
@@ -640,10 +653,14 @@ static int find_group_other(struct super_block *sb, struct inode *parent,
*group += i;
if (*group >= ngroups)
*group -= ngroups;
+ ext4_lock_group(sb, *group);
desc = ext4_get_group_desc(sb, *group, NULL);
if (desc && ext4_free_inodes_count(sb, desc) &&
- ext4_free_group_clusters(sb, desc))
+ ext4_free_group_clusters(sb, desc)) {
+ ext4_unlock_group(sb, *group);
return 0;
+ }
+ ext4_unlock_group(sb, *group);
}
/*
@@ -654,9 +671,13 @@ static int find_group_other(struct super_block *sb, struct inode *parent,
for (i = 0; i < ngroups; i++) {
if (++*group >= ngroups)
*group = 0;
+ ext4_lock_group(sb, *group);
desc = ext4_get_group_desc(sb, *group, NULL);
- if (desc && ext4_free_inodes_count(sb, desc))
+ if (desc && ext4_free_inodes_count(sb, desc)) {
+ ext4_unlock_group(sb, *group);
return 0;
+ }
+ ext4_unlock_group(sb, *group);
}
return -1;
--
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2024-09-20 14:27 ` Jeongjun Park
@ 2024-09-20 14:32 ` syzbot
0 siblings, 0 replies; 30+ messages in thread
From: syzbot @ 2024-09-20 14:32 UTC (permalink / raw)
To: aha310510, linux-kernel, syzkaller-bugs
Hello,
syzbot tried to test the proposed patch but the build/boot failed:
fs/ext4/ialloc.c:628:22: error: incompatible pointer to integer conversion passing 'ext4_group_t **' (aka 'unsigned int **') to parameter of type 'ext4_group_t' (aka 'unsigned int') [-Wint-conversion]
Tested on:
commit: baeb9a7d Merge tag 'sched-rt-2024-09-17' of git://git...
git tree: upstream
kernel config: https://syzkaller.appspot.com/x/.config?x=31b069fcee8f481d
dashboard link: https://syzkaller.appspot.com/bug?extid=702361cf7e3d95758761
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=15ecae9f980000
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2023-04-24 7:58 syzbot
` (6 preceding siblings ...)
2024-09-20 14:27 ` Jeongjun Park
@ 2024-09-20 14:33 ` Jeongjun Park
2024-09-20 14:43 ` syzbot
7 siblings, 1 reply; 30+ messages in thread
From: Jeongjun Park @ 2024-09-20 14:33 UTC (permalink / raw)
To: syzbot+702361cf7e3d95758761; +Cc: linux-kernel, syzkaller-bugs
#syz test git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
---
fs/ext4/ialloc.c | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index 9dfd768ed9f8..5cae247ff21f 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -500,11 +500,14 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent,
for (i = 0; i < flex_size; i++) {
if (grp+i >= real_ngroups)
break;
+ ext4_lock_group(sb, grp+i);
desc = ext4_get_group_desc(sb, grp+i, NULL);
if (desc && ext4_free_inodes_count(sb, desc)) {
*group = grp+i;
+ ext4_unlock_group(sb, grp+i);
return 0;
}
+ ext4_unlock_group(sb, grp+i);
}
goto fallback;
}
@@ -544,14 +547,17 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent,
parent_group = EXT4_I(parent)->i_block_group;
for (i = 0; i < ngroups; i++) {
grp = (parent_group + i) % ngroups;
+ ext4_lock_group(sb, grp);
desc = ext4_get_group_desc(sb, grp, NULL);
if (desc) {
grp_free = ext4_free_inodes_count(sb, desc);
if (grp_free && grp_free >= avefreei) {
*group = grp;
+ ext4_unlock_group(sb, grp);
return 0;
}
}
+ ext4_unlock_group(sb, grp);
}
if (avefreei) {
@@ -590,11 +596,14 @@ static int find_group_other(struct super_block *sb, struct inode *parent,
if (last > ngroups)
last = ngroups;
for (i = parent_group; i < last; i++) {
+ ext4_lock_group(sb, i);
desc = ext4_get_group_desc(sb, i, NULL);
if (desc && ext4_free_inodes_count(sb, desc)) {
*group = i;
+ ext4_unlock_group(sb, i);
return 0;
}
+ ext4_unlock_group(sb, i);
}
if (!retry && EXT4_I(parent)->i_last_alloc_group != ~0) {
retry = 1;
@@ -616,10 +625,14 @@ static int find_group_other(struct super_block *sb, struct inode *parent,
* Try to place the inode in its parent directory
*/
*group = parent_group;
+ ext4_lock_group(sb, *group);
desc = ext4_get_group_desc(sb, *group, NULL);
if (desc && ext4_free_inodes_count(sb, desc) &&
- ext4_free_group_clusters(sb, desc))
+ ext4_free_group_clusters(sb, desc)) {
+ ext4_unlock_group(sb, *group);
return 0;
+ }
+ ext4_unlock_group(sb, *group);
/*
* We're going to place this inode in a different blockgroup from its
@@ -640,10 +653,14 @@ static int find_group_other(struct super_block *sb, struct inode *parent,
*group += i;
if (*group >= ngroups)
*group -= ngroups;
+ ext4_lock_group(sb, *group);
desc = ext4_get_group_desc(sb, *group, NULL);
if (desc && ext4_free_inodes_count(sb, desc) &&
- ext4_free_group_clusters(sb, desc))
+ ext4_free_group_clusters(sb, desc)) {
+ ext4_unlock_group(sb, *group);
return 0;
+ }
+ ext4_unlock_group(sb, *group);
}
/*
@@ -654,9 +671,13 @@ static int find_group_other(struct super_block *sb, struct inode *parent,
for (i = 0; i < ngroups; i++) {
if (++*group >= ngroups)
*group = 0;
+ ext4_lock_group(sb, *group);
desc = ext4_get_group_desc(sb, *group, NULL);
- if (desc && ext4_free_inodes_count(sb, desc))
+ if (desc && ext4_free_inodes_count(sb, desc)) {
+ ext4_unlock_group(sb, *group);
return 0;
+ }
+ ext4_unlock_group(sb, *group);
}
return -1;
--
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2)
2024-09-20 14:33 ` Jeongjun Park
@ 2024-09-20 14:43 ` syzbot
0 siblings, 0 replies; 30+ messages in thread
From: syzbot @ 2024-09-20 14:43 UTC (permalink / raw)
To: aha310510, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KCSAN: data-race in ext4_fill_raw_inode / ext4_orphan_del
==================================================================
BUG: KCSAN: data-race in ext4_fill_raw_inode / ext4_orphan_del
write to 0xffff8881080b3214 of 4 bytes by task 3410 on cpu 1:
ext4_orphan_del+0x550/0x6e0 fs/ext4/orphan.c:296
ext4_evict_inode+0xac3/0xdc0 fs/ext4/inode.c:289
evict+0x2f0/0x570 fs/inode.c:731
iput_final fs/inode.c:1883 [inline]
iput+0x42a/0x5b0 fs/inode.c:1909
d_delete_notify include/linux/fsnotify.h:332 [inline]
vfs_rmdir+0x29f/0x320 fs/namei.c:4353
do_rmdir+0x194/0x320 fs/namei.c:4399
__do_sys_unlinkat fs/namei.c:4575 [inline]
__se_sys_unlinkat fs/namei.c:4569 [inline]
__x64_sys_unlinkat+0xa2/0xb0 fs/namei.c:4569
x64_sys_call+0x25fd/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:264
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x76/0x7e
read to 0xffff8881080b3214 of 4 bytes by task 3404 on cpu 0:
ext4_fill_raw_inode+0x28d/0xe80 fs/ext4/inode.c:4323
ext4_do_update_inode fs/ext4/inode.c:5148 [inline]
ext4_mark_iloc_dirty+0x2e9/0xe00 fs/ext4/inode.c:5778
__ext4_mark_inode_dirty+0x314/0x440 fs/ext4/inode.c:5982
__ext4_ext_dirty fs/ext4/extents.c:202 [inline]
ext4_ext_rm_leaf fs/ext4/extents.c:2722 [inline]
ext4_ext_remove_space+0x126d/0x2c80 fs/ext4/extents.c:2934
ext4_ext_truncate+0xc4/0x150 fs/ext4/extents.c:4441
ext4_truncate+0x776/0xb10 fs/ext4/inode.c:4215
ext4_evict_inode+0x8b4/0xdc0 fs/ext4/inode.c:258
evict+0x2f0/0x570 fs/inode.c:731
iput_final fs/inode.c:1883 [inline]
iput+0x42a/0x5b0 fs/inode.c:1909
d_delete_notify include/linux/fsnotify.h:332 [inline]
vfs_rmdir+0x29f/0x320 fs/namei.c:4353
do_rmdir+0x194/0x320 fs/namei.c:4399
__do_sys_unlinkat fs/namei.c:4575 [inline]
__se_sys_unlinkat fs/namei.c:4569 [inline]
__x64_sys_unlinkat+0xa2/0xb0 fs/namei.c:4569
x64_sys_call+0x25fd/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:264
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x76/0x7e
value changed: 0x0000079c -> 0x0000078b
Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 3404 Comm: syz-executor.0 Not tainted 6.11.0-syzkaller-07341-gbaeb9a7d8b60-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
==================================================================
Tested on:
commit: baeb9a7d Merge tag 'sched-rt-2024-09-17' of git://git...
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=1642ae9f980000
kernel config: https://syzkaller.appspot.com/x/.config?x=4ca35e71cb9a0a41
dashboard link: https://syzkaller.appspot.com/bug?extid=702361cf7e3d95758761
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=143cae9f980000
^ permalink raw reply [flat|nested] 30+ messages in thread
end of thread, other threads:[~2024-09-20 14:43 UTC | newest]
Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-08 11:33 [syzbot] [mm?] KCSAN: data-race in generic_fillattr / shmem_mknod (2) Jeongjun Park
2024-09-08 12:08 ` syzbot
-- strict thread matches above, loose matches on Subject: below --
2024-09-08 11:33 Jeongjun Park
2024-09-08 11:49 ` syzbot
2024-09-08 10:27 Jeongjun Park
2024-09-08 10:44 ` [syzbot] [mm?] " syzbot
2024-09-08 8:34 Jeongjun Park
2024-09-08 9:45 ` [syzbot] [mm?] " syzbot
2024-09-08 8:16 Jeongjun Park
2024-09-08 9:31 ` [syzbot] [mm?] " syzbot
2024-09-08 7:47 Jeongjun Park
2024-09-08 8:01 ` [syzbot] [mm?] " syzbot
2024-09-08 6:27 Jeongjun Park
2024-09-08 6:59 ` [syzbot] [mm?] " syzbot
2024-09-08 6:09 Jeongjun Park
2024-09-08 6:49 ` [syzbot] [mm?] " syzbot
2024-09-08 5:23 Jeongjun Park
2024-09-08 5:39 ` [syzbot] [mm?] " syzbot
2023-04-24 7:58 syzbot
2023-04-24 8:26 ` Dmitry Vyukov
2023-05-01 5:15 ` Tetsuo Handa
2023-05-01 14:05 ` Tetsuo Handa
2023-05-02 10:13 ` Tetsuo Handa
2023-05-02 6:13 ` Dmitry Vyukov
2024-01-12 12:15 ` syzbot
2024-09-18 4:03 ` Jeongjun Park
2024-09-18 4:58 ` syzbot
2024-09-18 6:26 ` Jeongjun Park
2024-09-18 6:31 ` syzbot
2024-09-18 6:41 ` Jeongjun Park
2024-09-18 7:37 ` syzbot
2024-09-18 7:46 ` Jeongjun Park
2024-09-18 7:58 ` syzbot
2024-09-20 14:27 ` Jeongjun Park
2024-09-20 14:32 ` syzbot
2024-09-20 14:33 ` Jeongjun Park
2024-09-20 14:43 ` syzbot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox