Skip to content

Commit 60da98e

Browse files
committed
Merge: filelock: Remove locks reliably when fcntl/close race is detected
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/4817 filelock: Remove locks reliably when fcntl/close race is detected JIRA: https://issues.redhat.com/browse/RHEL-50176 CVE: CVE-2024-41012 Signed-off-by: Bill O'Donnell <bodonnel@redhat.com> Approved-by: Eric Sandeen <esandeen@redhat.com> Approved-by: Brian Foster <bfoster@redhat.com> Approved-by: Ian Kent <ikent@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Lucas Zampieri <lzampier@redhat.com>
2 parents 4e90cf8 + 716e22b commit 60da98e

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
@@ -2364,8 +2364,9 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd,
23642364
error = do_lock_file_wait(filp, cmd, file_lock);
23652365

23662366
/*
2367-
* Attempt to detect a close/fcntl race and recover by releasing the
2368-
* lock that was just acquired. There is no need to do that when we're
2367+
* Detect close/fcntl races and recover by zapping all POSIX locks
2368+
* associated with this file and our files_struct, just like on
2369+
* filp_flush(). There is no need to do that when we're
23692370
* unlocking though, or for OFD locks.
23702371
*/
23712372
if (!error && file_lock->fl_type != F_UNLCK &&
@@ -2380,9 +2381,7 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd,
23802381
f = files_lookup_fd_locked(files, fd);
23812382
spin_unlock(&files->file_lock);
23822383
if (f != filp) {
2383-
file_lock->fl_type = F_UNLCK;
2384-
error = do_lock_file_wait(filp, cmd, file_lock);
2385-
WARN_ON_ONCE(error);
2384+
locks_remove_posix(filp, files);
23862385
error = -EBADF;
23872386
}
23882387
}

0 commit comments

Comments
 (0)