Skip to content

Commit 16b52bb

Browse files
amir73ilAl Viro
authored and
Al Viro
committed
kernfs: annotate different lockdep class for of->mutex of writable files
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: syzbot+9a5b0ced8b1bfb238b56@syzkaller.appspotmail.com Fixes: 0fedefd ("kernfs: sysfs: support custom llseek method for sysfs entries") Suggested-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent fec50db commit 16b52bb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

fs/kernfs/file.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,11 +636,18 @@ static int kernfs_fop_open(struct inode *inode, struct file *file)
636636
* each file a separate locking class. Let's differentiate on
637637
* whether the file has mmap or not for now.
638638
*
639-
* Both paths of the branch look the same. They're supposed to
639+
* For similar reasons, writable and readonly files are given different
640+
* lockdep key, because the writable file /sys/power/resume may call vfs
641+
* lookup helpers for arbitrary paths and readonly files can be read by
642+
* overlayfs from vfs helpers when sysfs is a lower layer of overalyfs.
643+
*
644+
* All three cases look the same. They're supposed to
640645
* look that way and give @of->mutex different static lockdep keys.
641646
*/
642647
if (has_mmap)
643648
mutex_init(&of->mutex);
649+
else if (file->f_mode & FMODE_WRITE)
650+
mutex_init(&of->mutex);
644651
else
645652
mutex_init(&of->mutex);
646653

0 commit comments

Comments
 (0)