From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jeff Layton Subject: [PATCH] locks: require that flock->l_pid be set to 0 for file-private locks Date: Tue, 4 Mar 2014 14:09:08 -0500 Message-ID: <1393960148-18802-1-git-send-email-jlayton@redhat.com> Cc: bfields@fieldses.org, neilb@suse.de To: linux-fsdevel@vger.kernel.org Return-path: Received: from mail-qa0-f54.google.com ([209.85.216.54]:37161 "EHLO mail-qa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753420AbaCDTJQ (ORCPT ); Tue, 4 Mar 2014 14:09:16 -0500 Received: by mail-qa0-f54.google.com with SMTP id w8so5354072qac.27 for ; Tue, 04 Mar 2014 11:09:16 -0800 (PST) Sender: linux-fsdevel-owner@vger.kernel.org List-ID: 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 Signed-off-by: Jeff Layton --- fs/locks.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/fs/locks.c b/fs/locks.c index ce93815b0626..6fdf26a79cc8 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -1931,6 +1931,10 @@ int fcntl_getlk(struct file *filp, unsigned int cmd, struct flock __user *l) goto out; if (cmd == F_GETLKP) { + error = -EINVAL; + if (flock.l_pid != 0) + goto out; + cmd = F_GETLK; file_lock.fl_flags |= FL_FILE_PVT; file_lock.fl_owner = (fl_owner_t)filp; @@ -2062,11 +2066,19 @@ again: */ switch (cmd) { case F_SETLKP: + error = -EINVAL; + if (flock.l_pid != 0) + goto out; + cmd = F_SETLK; file_lock->fl_flags |= FL_FILE_PVT; file_lock->fl_owner = (fl_owner_t)filp; break; case F_SETLKPW: + error = -EINVAL; + if (flock.l_pid != 0) + goto out; + cmd = F_SETLKW; file_lock->fl_flags |= FL_FILE_PVT; 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) goto out; if (cmd == F_GETLKP) { + error = -EINVAL; + if (flock.l_pid != 0) + goto out; + cmd = F_GETLK64; file_lock.fl_flags |= FL_FILE_PVT; file_lock.fl_owner = (fl_owner_t)filp; @@ -2185,11 +2201,19 @@ again: */ switch (cmd) { case F_SETLKP: + error = -EINVAL; + if (flock.l_pid != 0) + goto out; + cmd = F_SETLK64; file_lock->fl_flags |= FL_FILE_PVT; file_lock->fl_owner = (fl_owner_t)filp; break; case F_SETLKPW: + error = -EINVAL; + if (flock.l_pid != 0) + goto out; + cmd = F_SETLKW64; file_lock->fl_flags |= FL_FILE_PVT; file_lock->fl_owner = (fl_owner_t)filp; -- 1.8.5.3