Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2398218ybi; Thu, 18 Jul 2019 07:49:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqx7RNTqG/49IEWH4tVm7s3Ybef+9o6Y12HvsG2MxmsGaMd3K8285CFXvPNs7xt+Sr4mmFiT X-Received: by 2002:a17:90a:8591:: with SMTP id m17mr52299509pjn.100.1563461340518; Thu, 18 Jul 2019 07:49:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563461340; cv=none; d=google.com; s=arc-20160816; b=AyfLqkZhlCnOf5oDTmyQIvlI1AzGlBxEsGDQVyqTfryFWHaatT+Y8a59MZIwpBPQr8 LirvnhVufmqg88YQ6xYwBEo4LtL5lDB68LN2zC0RXo0UlqZ7N65VPj7WAOQYg7bCmYpx HUGvV2HJ1YIEx98GUZ9QP9NK6VJkkQrMMpoZzJscM4N4yzb/2Ez9oFZ0PT89tI760W6z 5g0Pu1+Z7HpRZCtdzyMpcBer88J2q60YHmZsHm0jk79ji3cEjadCiCqyIRU5ZWtIb25S iBXjWkD917ncs3L3YUgegL8s5QuhMfoOdQWTdQ4kByoKs/VKXsmBFrJCAJBQ8HlVijsx sQKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=qOzcTnaZtrCxVZ+wrCV9j1v3ZSJaRvDDDE3Ip4m8PX4=; b=DVEKOTVWsODaYQLyTV7XcYzMMzbqXPWEPUpVzW/OWTlnNvNNj8qXuOoIhSah8F0wkT Ohbuxy6gmGU2j9OvM6IqUdJhqFGmcuTJxLn5Hg7j0n47nFUu+chV1O4w9Dqc+nE10QiG OkrfKixZuA7SuqJUDnQaXbHMWaQVGOLOuIf53TJGIHQpuT508J/2wq4GZcS2sfk7J7Yy B7KFu4uvKL0Gs3E3E3Uut5pRDwxRyKogXK0idws7M9exFS6mCUvOORqV8dwDjfybPumU ubdW2hyS+46THwbK5FsHFk31U8gQDOg8/Ekor0CwA4HlvM4C2spfqRVbJO/F9rBxYFw7 qPMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=BvozhdyN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j192si27876863pge.393.2019.07.18.07.48.44; Thu, 18 Jul 2019 07:49:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=BvozhdyN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390725AbfGROsT (ORCPT + 99 others); Thu, 18 Jul 2019 10:48:19 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:38165 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390658AbfGROsS (ORCPT ); Thu, 18 Jul 2019 10:48:18 -0400 Received: by mail-lj1-f194.google.com with SMTP id r9so27632792ljg.5 for ; Thu, 18 Jul 2019 07:48:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=qOzcTnaZtrCxVZ+wrCV9j1v3ZSJaRvDDDE3Ip4m8PX4=; b=BvozhdyNjQm5IKs1TT9YoWn3Ui6wySHrveALu6p1t7AtDp7QFxBLfHh88f5ww+lLJn uwy3k971xxqR/HSbz4pAOIhSLMVdxGZ//qhiRBmEGbP5iSimOi3DrF8NmakZGMPtS2dX 7klk9Axk//12MJN1Z1lHBXwZgwDxdfLj6taYs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qOzcTnaZtrCxVZ+wrCV9j1v3ZSJaRvDDDE3Ip4m8PX4=; b=fKchHIc+pCjc38AYZ5wivTmF4zRY/8tU1eW7Mheo/c4eNIMLigHrt6uYIW2xmHDeEN /XJE2013XkP2rSW1TB6liIjhshpxYY626of0loeZ3l4HYniZjemzUAj7hBdK23phIZn/ 5CCWHJGYVUQEUfmLqqC4ws0NKYwq8rH3llwTG5SsxPmTDIWoWRpv/4m1RQAPpqbwSm7o 3EZg1J8kjLhcqO4l9mIEw8xl6YKE1xNv05oNmw6Kqb/OkgP7Wr91dTUQ+zrmn6IChclE A3wbHabf1SlVnxDlDSlysYlk5pyktzmOxTaWJA99qHunYyLNP/SslRf0A0mlDHieHxcf JB7g== X-Gm-Message-State: APjAAAWOeqdbsktd6bNsVsyovukkd7VG+jVDK5I6V/I1tw/R/rM34MOP CINn80M7kGLTxywv+xxwLc4= X-Received: by 2002:a05:651c:d1:: with SMTP id 17mr24822389ljr.174.1563461295757; Thu, 18 Jul 2019 07:48:15 -0700 (PDT) Received: from [172.16.11.28] ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id t4sm5672901ljh.9.2019.07.18.07.48.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jul 2019 07:48:15 -0700 (PDT) Subject: Re: [PATCH v9 08/10] open: openat2(2) syscall To: Aleksa Sarai , Al Viro , Jeff Layton , "J. Bruce Fields" , Arnd Bergmann , David Howells , Shuah Khan , Shuah Khan Cc: Christian Brauner , Eric Biederman , Andy Lutomirski , Andrew Morton , Alexei Starovoitov , Kees Cook , Jann Horn , Tycho Andersen , David Drysdale , Chanho Min , Oleg Nesterov , Aleksa Sarai , Linus Torvalds , containers@lists.linux-foundation.org, linux-alpha@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, linux-xtensa@linux-xtensa.org, sparclinux@vger.kernel.org References: <20190706145737.5299-1-cyphar@cyphar.com> <20190706145737.5299-9-cyphar@cyphar.com> From: Rasmus Villemoes Message-ID: <845e4364-685f-343b-46fb-c418766dce3e@rasmusvillemoes.dk> Date: Thu, 18 Jul 2019 16:48:12 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20190706145737.5299-9-cyphar@cyphar.com> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/07/2019 16.57, Aleksa Sarai wrote: > > --- a/fs/open.c > +++ b/fs/open.c > @@ -928,24 +928,32 @@ struct file *open_with_fake_path(const struct path *path, int flags, > } > EXPORT_SYMBOL(open_with_fake_path); > > -static inline int build_open_flags(int flags, umode_t mode, struct open_flags *op) > +static inline int build_open_flags(struct open_how how, struct open_flags *op) > { How does passing such a huge struct by value affect code generation? Does gcc actually inline the function (and does it even inline the old one given that it's already non-trivial and has more than one caller). > int lookup_flags = 0; > - int acc_mode = ACC_MODE(flags); > + int opath_mask = 0; > + int acc_mode = ACC_MODE(how.flags); > + > + if (how.resolve & ~VALID_RESOLVE_FLAGS) > + return -EINVAL; > + if (!(how.flags & (O_PATH | O_CREAT | __O_TMPFILE)) && how.mode != 0) > + return -EINVAL; > + if (memchr_inv(how.reserved, 0, sizeof(how.reserved))) > + return -EINVAL; How about passing how by const reference, and copy the few fields you need to local variables. That would at least simplify this patch by eliminating a lot of the > - flags &= VALID_OPEN_FLAGS; > + how.flags &= VALID_OPEN_FLAGS; > > - if (flags & (O_CREAT | __O_TMPFILE)) > - op->mode = (mode & S_IALLUGO) | S_IFREG; > + if (how.flags & (O_CREAT | __O_TMPFILE)) > + op->mode = (how.mode & S_IALLUGO) | S_IFREG; churn. > > diff --git a/include/linux/fcntl.h b/include/linux/fcntl.h > index 2868ae6c8fc1..e59917292213 100644 > --- a/include/linux/fcntl.h > +++ b/include/linux/fcntl.h > @@ -4,13 +4,26 @@ > > #include > > -/* list of all valid flags for the open/openat flags argument: */ > +/* Should open_how.mode be set for older syscalls wrappers? */ > +#define OPENHOW_MODE(flags, mode) \ > + (((flags) | (O_CREAT | __O_TMPFILE)) ? (mode) : 0) > + Typo: (((flags) & (O_CREAT | __O_TMPFILE)) ? (mode) : 0) > +/** > + * Arguments for how openat2(2) should open the target path. If @extra is zero, > + * then openat2(2) is identical to openat(2). > + * > + * @flags: O_* flags (unknown flags ignored). > + * @mode: O_CREAT file mode (ignored otherwise). should probably say "O_CREAT/O_TMPFILE file mode". > + * @upgrade_mask: restrict how the O_PATH may be re-opened (ignored otherwise). > + * @resolve: RESOLVE_* flags (-EINVAL on unknown flags). > + * @reserved: reserved for future extensions, must be zeroed. > + */ > +struct open_how { > + __u32 flags; > + union { > + __u16 mode; > + __u16 upgrade_mask; > + }; > + __u16 resolve; So mode and upgrade_mask are naturally u16 aka mode_t. And yes, they probably never need to be used together, so the union works. That then makes the next member 2-byte aligned, so using a u16 for the resolve flags brings us to an 8-byte boundary, and 11 unused flag bits should be enough for a while. But it seems a bit artificial to cram all this together and then add 56 bytes of reserved space. Rasmus