Skip to content

Commit 5b0af8e

Browse files
thejhgregkh
authored andcommitted
filelock: Fix fcntl/close race recovery compat path
commit f8138f2 upstream. 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: stable@kernel.org Link: https://bugs.chromium.org/p/project-zero/issues/detail?id=2563 Signed-off-by: Jann Horn <jannh@google.com> Link: https://lore.kernel.org/r/20240723-fs-lock-recover-compatfix-v1-1-148096719529@google.com Signed-off-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 93a7737 commit 5b0af8e

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

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)