Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1068402rwb; Wed, 26 Jul 2023 07:10:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlFoMey6glT1DBUlnTtv4ck3Z1hL+LvWKS+eIcAWen4vvhsJomZcN6VVjUDzNvXCCD3pqcfE X-Received: by 2002:a05:6a00:c93:b0:673:aca1:a0b0 with SMTP id a19-20020a056a000c9300b00673aca1a0b0mr2882116pfv.3.1690380655195; Wed, 26 Jul 2023 07:10:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690380655; cv=none; d=google.com; s=arc-20160816; b=FVG6u/PoBmOpZroMsyde6RCCfec3KeR9IWu911g3N1uxMyUEFuBgespskjAAQytmjB /2tMSouxZqtKxYDT1b6aVlzNcd7//B7NOMUeKs1VbJ2cTK72o1vgqV283Gj0QlYpCdX+ 4fuFNUAv2jeeAhgg8QLXN+a+bdq81xeFtPAN6TN6fm/KUfIv/QblCqmABZKtJA34KO0y yCdMeYCYs/Sd1iuf4ioyiyU86H/JGjzLlAzBTZgyZ02o7/R76dxSlKohmJgZgsztunLz XERnMn/3yVuKijPMaVPK5VG8WsZRq0jd73v47RuOhcn/z7+aVwex3m2b2PHSjwdlYcYR +7Uw== 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=2eFF44jzsdjZDZs+WxT9rM/paTkBj5qL1+VxlAPDoM4=; fh=VfDA4VFxA2bjmAGaP7S3zg4KL07NQ4wuXMcs9fV3DYI=; b=JP3ZrE+DaDFCXeofG7jwhQcKbHAZcV0NP0UgwLbjLYTyLLp0HXrVJnLGVtOCYPkQG1 H1qUPZsKwCPWXvxEMiEfeJqzduTc7krLstduu7pg00rcWj/aMlVFIsmy6uvdv+NwLgQz xeuDjoum6Owp0yk+jIJmAX7aWlHT2WnTvQ5X4XjXEvPDodVOz4WQdVFQYNMoRK7xJ1Z3 XMYnuTDCNFAfyw3mdBQELqXo+v0Hbs9D6qGOIc+1whynVNRVZ+Dxm0KVFN0jDFZh0gqr EEOwcFM5hadUmECRkFZb7CauLoJLd8HA2ZQNNh9sESjLcnzR30e3AK3uS1ePofzE88ew iiAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="iLrm54/O"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n6-20020a63e046000000b0055ace8caef9si13168524pgj.309.2023.07.26.07.10.40; Wed, 26 Jul 2023 07:10:55 -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=@kernel.org header.s=k20201202 header.b="iLrm54/O"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233052AbjGZNqP (ORCPT + 99 others); Wed, 26 Jul 2023 09:46:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232971AbjGZNqN (ORCPT ); Wed, 26 Jul 2023 09:46:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A72712C; Wed, 26 Jul 2023 06:46:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id ECB1D61A4F; Wed, 26 Jul 2023 13:46:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31A6EC433C7; Wed, 26 Jul 2023 13:46:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690379171; bh=YMmxomfMr9G4i/xBDFo8a+tJ6BzX3X5lQtLwpyL37dM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=iLrm54/OyVAkeX7XRTdQI6vJKk7fvA9E8WFuxeM1GUgON2oCeY1wjM8yTYrtIi4IQ Oo3FMgcMnRzknsY84kWAeTJ0inxm7fg97Q/tOUTzG6ZMmI5ATwnzUC945HbXcM2RRW HKanW7qmiSF3lCZhc3wQfBbpJJOtev2Fm0SsXZJptqvFFvEwrKyC1aKGldedLK/9Vz 62DImdurXvwbmhgOteOs/aXLApFhcpwiLDIG+sQUeQFLsagl1k2OVSVn88v78BFAcl Vj6NEoPbw1eyE9ZIq7xYhoiahGzuo+q0Lii/UprIQXPLwFPgjeIIKj3g1kimIqX0ng b/060n7yg03AQ== Date: Wed, 26 Jul 2023 15:45:56 +0200 From: Alexey Gladkov To: Aleksa Sarai 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: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 On Wed, Jul 26, 2023 at 02:36:25AM +1000, Aleksa Sarai wrote: > 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]. > > > > There doesn't appear to be a good userspace workaround for this issue > > but the implementation in the kernel is pretty straight-forward. > > > > The new fchmodat2() syscall allows to pass the AT_SYMLINK_NOFOLLOW flag, > > unlike existing fchmodat. > > > > [1] https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/fchmodat.c;h=17eca54051ee28ba1ec3f9aed170a62630959143;hb=a492b1e5ef7ab50c6fdd4e4e9879ea5569ab0a6c#l35 > > [2] https://git.musl-libc.org/cgit/musl/tree/src/stat/fchmodat.c?id=718f363bc2067b6487900eddc9180c84e7739f80#n28 > > > > 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(-) > > > > 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; > > } > > > > -static int do_fchmodat(int dfd, const char __user *filename, umode_t mode) > > +static int do_fchmodat(int dfd, const char __user *filename, umode_t mode, 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). I just addressed the Al Viro's suggestion. https://lore.kernel.org/lkml/20190717014802.GS17978@ZenIV.linux.org.uk/ > > { > > struct path path; > > int error; > > - unsigned int lookup_flags = LOOKUP_FOLLOW; > > + > > retry: > > error = 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; > > } > > > > +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. I'm not sure I understand. Can you explain what you mean? -- Rgrds, legion