Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1335614pxk; Thu, 10 Sep 2020 12:50:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8HnRwRy0RjnXY9Bpje/eijG7Zq4lurUhFxeVig0DpjoHpBnJxAPx77t83gZPd9u10Zvn7 X-Received: by 2002:aa7:c053:: with SMTP id k19mr10813974edo.326.1599767415153; Thu, 10 Sep 2020 12:50:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599767415; cv=none; d=google.com; s=arc-20160816; b=nLdU2MVyQHrKz2y8OSEn9csVUZUU4AtTp70fu3oc7LyWK+bdCageIYBXJ457WePgb1 YOqLKAtDAuEyxC0HpuS0jGMD0j0G8UArgscy26c2deRPqBMBqCNcWz3qy2GTSYeJCjpM AbIVRo3lGhkSaZ41r3a1PIspAJO0MZtR3Wrv7pE8LWHil8Bw/El97Y4AJiZQFpGTkve7 g4danvz1SDMpoiEUk+k36UDRekRCm8X10wLLwL/Omg9DyrUJrq4uImbcBrnAhz2ET74y ben0XCZVJgtklLPGLmFH7xesEi0WVTajcWFU8CKEnCaRwhHhrShS84kKrppz2lqvQTGg V9SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:mime-version:accept-language:in-reply-to :references:message-id:date:thread-index:thread-topic:subject:cc:to :from; bh=oXH+StdhZFqqhgFdaM4NJcHYRFP0LLwj8+b2nL9X3z4=; b=I70pczRfbTMP45Wx9D5zrv5kAVSL3eyAMMsbdJ4eWnuKve1xxKEuChoNQTtIm9h3IT DHHm5ueuYfPo5nRO6qdFv8CleXHevIF3MANO3qcHG+cOb3SZmPRHV5U3WdyKD6eEB+cr JxEOsMUgsR8K0tprQ7YuMddnJgxZnaUWh09nUJk8cdu0mefBQg/9aD+X3n1AK0vNeJ/D bxfxNWyHhA/JaQbqJ/Mwl9kxFUbY5gMjatbE/LJ6R+1ZAJsrD9jKhTSgOyEKXQt8k22v Wr/Gwm3KBhVI9GtSnoXUdG7/X8bkOn/zL9b2+78H6ON1ocKUU0SUAshyfKKStgBXoZti 8CiQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mh15si4307906ejb.389.2020.09.10.12.49.52; Thu, 10 Sep 2020 12:50:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726802AbgIJTrX convert rfc822-to-8bit (ORCPT + 99 others); Thu, 10 Sep 2020 15:47:23 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([207.82.80.151]:44044 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731268AbgIJPZO (ORCPT ); Thu, 10 Sep 2020 11:25:14 -0400 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-193-SwYyQJkFN1CKNX6P6arlLA-1; Thu, 10 Sep 2020 16:23:41 +0100 X-MC-Unique: SwYyQJkFN1CKNX6P6arlLA-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Thu, 10 Sep 2020 16:23:40 +0100 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Thu, 10 Sep 2020 16:23:40 +0100 From: David Laight To: 'Rich Felker' , "linux-api@vger.kernel.org" CC: Alexander Viro , "linux-fsdevel@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH] vfs: add fchmodat2 syscall Thread-Topic: [PATCH] vfs: add fchmodat2 syscall Thread-Index: AQHWh4NogO4zJqm73EG5GUWCltp+Valh+9/A Date: Thu, 10 Sep 2020 15:23:40 +0000 Message-ID: <1111806ca0344527a8855616e46346c5@AcuMS.aculab.com> References: <20200910142335.GG3265@brightrain.aerifal.cx> In-Reply-To: <20200910142335.GG3265@brightrain.aerifal.cx> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: aculab.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rich Felker > Sent: 10 September 2020 15:24 ... > index 9af548fb841b..570a21f4d81e 100644 > --- a/fs/open.c > +++ b/fs/open.c > @@ -610,15 +610,30 @@ 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 flags) > { > struct path path; > int error; > unsigned int lookup_flags = LOOKUP_FOLLOW; > + > + if (flags & AT_SYMLINK_NOFOLLOW) > + lookup_flags &= ~LOOKUP_FOLLOW; > + if (flags & ~AT_SYMLINK_NOFOLLOW) > + return -EINVAL; I think I'd swap over those two tests. So unsupported flags are clearly errored. > retry: > error = user_path_at(dfd, filename, lookup_flags, &path); > if (!error) { > - error = chmod_common(&path, mode); > + /* Block chmod from getting to fs layer. Ideally the > + * fs would either allow it or fail with EOPNOTSUPP, > + * but some are buggy and return an error but change > + * the mode, which is non-conforming and wrong. > + * Userspace emulation of AT_SYMLINK_NOFOLLOW in > + * glibc and musl blocked it too, for same reason. */ > + if (S_ISLNK(path.dentry->d_inode->i_mode) > + && (flags & AT_SYMLINK_NOFOLLOW)) > + error = -EOPNOTSUPP; Again swap the order of the tests. I think it reads better as: if ((flags & AT_SYMLINK_NOFOLLOW) && S_ISLNK(path.dentry->d_inode->i_mode)) error = -EOPNOTSUPP; As well as saving a few clock cycles. > + else > + error = chmod_common(&path, mode); > path_put(&path); > if (retry_estale(error, lookup_flags)) { > lookup_flags |= LOOKUP_REVAL; ... David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)