]> Git Repo - J-linux.git/commitdiff
filelock: fix potential use-after-free in posix_lock_inode
authorJeff Layton <[email protected]>
Tue, 2 Jul 2024 22:44:48 +0000 (18:44 -0400)
committerChristian Brauner <[email protected]>
Fri, 5 Jul 2024 16:40:44 +0000 (18:40 +0200)
Light Hsieh reported a KASAN UAF warning in trace_posix_lock_inode().
The request pointer had been changed earlier to point to a lock entry
that was added to the inode's list. However, before the tracepoint could
fire, another task raced in and freed that lock.

Fix this by moving the tracepoint inside the spinlock, which should
ensure that this doesn't happen.

Fixes: 74f6f5912693 ("locks: fix KASAN: use-after-free in trace_event_raw_event_filelock_lock")
Link: https://lore.kernel.org/linux-fsdevel/[email protected]/
Reported-by: Light Hsieh (謝明燈) <[email protected]>
Signed-off-by: Jeff Layton <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Reviewed-by: Alexander Aring <[email protected]>
Signed-off-by: Christian Brauner <[email protected]>
fs/locks.c

index 90c8746874dedbbb71e14b8269bbbcd216fd1bf7..2a445776dae3c85c788ba07a9867d5623c8abee4 100644 (file)
@@ -1367,9 +1367,9 @@ retry:
                locks_wake_up_blocks(&left->c);
        }
  out:
+       trace_posix_lock_inode(inode, request, error);
        spin_unlock(&ctx->flc_lock);
        percpu_up_read(&file_rwsem);
-       trace_posix_lock_inode(inode, request, error);
        /*
         * Free any unused locks.
         */
This page took 0.058961 seconds and 4 git commands to generate.