Commit 90478939 authored by Jeff Layton's avatar Jeff Layton

locks: require that flock->l_pid be set to 0 for file-private locks

Neil Brown suggested potentially overloading the l_pid value as a "lock
context" field for file-private locks. While I don't think we will
probably want to do that here, it's probably a good idea to ensure that
in the future we could extend this API without breaking existing
callers.

Typically the l_pid value is ignored for incoming struct flock
arguments, serving mainly as a place to return the pid of the owner if
there is a conflicting lock. For file-private locks, require that it
currently be set to 0 and return EINVAL if it isn't. If we eventually
want to make a non-zero l_pid mean something, then this will help ensure
that we don't break legacy programs that are using file-private locks.

Cc: Neil Brown <neilb@suse.de>
Signed-off-by: default avatarJeff Layton <jlayton@redhat.com>
parent 5d50ffd7
...@@ -1931,6 +1931,10 @@ int fcntl_getlk(struct file *filp, unsigned int cmd, struct flock __user *l) ...@@ -1931,6 +1931,10 @@ int fcntl_getlk(struct file *filp, unsigned int cmd, struct flock __user *l)
goto out; goto out;
if (cmd == F_GETLKP) { if (cmd == F_GETLKP) {
error = -EINVAL;
if (flock.l_pid != 0)
goto out;
cmd = F_GETLK; cmd = F_GETLK;
file_lock.fl_flags |= FL_FILE_PVT; file_lock.fl_flags |= FL_FILE_PVT;
file_lock.fl_owner = (fl_owner_t)filp; file_lock.fl_owner = (fl_owner_t)filp;
...@@ -2062,11 +2066,19 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd, ...@@ -2062,11 +2066,19 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd,
*/ */
switch (cmd) { switch (cmd) {
case F_SETLKP: case F_SETLKP:
error = -EINVAL;
if (flock.l_pid != 0)
goto out;
cmd = F_SETLK; cmd = F_SETLK;
file_lock->fl_flags |= FL_FILE_PVT; file_lock->fl_flags |= FL_FILE_PVT;
file_lock->fl_owner = (fl_owner_t)filp; file_lock->fl_owner = (fl_owner_t)filp;
break; break;
case F_SETLKPW: case F_SETLKPW:
error = -EINVAL;
if (flock.l_pid != 0)
goto out;
cmd = F_SETLKW; cmd = F_SETLKW;
file_lock->fl_flags |= FL_FILE_PVT; file_lock->fl_flags |= FL_FILE_PVT;
file_lock->fl_owner = (fl_owner_t)filp; file_lock->fl_owner = (fl_owner_t)filp;
...@@ -2121,6 +2133,10 @@ int fcntl_getlk64(struct file *filp, unsigned int cmd, struct flock64 __user *l) ...@@ -2121,6 +2133,10 @@ int fcntl_getlk64(struct file *filp, unsigned int cmd, struct flock64 __user *l)
goto out; goto out;
if (cmd == F_GETLKP) { if (cmd == F_GETLKP) {
error = -EINVAL;
if (flock.l_pid != 0)
goto out;
cmd = F_GETLK64; cmd = F_GETLK64;
file_lock.fl_flags |= FL_FILE_PVT; file_lock.fl_flags |= FL_FILE_PVT;
file_lock.fl_owner = (fl_owner_t)filp; file_lock.fl_owner = (fl_owner_t)filp;
...@@ -2185,11 +2201,19 @@ int fcntl_setlk64(unsigned int fd, struct file *filp, unsigned int cmd, ...@@ -2185,11 +2201,19 @@ int fcntl_setlk64(unsigned int fd, struct file *filp, unsigned int cmd,
*/ */
switch (cmd) { switch (cmd) {
case F_SETLKP: case F_SETLKP:
error = -EINVAL;
if (flock.l_pid != 0)
goto out;
cmd = F_SETLK64; cmd = F_SETLK64;
file_lock->fl_flags |= FL_FILE_PVT; file_lock->fl_flags |= FL_FILE_PVT;
file_lock->fl_owner = (fl_owner_t)filp; file_lock->fl_owner = (fl_owner_t)filp;
break; break;
case F_SETLKPW: case F_SETLKPW:
error = -EINVAL;
if (flock.l_pid != 0)
goto out;
cmd = F_SETLKW64; cmd = F_SETLKW64;
file_lock->fl_flags |= FL_FILE_PVT; file_lock->fl_flags |= FL_FILE_PVT;
file_lock->fl_owner = (fl_owner_t)filp; file_lock->fl_owner = (fl_owner_t)filp;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment