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: 11811523 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 5EAF592C for ; Thu, 1 Oct 2020 14:13:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1D1F920872 for ; Thu, 1 Oct 2020 14:13:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1D1F920872 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arndb.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8F3CD900004; Thu, 1 Oct 2020 10:13:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 89DF6900003; Thu, 1 Oct 2020 10:13:06 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B262900004; Thu, 1 Oct 2020 10:13:06 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0087.hostedemail.com [216.40.44.87]) by kanga.kvack.org (Postfix) with ESMTP id 3606A900003 for ; Thu, 1 Oct 2020 10:13:06 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B293B3631 for ; Thu, 1 Oct 2020 14:13:05 +0000 (UTC) X-FDA: 77323548330.17.end34_4b181d22719c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id B87AA1807EE81 for ; Thu, 1 Oct 2020 14:12:55 +0000 (UTC) X-Spam-Summary: 1,0,0,2207c55afb94f48f,d41d8cd98f00b204,arnd@arndb.de,,RULES_HIT:41:69:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1535:1543:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:3138:3139:3140:3141:3142:3355:3865:3866:3867:3868:3871:3872:4321:4605:5007:6119:6261:7903:7904:9592:9707:10004:11026:11658:11914:12043:12160:12291:12297:12555:12683:12895:13161:13229:13894:14096:14110:14181:14394:14721:21080:21627:21795:21990:30051:30054:30070:30079,0,RBL:217.72.192.75:@arndb.de:.lbl8.mailshell.net-64.201.201.201 62.8.6.100;04ygeg6xxba35m4qn6q1i46p5r5e8yp5ih3zofx6yr4c5kmke7opidd17ptegrf.paftoi8b8chy3pspnief371zxj8a9ozs4ph4g9k3ichh5akrys6sm1d8s9i9kec.o-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:20,LUA_SUMMARY:none X-HE-Tag: end34_4b181d22719c X-Filterd-Recvd-Size: 5789 Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.75]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Thu, 1 Oct 2020 14:12:54 +0000 (UTC) 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 Cc: Alexander Viro , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Arnd Bergmann 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-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 {