Skip to content

Commit a770863

Browse files
committed
Merge: filelock: Fix fcntl/close race recovery compat path
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/4912 JIRA: https://issues.redhat.com/browse/RHEL-50898 CVE: CVE-2024-41020 Conflicts: Conflict is caused by absence of upstream commit 4ca52f5 (filelock: have fs/locks.c deal with file_lock_core directly) Signed-off-by: Pavel Reichl <preichl@redhat.com> Approved-by: Andrey Albershteyn <aalbersh@redhat.com> Approved-by: Brian Foster <bfoster@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Lucas Zampieri <lzampier@redhat.com>
2 parents 17d4804 + 37f2f2a commit a770863

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
@@ -2485,8 +2485,9 @@ int fcntl_setlk64(unsigned int fd, struct file *filp, unsigned int cmd,
24852485
error = do_lock_file_wait(filp, cmd, file_lock);
24862486

24872487
/*
2488-
* Attempt to detect a close/fcntl race and recover by releasing the
2489-
* lock that was just acquired. There is no need to do that when we're
2488+
* Detect close/fcntl races and recover by zapping all POSIX locks
2489+
* associated with this file and our files_struct, just like on
2490+
* filp_flush(). There is no need to do that when we're
24902491
* unlocking though, or for OFD locks.
24912492
*/
24922493
if (!error && file_lock->fl_type != F_UNLCK &&
@@ -2501,9 +2502,7 @@ int fcntl_setlk64(unsigned int fd, struct file *filp, unsigned int cmd,
25012502
f = files_lookup_fd_locked(files, fd);
25022503
spin_unlock(&files->file_lock);
25032504
if (f != filp) {
2504-
file_lock->fl_type = F_UNLCK;
2505-
error = do_lock_file_wait(filp, cmd, file_lock);
2506-
WARN_ON_ONCE(error);
2505+
locks_remove_posix(filp, files);
25072506
error = -EBADF;
25082507
}
25092508
}

0 commit comments

Comments
 (0)