From patchwork Fri Sep 18 12:46:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11784901 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 78DD4618 for ; Fri, 18 Sep 2020 12:46:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2E2C1208B8 for ; Fri, 18 Sep 2020 12:46:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2E2C1208B8 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 2D6BB6B0072; Fri, 18 Sep 2020 08:46:42 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1C45A6B0062; Fri, 18 Sep 2020 08:46:41 -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 D05C4900002; Fri, 18 Sep 2020 08:46:41 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0134.hostedemail.com [216.40.44.134]) by kanga.kvack.org (Postfix) with ESMTP id 996096B0062 for ; Fri, 18 Sep 2020 08:46:41 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 6583A180AD81F for ; Fri, 18 Sep 2020 12:46:41 +0000 (UTC) X-FDA: 77276156202.16.park92_23093672712b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 351A1100D95D9 for ; Fri, 18 Sep 2020 12:46:41 +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:212.227.126.133:@arndb.de:.lbl8.mailshell.net-66.201.201.201 62.8.6.100;04yfxzgu63wybmji61mij5u3pbhm7op5ih3zofx6yr4c5kmke7opidd17ptegrf.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:24,LUA_SUMMARY:none X-HE-Tag: park92_23093672712b X-Filterd-Recvd-Size: 5800 Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.133]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Fri, 18 Sep 2020 12:46:40 +0000 (UTC) Received: from threadripper.lan ([149.172.98.151]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.129]) with ESMTPA (Nemesis) id 1M8Qme-1kNfdU10s4-004WgL; Fri, 18 Sep 2020 14:46:36 +0200 From: Arnd Bergmann To: Christoph Hellwig , Russell King , Alexander Viro Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Arnd Bergmann Subject: [PATCH v2 7/9] ARM: oabi-compat: rework fcntl64() emulation Date: Fri, 18 Sep 2020 14:46:22 +0200 Message-Id: <20200918124624.1469673-8-arnd@arndb.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200918124624.1469673-1-arnd@arndb.de> References: <20200918124624.1469673-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:tgHAPjFkzbmCrE0bFNFXx5gUKVFkZULUnNl2Z7bJY7N2qHCsD2v KxA9/gMyrAyTOk65mT0VC7GjVFiG99ZMfH+CIhQ0T1DD7tfV2JfILE0v1H2uYUBsV5kjCpL qLV+hvKw7tDTD40FdC3n7sRHdoOYJpdAHcojUvWic/8qS5523SKEc/J45k3v22gNJgeqI8C HOs5NKWBB8JUnW1iHNDVg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:XydK1/HE+Ug=:asvyqVorczkPh2fDmcWUGN j8hUN9gPSeVltl6iGMiZRMS05l42B7/+fQQQNLJj3OJFM7MOvbcaX72mx+BGyQnQBjmIHSZVP 2+3SW23PCJrtj199P0S5UQhas0UQzwFtb2nCK1B1s9G+s5PIGmAQUHAcGQ75C+PKch1j+9cYB ym9vb+W/SWOdHaTyrJ2qY6j2gJWcHyWFmt1H1Mt3ifleR8dRqvzzkk0tcyfMREZ1hN6e1Q8oi 5N8kGpzuffwapvoVDP8oInvunl/fFhUQIZODLY782dWmx5gn69kokGGNtsSPpGWzZNVsiozln tsDPdRm0/aHcyEsdz74d3d8+Gh7t5ujxOBCjv0pQu7/yKOc/s6uWohlNj+JVKltZ3pDDunPZg xIyAtZ24zdriKQBI/I8rbff/zsA1ix7JDbZfYW2Mp30sVuO9t/4M2e8NvN1BGRJtRY77iLbzB //ombsiWgpJNTuLZCMM13xnm7xvkktLe58dXXgLXBLhSbwUi//BkZ9/EvbMtrGa/A9WAISPGG Ea8z/7rxsTnmf1e1Hil8w/5NyBf5r9qwkHqMaruWnntagzAfYmpU2vfp5NGLFm8fnu4A7u/12 MMIlPRxsZMSPQomGdMLAFuZw1xRzb4P9wdn3jJa0Ohf+4bDA597mO1XbhgGBs85MBsD2vP+uo Ch8SZpqlrpcUBTquaGqFI1+CCB3dj3qbNalb+denOuQ3os14KBWr1yKuUO/jlusIHcQk06jM0 UOwMy2QrJifGnazzd7Fw8IkI09qe9wxHyEzniBCVTl3n8Qd6d2yOOJgp9+6NIujTxNCg+p5+P BINOjwEUFesVaPmeHU4r+3a/zCoCA85viYsnq4lBYvxpJbsYEO0BYeaCXAq+PF8slF1bfrU 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 {