Bug 205571 - potential data race on ext4_setattr around inode->i_mtime with ftruncate and readv
Summary: potential data race on ext4_setattr around inode->i_mtime with ftruncate and ...
Status: NEW
Alias: None
Product: File System
Classification: Unclassified
Component: ext4 (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: fs_ext4@kernel-bugs.osdl.org
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-11-18 22:23 UTC by Meng Xu
Modified: 2019-11-18 22:23 UTC (History)
0 users

See Also:
Kernel Version: 5.4-rc5
Subsystem:
Regression: No
Bisected commit-id:


Attachments

Description Meng Xu 2019-11-18 22:23:08 UTC
I am bringing up the visibility of a potential data race on ext4_setattr around inode->i_mtime when one thread is doing ftruncate and the other readv.

[Setup]
creat(file_bar, 0777, ) = 4;
dup2(4, 198) = 198;
link(file_bar, link_bar) = 0;
open(link_bar, 0x2, 0777) = 6;
dup2(6, 196) = 196;


[Thread 1] ftruncate(198, 21009);
[Thread 2] readv(196, [{iov_base=0x0x7fa652a1fa07, iov_len=1641}, ,..], 6);

The function call trace is shown below:

[Thread 1: SYS_ftruncate]
__do_sys_ftruncate
  do_sys_ftruncate
    do_truncate
      ext4_setattr
        [WRITE] inode->i_mtime = current_time(inode);

[Thread 2: SYS_readv]
__do_sys_readv
  do_readv
    vfs_readv
      do_iter_read
        do_iter_readv_writev
          call_read_iter
            ext4_file_read_iter
              generic_file_read_iter
                generic_file_buffered_read
                  file_accessed
                    atime_needs_update
                      relatime_need_update
                        [READ] if (timespec64_compare(&inode->i_mtime, &inode->i_atime) >= 0)


I could confirm that the WRITE may happen before and after the READ operation by controlling the timing of the two threads, i.e., by setting breakpoints before the WRITE statement.

However, I am not very sure about the implication of such a data race (e.g., causing violations of assumptions). I would appreciate if you could help check on this potential bug and advise whether this is a harmful data race or it
is intended. Thank you!

Note You need to log in before you can comment on or make changes to this bug.