Skip to content

Commit 7e8e5cc

Browse files
committed
filelock: WARN_ON_ONCE when ->fl_file and filp don't match
vfs_lock_file, vfs_test_lock and vfs_cancel_lock all take both a struct file argument and a file_lock. The file_lock has a fl_file field in it howevever and it _must_ match the file passed in. While most of the locks.c routines use the separately-passed file argument, some filesystems rely on fl_file being filled out correctly. I'm working on a patch series to remove the redundant argument from these routines, but for now, let's ensure that the callers always set this properly by issuing a WARN_ON_ONCE if they ever don't match. Cc: Chuck Lever <[email protected]> Cc: Trond Myklebust <[email protected]> Signed-off-by: Jeff Layton <[email protected]>
1 parent 094226a commit 7e8e5cc

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

fs/locks.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,6 +2146,7 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd)
21462146
*/
21472147
int vfs_test_lock(struct file *filp, struct file_lock *fl)
21482148
{
2149+
WARN_ON_ONCE(filp != fl->fl_file);
21492150
if (filp->f_op->lock)
21502151
return filp->f_op->lock(filp, F_GETLK, fl);
21512152
posix_test_lock(filp, fl);
@@ -2295,6 +2296,7 @@ int fcntl_getlk(struct file *filp, unsigned int cmd, struct flock *flock)
22952296
*/
22962297
int vfs_lock_file(struct file *filp, unsigned int cmd, struct file_lock *fl, struct file_lock *conf)
22972298
{
2299+
WARN_ON_ONCE(filp != fl->fl_file);
22982300
if (filp->f_op->lock)
22992301
return filp->f_op->lock(filp, cmd, fl);
23002302
else
@@ -2663,6 +2665,7 @@ void locks_remove_file(struct file *filp)
26632665
*/
26642666
int vfs_cancel_lock(struct file *filp, struct file_lock *fl)
26652667
{
2668+
WARN_ON_ONCE(filp != fl->fl_file);
26662669
if (filp->f_op->lock)
26672670
return filp->f_op->lock(filp, F_CANCELLK, fl);
26682671
return 0;

0 commit comments

Comments
 (0)