Skip to content

Commit f8138f2

Browse files
thejhbrauner
authored andcommitted
filelock: Fix fcntl/close race recovery compat path
When I wrote commit 3cad1bc ("filelock: Remove locks reliably when fcntl/close race is detected"), I missed that there are two copies of the code I was patching: The normal version, and the version for 64-bit offsets on 32-bit kernels. Thanks to Greg KH for stumbling over this while doing the stable backport... Apply exactly the same fix to the compat path for 32-bit kernels. Fixes: c293621 ("[PATCH] stale POSIX lock handling") Cc: [email protected] Link: https://bugs.chromium.org/p/project-zero/issues/detail?id=2563 Signed-off-by: Jann Horn <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 8eac535 commit f8138f2

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

fs/locks.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,8 +2570,9 @@ int fcntl_setlk64(unsigned int fd, struct file *filp, unsigned int cmd,
25702570
error = do_lock_file_wait(filp, cmd, file_lock);
25712571

25722572
/*
2573-
* Attempt to detect a close/fcntl race and recover by releasing the
2574-
* lock that was just acquired. There is no need to do that when we're
2573+
* Detect close/fcntl races and recover by zapping all POSIX locks
2574+
* associated with this file and our files_struct, just like on
2575+
* filp_flush(). There is no need to do that when we're
25752576
* unlocking though, or for OFD locks.
25762577
*/
25772578
if (!error && file_lock->c.flc_type != F_UNLCK &&
@@ -2586,9 +2587,7 @@ int fcntl_setlk64(unsigned int fd, struct file *filp, unsigned int cmd,
25862587
f = files_lookup_fd_locked(files, fd);
25872588
spin_unlock(&files->file_lock);
25882589
if (f != filp) {
2589-
file_lock->c.flc_type = F_UNLCK;
2590-
error = do_lock_file_wait(filp, cmd, file_lock);
2591-
WARN_ON_ONCE(error);
2590+
locks_remove_posix(filp, files);
25922591
error = -EBADF;
25932592
}
25942593
}

0 commit comments

Comments
 (0)