From patchwork Thu Aug 18 12:03:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 14747 Received: (qmail 4812 invoked by alias); 18 Aug 2016 12:03:37 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 4798 invoked by uid 89); 18 Aug 2016 12:03:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=no version=3.3.2 spammy=UD:fcntl.h, fcntlh, fcntl.h, H*MI:4291 X-HELO: mx1.redhat.com From: Jeff Layton To: linux-fsdevel@vger.kernel.org Cc: libc-alpha@sourceware.org, chrubis@suse.cz Subject: [Linux PATCH] fcntl: add new F_OFD_*32 constants and handle them appropriately Date: Thu, 18 Aug 2016 08:03:24 -0400 Message-Id: <1471521804-4291-1-git-send-email-jlayton@redhat.com> When I originally added OFD lock support, we made the assumption that userland would always pass in a struct flock64 for an OFD lock. It's possible however for someone to build a binary without large file support (aka LFS), which will call down into the kernel with the standard F_OFD_* constants, but pass in a "legacy" struct flock. My first thought was to patch glibc to cause a build break if anyone tries to use OFD locks without LFS, but now I think it might be less problematic to simply support OFD locks without LFS enabled. The kernel handles this for classic POSIX locks with a separate set of constants (postfixed with "64") to indicate that the incoming structure is an LFS one. We can't do that here since the kernel already assumes that the structure is an LFS one. Instead, we can define a new set of constants that are postfixed with "32" to indicate that the incoming structure is a non-LFS one. This patch adds the kernel plumbing to handle that case. We'll also need a small patch for glibc to make it to use these constants when LFS is disabled. In the event that someone builds a program with a new glibc, and runs it on a kernel without support for F_OFD_*32 constants, they will just get back EINVAL. That's preferable to the current situation which is undefined behavior due to misinterpretation of the struct flock argument. Cc: stable@vger.kernel.org # v3.15+ Reported-by: Cyril Hrubis Signed-off-by: Jeff Layton --- fs/compat.c | 3 +++ fs/fcntl.c | 4 +++- fs/locks.c | 4 +++- include/uapi/asm-generic/fcntl.h | 4 ++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/fs/compat.c b/fs/compat.c index be6e48b0a46c..a7e9640e9107 100644 --- a/fs/compat.c +++ b/fs/compat.c @@ -426,6 +426,9 @@ COMPAT_SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd, case F_GETLK: case F_SETLK: case F_SETLKW: + case F_OFD_GETLK32: + case F_OFD_SETLK32: + case F_OFD_SETLKW32: ret = get_compat_flock(&f, compat_ptr(arg)); if (ret != 0) break; diff --git a/fs/fcntl.c b/fs/fcntl.c index 350a2c8cfd28..71704aa11170 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -270,6 +270,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg, /* 32-bit arches must use fcntl64() */ case F_OFD_GETLK: #endif + case F_OFD_GETLK32: case F_GETLK: err = fcntl_getlk(filp, cmd, (struct flock __user *) arg); break; @@ -278,7 +279,8 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg, case F_OFD_SETLK: case F_OFD_SETLKW: #endif - /* Fallthrough */ + case F_OFD_SETLK32: + case F_OFD_SETLKW32: case F_SETLK: case F_SETLKW: err = fcntl_setlk(fd, filp, cmd, (struct flock __user *) arg); diff --git a/fs/locks.c b/fs/locks.c index 7e428b78be07..4ffde68322de 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -2065,7 +2065,7 @@ int fcntl_getlk(struct file *filp, unsigned int cmd, struct flock __user *l) if (error) goto out; - if (cmd == F_OFD_GETLK) { + if (cmd == F_OFD_GETLK || cmd == F_OFD_GETLK32) { error = -EINVAL; if (flock.l_pid != 0) goto out; @@ -2222,6 +2222,7 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd, */ switch (cmd) { case F_OFD_SETLK: + case F_OFD_SETLK32: error = -EINVAL; if (flock.l_pid != 0) goto out; @@ -2231,6 +2232,7 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd, file_lock->fl_owner = filp; break; case F_OFD_SETLKW: + case F_OFD_SETLKW32: error = -EINVAL; if (flock.l_pid != 0) goto out; diff --git a/include/uapi/asm-generic/fcntl.h b/include/uapi/asm-generic/fcntl.h index e063effe0cc1..b407deee68e1 100644 --- a/include/uapi/asm-generic/fcntl.h +++ b/include/uapi/asm-generic/fcntl.h @@ -148,6 +148,10 @@ #define F_OFD_SETLK 37 #define F_OFD_SETLKW 38 +#define F_OFD_GETLK32 39 +#define F_OFD_SETLK32 40 +#define F_OFD_SETLKW32 41 + #define F_OWNER_TID 0 #define F_OWNER_PID 1 #define F_OWNER_PGRP 2