From patchwork Thu Oct 1 14:12:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11811537 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 889F06CA for ; Thu, 1 Oct 2020 14:15:17 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 571ED20872 for ; Thu, 1 Oct 2020 14:15:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="a3sByaUr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 571ED20872 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arndb.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+zanp3Jfhn8fGlovN3T5kLugfvJd9gHkA2fBgtHtPf0=; b=a3sByaUrJju/q3qcVTeG/7rdP KSL3VFtOQZW20iE4oygVUBF9G3LGA5PEnCJTW15AavZUPB4ITPl7gRN5yFuSzCKavwX93j1bm4fFH gNpVQNSHrAbG3yVMU2gbyz01fi4g/EFKVUpVN37QMCmkB+3RM4W9NFfCEy4ThiSORfXEoc3Nxle9n TXx/a6+zqyo9xsvAz59QmOTpl92KOsg/lfJ645qI7nuxBBynnJRorDwZhkXRU1cjowGHXVuulg0ZC UDQBSj4m13nc6kShQ3OPGUW75fN+DmfrUyZEQKG5j4mTuEahcjzhavMFvxbAjgzeKrZZm4+OajVAd WaL7oKYRg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kNzKo-0001Px-8M; Thu, 01 Oct 2020 14:13:26 +0000 Received: from mout.kundenserver.de ([217.72.192.75]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kNzKN-00019Y-Ns for linux-arm-kernel@lists.infradead.org; Thu, 01 Oct 2020 14:13:02 +0000 Received: from threadripper.lan ([46.223.126.90]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MLR9p-1k6ala2thD-00IXTP; Thu, 01 Oct 2020 16:12:53 +0200 From: Arnd Bergmann To: Russell King , Christoph Hellwig Subject: [PATCH v3 07/10] ARM: oabi-compat: rework fcntl64() emulation Date: Thu, 1 Oct 2020 16:12:30 +0200 Message-Id: <20201001141233.119343-8-arnd@arndb.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201001141233.119343-1-arnd@arndb.de> References: <20201001141233.119343-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:3TKgNrSTMpXNYGaFmu+SKHQrcSCbfmgZhLqpwbUtnDHIn9vPu29 oSkmHqaY7tsVWPZ2Ptkj1ib/NP/Dj6JPyQuSGpHXVR1Gqq30UVLFmv4Ia29rizLkAFHMdnl ozciaEsv5U1wTT6P8yVO75ZH+AeAXUIPO3efL7tlJ3g/x+yGiqwRxzgti7AONfBzTsd4hu2 JhI+LZ53Zez1akbZmzfzw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:w4rV1cQPcYg=:EYlyzTuBZ/LUfCWS+MzcGD kMfyyUknM+NGlxu5WBpVCEYA1LRustzlIEARJoYZofCaPKT8/dorMGR5Hr3nvdkP1cIs6McH1 qwT8N4mE9Q/ii5jF84vfiLgM3AddNFZbeXDLGOOGU5X/pyq4uSUY21T3O3icI+WZTF5pfyYpy 9DuJbOAYpzMgK8MtlknyOgV93A/KijM5rxcuUglbkmTdgq1EEnDENMO0Glt/qE6weMaG+fsy6 Krc1lkjbXQkIhPxHQg/6xnbepbCQN+0dshF18C3D/Zn4koW0EkRAb3XwvMRIsFfCB8ykkdHdB XSCv+v9HaIk7Guf6hFtuAXwLvZu7X4KUoAqs/cB+e/ZcMzs/Q9gkL0QhLfFVtgxZv9ftyBsyQ TD+rXPLIB/1q1M0/sbhCYec3Kpjd1QriCjO5mNR1iOnefl6VsAo7M/MTGvLJGsrKaqfsSCMYb L7KG8rfu8kd/OjXc0oL7N1EIcjHf9fzJS1xNyKOgTds2kzWlHP8mubFzySKwTc19CHJQ51qgo py0nbEm9jac3RR09S9gstqr8OGEkxH4O7d1g8uxinKK5xLLUGW129ZcRjQWwrxkfkIjJ6as3G 2IIhS1mqvsh8dP7or52uNvPR6tiyxwePa7QT8/A7ghsJ/IyWHLpZjUW98AwBOdbP/Fhcz/dU8 bJcj3ooA9MwkzpcyRqg85wPztd7M7JIdj08prwnymILsBvnMO+8aGRj45XaQb/3K+Wx0EDx8k Soqy/pKwglc2a6OAD8CqfxmS8hf7i9wXQMEBupL/22XLoqp9dU/TKBsVm+l2n0oOYyCe1o0bj fZfZIXsgGpQDcFiaZt66nmNuAc1OjREDo9MO8Y3cA6082coiaCG8i5fUQYhYo/D5qXXMpoT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201001_101259_996345_0C746404 X-CRM114-Status: GOOD ( 18.75 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [217.72.192.75 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [217.72.192.75 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Arnd Bergmann , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Viro , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This is one of the last users of get_fs(), and this is fairly easy to change, since the infrastructure for it is already there. The replacement here is essentially a copy of the existing fcntl64() syscall entry function. Signed-off-by: Arnd Bergmann --- arch/arm/kernel/sys_oabi-compat.c | 93 ++++++++++++++++++++----------- 1 file changed, 60 insertions(+), 33 deletions(-) diff --git a/arch/arm/kernel/sys_oabi-compat.c b/arch/arm/kernel/sys_oabi-compat.c index c3e63b73b6ae..3449e163ea88 100644 --- a/arch/arm/kernel/sys_oabi-compat.c +++ b/arch/arm/kernel/sys_oabi-compat.c @@ -194,56 +194,83 @@ struct oabi_flock64 { pid_t l_pid; } __attribute__ ((packed,aligned(4))); -static long do_locks(unsigned int fd, unsigned int cmd, - unsigned long arg) +static int get_oabi_flock(struct flock64 *kernel, struct oabi_flock64 __user *arg) { - struct flock64 kernel; struct oabi_flock64 user; - mm_segment_t fs; - long ret; if (copy_from_user(&user, (struct oabi_flock64 __user *)arg, sizeof(user))) return -EFAULT; - kernel.l_type = user.l_type; - kernel.l_whence = user.l_whence; - kernel.l_start = user.l_start; - kernel.l_len = user.l_len; - kernel.l_pid = user.l_pid; - - fs = get_fs(); - set_fs(KERNEL_DS); - ret = sys_fcntl64(fd, cmd, (unsigned long)&kernel); - set_fs(fs); - - if (!ret && (cmd == F_GETLK64 || cmd == F_OFD_GETLK)) { - user.l_type = kernel.l_type; - user.l_whence = kernel.l_whence; - user.l_start = kernel.l_start; - user.l_len = kernel.l_len; - user.l_pid = kernel.l_pid; - if (copy_to_user((struct oabi_flock64 __user *)arg, - &user, sizeof(user))) - ret = -EFAULT; - } - return ret; + + kernel->l_type = user.l_type; + kernel->l_whence = user.l_whence; + kernel->l_start = user.l_start; + kernel->l_len = user.l_len; + kernel->l_pid = user.l_pid; + + return 0; +} + +static int put_oabi_flock(struct flock64 *kernel, struct oabi_flock64 __user *arg) +{ + struct oabi_flock64 user; + + user.l_type = kernel->l_type; + user.l_whence = kernel->l_whence; + user.l_start = kernel->l_start; + user.l_len = kernel->l_len; + user.l_pid = kernel->l_pid; + + if (copy_to_user((struct oabi_flock64 __user *)arg, + &user, sizeof(user))) + return -EFAULT; + + return 0; } asmlinkage long sys_oabi_fcntl64(unsigned int fd, unsigned int cmd, unsigned long arg) { + void __user *argp = (void __user *)arg; + struct fd f = fdget_raw(fd); + struct flock64 flock; + long err = -EBADF; + + if (!f.file) + goto out; + switch (cmd) { - case F_OFD_GETLK: - case F_OFD_SETLK: - case F_OFD_SETLKW: case F_GETLK64: + case F_OFD_GETLK: + err = security_file_fcntl(f.file, cmd, arg); + if (err) + break; + err = get_oabi_flock(&flock, argp); + if (err) + break; + err = fcntl_getlk64(f.file, cmd, &flock); + if (!err) + err = put_oabi_flock(&flock, argp); + break; case F_SETLK64: case F_SETLKW64: - return do_locks(fd, cmd, arg); - + case F_OFD_SETLK: + case F_OFD_SETLKW: + err = security_file_fcntl(f.file, cmd, arg); + if (err) + break; + err = get_oabi_flock(&flock, argp); + if (err) + break; + err = fcntl_setlk64(fd, f.file, cmd, &flock); + break; default: - return sys_fcntl64(fd, cmd, arg); + err = sys_fcntl64(fd, cmd, arg); + break; } + fdput(f); +out: + return err; } struct oabi_epoll_event {