Skip to contentSkip to conversation

ksmbd: use F_SETLK when unlocking a file

PATCH In review Jeff Layton 4 participants 6 messages Nov 11, 2022 – Nov 16, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ksmbd: use F_SETLK when unlocking a file

ksmbd seems to be trying to use a cmd value of 0 when unlocking a file. That activity requires a type of F_UNLCK with a cmd of F_SETLK. For local POSIX locking, it doesn't matter much since vfs_lock_file ignores @cmd, but filesystems that define their own ->lock operation expect to see it set sanely.

---
 fs/ksmbd/smb2pdu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ksmbd/smb2pdu.c +2 -2
index b2fc85d440d0..f2bcd2a5fb7f 100644
@@ -6751,7 +6751,7 @@ static int smb2_set_flock_flags(struct file_lock *flock, int flags)
 	case SMB2_LOCKFLAG_UNLOCK:
 		ksmbd_debug(SMB, "received unlock request\n");
 		flock->fl_type = F_UNLCK;
-		cmd = 0;
+		cmd = F_SETLK;
 		break;
 	}
 
@@ -7129,7 +7129,7 @@ int smb2_lock(struct ksmbd_work *work)
 		rlock->fl_start = smb_lock->start;
 		rlock->fl_end = smb_lock->end;
 
-		rc = vfs_lock_file(filp, 0, rlock, NULL);
+		rc = vfs_lock_file(filp, F_SETLK, rlock, NULL);
 		if (rc)
 			pr_err("rollback unlock fail : %d\n", rc);
 
Signature · 1 line
2.38.1
maintainer Acked-by on v1 1/1
#1 lore raw

2022-11-11 22:11 GMT+09:00, Jeff Layton <[email protected]>:

Quoted 8 lines

ksmbd seems to be trying to use a cmd value of 0 when unlocking a file. That activity requires a type of F_UNLCK with a cmd of F_SETLK. For local POSIX locking, it doesn't matter much since vfs_lock_file ignores @cmd, but filesystems that define their own ->lock operation expect to see it set sanely.

Thanks for your patch.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Jeff Layton
Quoted 8 lines · Jeff Layton

ksmbd seems to be trying to use a cmd value of 0 when unlocking a file. That activity requires a type of F_UNLCK with a cmd of F_SETLK. For local POSIX locking, it doesn't matter much since vfs_lock_file ignores @cmd, but filesystems that define their own ->lock operation expect to see it set sanely.

#3 lore raw
In reply to Jeff Layton
Quoted 5 lines · Jeff Layton

ksmbd seems to be trying to use a cmd value of 0 when unlocking a file. That activity requires a type of F_UNLCK with a cmd of F_SETLK. For local POSIX locking, it doesn't matter much since vfs_lock_file ignores @cmd, but filesystems that define their own ->lock operation expect to see it set sanely.

Btw, I really wonder if we should split vfs_lock_file into separate calls for locking vs unlocking. The current interface seems very confusing.

#4 lore raw
Quoted 10 lines · Christoph Hellwig
Quoted 5 lines · Jeff Layton

ksmbd seems to be trying to use a cmd value of 0 when unlocking a file. That activity requires a type of F_UNLCK with a cmd of F_SETLK. For local POSIX locking, it doesn't matter much since vfs_lock_file ignores @cmd, but filesystems that define their own ->lock operation expect to see it set sanely.

Btw, I really wonder if we should split vfs_lock_file into separate calls for locking vs unlocking. The current interface seems very confusing.

Maybe, though the current scheme basically of mirrors the userland API, as do the ->lock and ->flock file_operations.

FWIW, the filelocking API is pretty rife with warts. Several other things that I wouldn't mind doing, just off the top of my head:

- move the file locking API into a separate header. No need for it to be in fs.h, which is already too bloated.

- define a new struct for leases, and drop lease-specific fields from file_lock

- remove more separate filp and inode arguments

- maybe rename locks.c to filelock.c? "locks.c" is too ambiguous

Any others?

Signature · 1 line
Jeff Layton <[email protected]>
#5 lore raw
Quoted 2 lines · Jeff Layton

Maybe, though the current scheme basically of mirrors the userland API, as do the ->lock and ->flock file_operations.

Yes. But the userland API is pretty horrible and the file_operations should go along with any locks API change.

Quoted 6 lines

FWIW, the filelocking API is pretty rife with warts. Several other things that I wouldn't mind doing, just off the top of my head:

- move the file locking API into a separate header. No need for it to be in fs.h, which is already too bloated.

Quoted 6 lines

- define a new struct for leases, and drop lease-specific fields from file_lock

- remove more separate filp and inode arguments

- maybe rename locks.c to filelock.c? "locks.c" is too ambiguous

These all sounds pretty reasonable to me.