Skip to content

Commit

Permalink
kernfs: annotate different lockdep class for of->mutex of writable files
Browse files Browse the repository at this point in the history
The writable file /sys/power/resume may call vfs lookup helpers for
arbitrary paths and readonly files can be read by overlayfs from vfs
helpers when sysfs is a lower layer of overalyfs.

To avoid a lockdep warning of circular dependency between overlayfs
inode lock and kernfs of->mutex, use a different lockdep class for
writable and readonly kernfs files.

Reported-by: [email protected]
Fixes: 0fedefd ("kernfs: sysfs: support custom llseek method for sysfs entries")
Suggested-by: Al Viro <[email protected]>
Signed-off-by: Amir Goldstein <[email protected]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
amir73il authored and Al Viro committed Apr 14, 2024
1 parent fec50db commit 16b52bb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion fs/kernfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -636,11 +636,18 @@ static int kernfs_fop_open(struct inode *inode, struct file *file)
* each file a separate locking class. Let's differentiate on
* whether the file has mmap or not for now.
*
* Both paths of the branch look the same. They're supposed to
* For similar reasons, writable and readonly files are given different
* lockdep key, because the writable file /sys/power/resume may call vfs
* lookup helpers for arbitrary paths and readonly files can be read by
* overlayfs from vfs helpers when sysfs is a lower layer of overalyfs.
*
* All three cases look the same. They're supposed to
* look that way and give @of->mutex different static lockdep keys.
*/
if (has_mmap)
mutex_init(&of->mutex);
else if (file->f_mode & FMODE_WRITE)
mutex_init(&of->mutex);
else
mutex_init(&of->mutex);

Expand Down

0 comments on commit 16b52bb

Please sign in to comment.