Files
linux/fs
Amir Goldstein d6da19c9ca locks: fix TOCTOU race when granting write lease
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: 387e3746d0 ("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>
2022-08-16 10:59:54 -04:00
..
2022-07-02 18:52:21 +09:00
2022-08-13 17:20:51 -07:00
2022-06-29 08:51:06 -04:00
2022-05-09 16:21:45 -04:00
2022-07-26 13:38:47 +02:00
2022-05-09 16:21:46 -04:00
2022-05-23 20:24:12 -05:00
2022-07-15 23:42:30 -07:00
2022-07-16 09:19:15 -04:00
2022-07-24 18:39:10 -06:00
2022-06-28 13:58:05 -04:00
2022-05-22 21:03:01 +01:00
2021-02-13 17:17:53 +01:00
2021-08-10 17:57:22 +02:00