diff options
| author | Amir Goldstein <amir73il@gmail.com> | 2022-08-16 17:53:17 +0300 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2022-10-26 12:34:58 +0200 |
| commit | a29b6eb959bd5c3cbb2dd0ed7c982a10c93734d4 (patch) | |
| tree | a469a00152582163dfe7c7ba3680f43f87a265bf /fs/file_table.c | |
| parent | 7e053784c4c70df28324106d476778be7a4519b3 (diff) | |
| download | linux-a29b6eb959bd5c3cbb2dd0ed7c982a10c93734d4.tar.gz linux-a29b6eb959bd5c3cbb2dd0ed7c982a10c93734d4.tar.bz2 linux-a29b6eb959bd5c3cbb2dd0ed7c982a10c93734d4.zip | |
locks: fix TOCTOU race when granting write lease
[ Upstream commit d6da19c9cace63290ccfccb1fc35151ffefc0bec ]
Thread A trying to acquire a write lease checks the value of i_readcount
and i_writecount in check_conflicting_open() to verify that its own fd
is the only fd referencing the file.
Thread B trying to open the file for read will call break_lease() in
do_dentry_open() before incrementing i_readcount, which leaves a small
window where thread A can acquire the write lease and then thread B
completes the open of the file for read without breaking the write lease
that was acquired by thread A.
Fix this race by incrementing i_readcount before checking for existing
leases, same as the case with i_writecount.
Use a helper put_file_access() to decrement i_readcount or i_writecount
in do_dentry_open() and __fput().
Fixes: 387e3746d01c ("locks: eliminate false positive conflicts for write lease")
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'fs/file_table.c')
| -rw-r--r-- | fs/file_table.c | 7 |
1 files changed, 1 insertions, 6 deletions
diff --git a/fs/file_table.c b/fs/file_table.c index e8c9016703ad..6f297f9782fc 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -284,12 +284,7 @@ static void __fput(struct file *file) } fops_put(file->f_op); put_pid(file->f_owner.pid); - if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) - i_readcount_dec(inode); - if (mode & FMODE_WRITER) { - put_write_access(inode); - __mnt_drop_write(mnt); - } + put_file_access(file); dput(dentry); if (unlikely(mode & FMODE_NEED_UNMOUNT)) dissolve_on_fput(mnt); |
