Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp4744995rwo; Tue, 25 Jul 2023 10:15:03 -0700 (PDT) X-Google-Smtp-Source: APBJJlHrXoMrXyk9RoCTMKbxzM8jId2ERkcMvENI1oESw/If9/mTfCQydFLTeVSTz4ceIKnxwvad X-Received: by 2002:a17:902:aa8a:b0:1b8:b41a:d4be with SMTP id d10-20020a170902aa8a00b001b8b41ad4bemr13296125plr.10.1690305302627; Tue, 25 Jul 2023 10:15:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690305302; cv=none; d=google.com; s=arc-20160816; b=ssesqKUPbFsOwkk7UORgKQcDRRbPY9419ro/CWoyG0f5qsvegRmydwzGUjtvjIFDvu P5TDFm1m6dkOsXdTPvlzBrsySOrCkUI3+iBKzAQCMK1hQXgpPD3CpvCfR6xLvQ4iOIOr BMMN0CiwLTq5RbeXXnYmLgMr0hQ38Xz/KMsNqabI+9Qo5tDpiLWdkvtG3X68OZ7vtJQd akyM5yXTeN7w0BccgwRaOBHSCDVITqB5mjco8DBC7IfqldQlkWaRQDEX4fpGKG2kmjB4 XiNzSj/U0OKLMaM7G+B5a3cGr4Aj7FwOmLEYqkRA45f5776jtQaD8r7yyvIsMRWfwXUB qKjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=JqCAz4pT3GDUTh/C6LdHYGGzlykcrPzOPXi/2ZYbtJI=; fh=S8a0lK6y3n+HOioFboRSiPuw3lW6qu3ey1t8rHkSEC4=; b=HFLCfGO1M+5wfYOxksCB9E3GizaOmM7tUT5lMuZc+4O1TU0tZUQrQNs9PeFRGltRR4 6eixh5xObU0HSKc6Y1Lrb404tnSrNNBRdjbNXmtnriQWYrpjuMz4v7hS0hAoCji01PyI b7Bo/fSB+FoL6FG6Zp1vE4KStOPSjCX4FuaiteQtHW9s08PL1J2yWE8Tk+63ow4ygDkg hUW5WNTkxaO7g5NSsTbW6yZp4L89qXCFShJQG/zS3kiXXev7BnQdqc0qGexxNsHo0Eb9 nI1wIdHuE7n/dAgUXrFPQdysZTxMXbYiw6ulcfp/iEMc4QsVrm0/ohCEWxscp5PoSG2d EvpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cyphar.com header.s=MBO0001 header.b=Rjz3Tj6G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cyphar.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l4-20020a17090a850400b00262ff3a4545si6841319pjn.169.2023.07.25.10.14.49; Tue, 25 Jul 2023 10:15:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cyphar.com header.s=MBO0001 header.b=Rjz3Tj6G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cyphar.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231557AbjGYQhI (ORCPT + 99 others); Tue, 25 Jul 2023 12:37:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230082AbjGYQhG (ORCPT ); Tue, 25 Jul 2023 12:37:06 -0400 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050:0:465::101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACAE610CC; Tue, 25 Jul 2023 09:37:04 -0700 (PDT) Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4R9N3J6CnSz9sd0; Tue, 25 Jul 2023 18:37:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cyphar.com; s=MBO0001; t=1690303020; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JqCAz4pT3GDUTh/C6LdHYGGzlykcrPzOPXi/2ZYbtJI=; b=Rjz3Tj6GNkJ756LoUn5njBvcsbsW0/MAqHFGq5N7S5DZflWFrn2po7Qsa2nBdkNLHPX2QN WbOZe7hgRbuHfs7lKyLUw758wTVF1+2jDq6xMeLtjMSAFOTSnglc7uLKJyCyAUZDbJP5qn WIr03ybhOR/BXivfWU8k54fCj/jkt46b7teY6si6XwQWnj/C2q4F/gk33Oq8fGPID1nU3V Fm/Rx2muN4rG5Em8xoygWv7E6rqY2XuejuMkNewe4kxYskk5tul+YgVcZYcpz78OL4DHVO pPLH6reidbUYi5iU0C947Q8MP5DncBUqNY6zptq9PlTGyGKyBOzpX+MhlLxHTg== Date: Wed, 26 Jul 2023 02:36:25 +1000 From: Aleksa Sarai To: Alexey Gladkov Cc: LKML , Arnd Bergmann , linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, James.Bottomley@hansenpartnership.com, acme@kernel.org, alexander.shishkin@linux.intel.com, axboe@kernel.dk, benh@kernel.crashing.org, borntraeger@de.ibm.com, bp@alien8.de, catalin.marinas@arm.com, christian@brauner.io, dalias@libc.org, davem@davemloft.net, deepa.kernel@gmail.com, deller@gmx.de, dhowells@redhat.com, fenghua.yu@intel.com, fweimer@redhat.com, geert@linux-m68k.org, glebfm@altlinux.org, gor@linux.ibm.com, hare@suse.com, hpa@zytor.com, ink@jurassic.park.msu.ru, jhogan@kernel.org, kim.phillips@arm.com, ldv@altlinux.org, linux-alpha@vger.kernel.org, linux-arch@vger.kernel.org, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, linux@armlinux.org.uk, linuxppc-dev@lists.ozlabs.org, luto@kernel.org, mattst88@gmail.com, mingo@redhat.com, monstr@monstr.eu, mpe@ellerman.id.au, namhyung@kernel.org, paulus@samba.org, peterz@infradead.org, ralf@linux-mips.org, sparclinux@vger.kernel.org, stefan@agner.ch, tglx@linutronix.de, tony.luck@intel.com, tycho@tycho.ws, will@kernel.org, x86@kernel.org, ysato@users.sourceforge.jp, Palmer Dabbelt Subject: Re: [PATCH v4 2/5] fs: Add fchmodat2() Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="afbbamzjyar6dsnm" Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 4R9N3J6CnSz9sd0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --afbbamzjyar6dsnm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2023-07-11, Alexey Gladkov wrote: > On the userspace side fchmodat(3) is implemented as a wrapper > function which implements the POSIX-specified interface. This > interface differs from the underlying kernel system call, which does not > have a flags argument. Most implementations require procfs [1][2]. >=20 > There doesn't appear to be a good userspace workaround for this issue > but the implementation in the kernel is pretty straight-forward. >=20 > The new fchmodat2() syscall allows to pass the AT_SYMLINK_NOFOLLOW flag, > unlike existing fchmodat. >=20 > [1] https://sourceware.org/git/?p=3Dglibc.git;a=3Dblob;f=3Dsysdeps/unix/s= ysv/linux/fchmodat.c;h=3D17eca54051ee28ba1ec3f9aed170a62630959143;hb=3Da492= b1e5ef7ab50c6fdd4e4e9879ea5569ab0a6c#l35 > [2] https://git.musl-libc.org/cgit/musl/tree/src/stat/fchmodat.c?id=3D718= f363bc2067b6487900eddc9180c84e7739f80#n28 >=20 > Co-developed-by: Palmer Dabbelt > Signed-off-by: Palmer Dabbelt > Signed-off-by: Alexey Gladkov > Acked-by: Arnd Bergmann > --- > fs/open.c | 18 ++++++++++++++---- > include/linux/syscalls.h | 2 ++ > 2 files changed, 16 insertions(+), 4 deletions(-) >=20 > diff --git a/fs/open.c b/fs/open.c > index 0c55c8e7f837..39a7939f0d00 100644 > --- a/fs/open.c > +++ b/fs/open.c > @@ -671,11 +671,11 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, = mode) > return err; > } > =20 > -static int do_fchmodat(int dfd, const char __user *filename, umode_t mod= e) > +static int do_fchmodat(int dfd, const char __user *filename, umode_t mod= e, int lookup_flags) I think it'd be much neater to do the conversion of AT_ flags here and pass 0 as a flags argument for all of the wrappers (this is how most of the other xyz(), fxyz(), fxyzat() syscall wrappers are done IIRC). > { > struct path path; > int error; > - unsigned int lookup_flags =3D LOOKUP_FOLLOW; > + > retry: > error =3D user_path_at(dfd, filename, lookup_flags, &path); > if (!error) { > @@ -689,15 +689,25 @@ static int do_fchmodat(int dfd, const char __user *= filename, umode_t mode) > return error; > } > =20 > +SYSCALL_DEFINE4(fchmodat2, int, dfd, const char __user *, filename, > + umode_t, mode, int, flags) > +{ > + if (unlikely(flags & ~AT_SYMLINK_NOFOLLOW)) > + return -EINVAL; We almost certainly want to support AT_EMPTY_PATH at the same time. Otherwise userspace will still need to go through /proc when trying to chmod a file handle they have. > + > + return do_fchmodat(dfd, filename, mode, > + flags & AT_SYMLINK_NOFOLLOW ? 0 : LOOKUP_FOLLOW); > +} > + > SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, > umode_t, mode) > { > - return do_fchmodat(dfd, filename, mode); > + return do_fchmodat(dfd, filename, mode, LOOKUP_FOLLOW); > } > =20 > SYSCALL_DEFINE2(chmod, const char __user *, filename, umode_t, mode) > { > - return do_fchmodat(AT_FDCWD, filename, mode); > + return do_fchmodat(AT_FDCWD, filename, mode, LOOKUP_FOLLOW); > } > =20 > /* > diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h > index 584f404bf868..6e852279fbc3 100644 > --- a/include/linux/syscalls.h > +++ b/include/linux/syscalls.h > @@ -440,6 +440,8 @@ asmlinkage long sys_chroot(const char __user *filenam= e); > asmlinkage long sys_fchmod(unsigned int fd, umode_t mode); > asmlinkage long sys_fchmodat(int dfd, const char __user *filename, > umode_t mode); > +asmlinkage long sys_fchmodat2(int dfd, const char __user *filename, > + umode_t mode, int flags); > asmlinkage long sys_fchownat(int dfd, const char __user *filename, uid_t= user, > gid_t group, int flag); > asmlinkage long sys_fchown(unsigned int fd, uid_t user, gid_t group); > --=20 > 2.33.8 >=20 --=20 Aleksa Sarai Senior Software Engineer (Containers) SUSE Linux GmbH --afbbamzjyar6dsnm Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQS2TklVsp+j1GPyqQYol/rSt+lEbwUCZL/6CAAKCRAol/rSt+lE b6sDAP4lsghYpoBg52FejYPCUR5VtRTHaPrZUbfu6F44pCzVHgEAjO6SIBNVvxu2 rHWRVzHnnBK8tOaeoiT0Xiex2/+5PAE= =mARF -----END PGP SIGNATURE----- --afbbamzjyar6dsnm--