From cd189999d1160c6f9890689a418d0088d8477ef5 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Fri, 17 Jun 2022 19:06:05 +0200 Subject: [PATCH] Kernel: Don't let locks of the same owner conflict with each other Documentation on POSIX locks seems sparse, but this is how the Linux kernel implementation handles it. --- Kernel/FileSystem/Inode.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp index 59066cf751..1f59a1d967 100644 --- a/Kernel/FileSystem/Inode.cpp +++ b/Kernel/FileSystem/Inode.cpp @@ -348,6 +348,10 @@ ErrorOr Inode::get_flock(OpenFileDescription const& description, Userspace if (!range_overlap(lock.start, lock.len, lookup.l_start, lookup.l_len)) continue; + // Locks with the same owner can't conflict with each other. + if (lock.pid == Process::current().pid()) + continue; + if ((lookup.l_type == F_RDLCK && lock.type == F_WRLCK) || lookup.l_type == F_WRLCK) { lookup = { lock.type, SEEK_SET, lock.start, lock.len, lock.pid }; return copy_to_user(reference_lock, &lookup);