From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87DF2C55179 for ; Fri, 30 Oct 2020 15:49:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 07DFE22246 for ; Fri, 30 Oct 2020 15:49:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="ugPQTkip" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 07DFE22246 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 615716B006E; Fri, 30 Oct 2020 11:49:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 57A3D6B0083; Fri, 30 Oct 2020 11:49:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 359D06B0085; Fri, 30 Oct 2020 11:49:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0103.hostedemail.com [216.40.44.103]) by kanga.kvack.org (Postfix) with ESMTP id E5E0E6B006E for ; Fri, 30 Oct 2020 11:49:45 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 902ED181AEF10 for ; Fri, 30 Oct 2020 15:49:45 +0000 (UTC) X-FDA: 77429027130.17.brain83_4907bea27297 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 71055180D0180 for ; Fri, 30 Oct 2020 15:49:45 +0000 (UTC) X-HE-Tag: brain83_4907bea27297 X-Filterd-Recvd-Size: 5122 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf42.hostedemail.com (Postfix) with ESMTP for ; Fri, 30 Oct 2020 15:49:44 +0000 (UTC) Received: from localhost.localdomain (HSI-KBW-46-223-126-90.hsi.kabel-badenwuerttemberg.de [46.223.126.90]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0B43B22241; Fri, 30 Oct 2020 15:49:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604072983; bh=Mx21NEzsW0sqOlRSKKtH114cIyZ8zXg4jMUbhna5VF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ugPQTkip7iCrZSHrqBz6Pc8ED6zMvRtbryCcPbLZLzqUBWWz6eL+SfaLIu5/pSc6V TS+HeRVtV2vG7RW/aipBaP6YOToLXIC/1wQbnJfLxsTA22Cfp/tGzuBNIK8DWVVd2Q CGoec7enG38Hfk3qgtSkzJ35WeM5bIJXZf0w67YQ= From: Arnd Bergmann To: Russell King , Christoph Hellwig Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, viro@zeniv.linux.org.uk, linus.walleij@linaro.org, arnd@arndb.de Subject: [PATCH 7/9] ARM: oabi-compat: rework fcntl64() emulation Date: Fri, 30 Oct 2020 16:49:17 +0100 Message-Id: <20201030154919.1246645-7-arnd@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201030154919.1246645-1-arnd@kernel.org> References: <20201030154519.1245983-1-arnd@kernel.org> <20201030154919.1246645-1-arnd@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: From: Arnd Bergmann 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))); =20 -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; =20 if (copy_from_user(&user, (struct oabi_flock64 __user *)arg, sizeof(user))) return -EFAULT; - kernel.l_type =3D user.l_type; - kernel.l_whence =3D user.l_whence; - kernel.l_start =3D user.l_start; - kernel.l_len =3D user.l_len; - kernel.l_pid =3D user.l_pid; - - fs =3D get_fs(); - set_fs(KERNEL_DS); - ret =3D sys_fcntl64(fd, cmd, (unsigned long)&kernel); - set_fs(fs); - - if (!ret && (cmd =3D=3D F_GETLK64 || cmd =3D=3D F_OFD_GETLK)) { - user.l_type =3D kernel.l_type; - user.l_whence =3D kernel.l_whence; - user.l_start =3D kernel.l_start; - user.l_len =3D kernel.l_len; - user.l_pid =3D kernel.l_pid; - if (copy_to_user((struct oabi_flock64 __user *)arg, - &user, sizeof(user))) - ret =3D -EFAULT; - } - return ret; + + kernel->l_type =3D user.l_type; + kernel->l_whence =3D user.l_whence; + kernel->l_start =3D user.l_start; + kernel->l_len =3D user.l_len; + kernel->l_pid =3D 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 =3D kernel->l_type; + user.l_whence =3D kernel->l_whence; + user.l_start =3D kernel->l_start; + user.l_len =3D kernel->l_len; + user.l_pid =3D kernel->l_pid; + + if (copy_to_user((struct oabi_flock64 __user *)arg, + &user, sizeof(user))) + return -EFAULT; + + return 0; } =20 asmlinkage long sys_oabi_fcntl64(unsigned int fd, unsigned int cmd, unsigned long arg) { + void __user *argp =3D (void __user *)arg; + struct fd f =3D fdget_raw(fd); + struct flock64 flock; + long err =3D -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 =3D security_file_fcntl(f.file, cmd, arg); + if (err) + break; + err =3D get_oabi_flock(&flock, argp); + if (err) + break; + err =3D fcntl_getlk64(f.file, cmd, &flock); + if (!err) + err =3D 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 =3D security_file_fcntl(f.file, cmd, arg); + if (err) + break; + err =3D get_oabi_flock(&flock, argp); + if (err) + break; + err =3D fcntl_setlk64(fd, f.file, cmd, &flock); + break; default: - return sys_fcntl64(fd, cmd, arg); + err =3D sys_fcntl64(fd, cmd, arg); + break; } + fdput(f); +out: + return err; } =20 struct oabi_epoll_event { --=20 2.27.0