Received: by 2002:ac8:156:0:b0:3e0:cd10:60c8 with SMTP id f22csp1545144qtg; Tue, 21 Mar 2023 14:53:53 -0700 (PDT) X-Google-Smtp-Source: AK7set873yKMHSahvN9KN0DES89/xbF/k8nFzfO6Nkq8ObrULo2S9XjGB/17YLLvivJSzybUlPle X-Received: by 2002:a17:902:ceca:b0:1a1:d395:e85c with SMTP id d10-20020a170902ceca00b001a1d395e85cmr3844278plg.0.1679435632946; Tue, 21 Mar 2023 14:53:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679435632; cv=none; d=google.com; s=arc-20160816; b=jrkIlkJFomsXoBEpQhIzgBQX/6UqE1m0vD8utEbWw50xuDQNMRyB68aEClv3GosuUx 5io76M9FIB2vPfwEOBTu9bpFq3QxYSDig0UGdOdnt4Sl6zHALgDD+ak3JcilLEBGaapj l80fnGMNE0forA+vt7VrZHDB5KHNOlxg7IWRtZ1CGFo/dJK8TycCcGt0Hp36PQkulobW 6OFBp391MT7k3fVpefKrfOVNvuYWJBJqXGnS5ku7uWePH0rkzxsOX/ZvYLd8/5GLOzrz ku3XY5poHLVPOXnL6+VIFVdyl3DQZgcQsXSifZxYxjelw6eHoaF+RWkN6pbzWIrGfmic cRHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=5xh3paPfK126WRaNNgpf/HW2EljH41BR2zEW9a9muNk=; b=zaei6lJqnGR9b40V46Ms79Yyr/RgPR8MhcWd08N+m0ZxqV1jlXp4V2dgKZ6pAdM/WK SGw8jUYvcM+/xpm6l0tCMTkEXbQNt4f+YuH7JCncLsFN/kR46yKpL+0IxFXx3WnLH5RG 0uE4IsxJfickyLfnium5s4k1h/+DFpYultDfMqQWVp+5sFK7D3r0iTTSRO/dMpPBdsPG tjwftdATmyunFGrcRqh7za2Zd2tJF4w6DzlOijXbIooJaRVu8zSyI6Z43lu4r1bGib3p +oZAt2Fa0kyQdjOdadROYV09YSfJ+VxxUTa9uC5bl6MdMtynDpVCrVrHOpnwVvA17PtY OT/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=EFxwAMPN; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n8-20020a170902d2c800b0019a95ab6b4esi15940593plc.407.2023.03.21.14.53.36; Tue, 21 Mar 2023 14:53:52 -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=@linux-foundation.org header.s=google header.b=EFxwAMPN; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229757AbjCUVsR (ORCPT + 99 others); Tue, 21 Mar 2023 17:48:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229484AbjCUVsQ (ORCPT ); Tue, 21 Mar 2023 17:48:16 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D11D1B320 for ; Tue, 21 Mar 2023 14:48:15 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id x3so65234396edb.10 for ; Tue, 21 Mar 2023 14:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1679435293; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=5xh3paPfK126WRaNNgpf/HW2EljH41BR2zEW9a9muNk=; b=EFxwAMPN5TNr9d2A4kweGJd3JvbAXyVvHd2P4P/SPMq8eJwqHtiU2c608UDjkDSyrz wR9OSjQqsgjrMn3V2brzMT7hrk3n7WySExiC0d5PdJqq8l2DHGZB+gq0rlaX1KwB/rmM fpNw9bEhzSMSgl0yKzTNbCiUhYXsAohTsLFDE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679435293; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5xh3paPfK126WRaNNgpf/HW2EljH41BR2zEW9a9muNk=; b=Le9brL+SYCygnwnjNu/0T8/1V8hL8OpcKZxdw16TToRvMV8kZT/KHoPdA1vGKn3FF0 HyB2tJ8bjCWPVInBK4l4gJ9yK7QcJae0PAHBpkrxZ+LJRm0Q9cBs4yGg+l7rH2a9csCF iAz7+GEVxwY+L1Dhz8dLaNUSUp/d2uScNi6/JRvhd74DoNY7MZylkHDyUpB48EWZk8Ov GuK6x2hf9mcsly6k02bdT2vqyrW5RXHTV4WywoRYtJg2g3tpMsSjCtTidvlu58h4Q8k3 HwWn306D+dk3kUZHF3Sgd4d6RfnJ6G9eYjps8wshxUC2Zy5/1ns2hgRND0eujjeL4U7e x9/g== X-Gm-Message-State: AO0yUKXEiV/s3/agDp6pDQE+VrFpAtsYAlEwsrasxU2oWEekqOQ1/dNQ E8vt1pMGInui3dUpbHrMzaN4qF31tpSJkOannMPBjtRU X-Received: by 2002:a17:907:2da0:b0:939:ad91:adf5 with SMTP id gt32-20020a1709072da000b00939ad91adf5mr5775912ejc.25.1679435293279; Tue, 21 Mar 2023 14:48:13 -0700 (PDT) Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com. [209.85.208.45]) by smtp.gmail.com with ESMTPSA id v15-20020a170906858f00b0093229e527cdsm5845308ejx.42.2023.03.21.14.48.12 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Mar 2023 14:48:12 -0700 (PDT) Received: by mail-ed1-f45.google.com with SMTP id o12so65269370edb.9 for ; Tue, 21 Mar 2023 14:48:12 -0700 (PDT) X-Received: by 2002:a17:906:b28e:b0:935:3085:303b with SMTP id q14-20020a170906b28e00b009353085303bmr2028336ejz.15.1679435291907; Tue, 21 Mar 2023 14:48:11 -0700 (PDT) MIME-Version: 1.0 References: <20230320071442.172228-1-pedro.falcato@gmail.com> <20230320115153.7n5cq4wl2hmcbndf@wittgenstein> <20230321142413.6mlowi5u6ewecodx@wittgenstein> <20230321161736.njmtnkvjf5rf7x5p@wittgenstein> <20230321201632.o2wiz5gk7cz36rn3@wittgenstein> In-Reply-To: <20230321201632.o2wiz5gk7cz36rn3@wittgenstein> From: Linus Torvalds Date: Tue, 21 Mar 2023 14:47:55 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] do_open(): Fix O_DIRECTORY | O_CREAT behavior To: Christian Brauner Cc: Pedro Falcato , Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Aleksa Sarai Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 Tue, Mar 21, 2023 at 1:16=E2=80=AFPM Christian Brauner wrote: > > But yes, that is a valid complaint so - without having tested - sm like: I'd actually go a bit further, and really spell all the bits out explicitly= . I mean, I was *literally* involved in that original O_TMPFILE_MASK thing: https://lore.kernel.org/all/CA+55aFxA3qoM5wpMUya7gEA8SZyJep7kMBRjrPOsOm_= OudD8aQ@mail.gmail.com/ with the whole O_DIRECOTY games to make O_TMPFILE safer, but despite that I didn't remember this at all, and my suggested "maybe something like this" patch was broken for the O_TMPFILE case. So while we do have all this documented in our history (both git commit logs and lore.kernel.org), I actually think it would be lovely to just make build_open_flags() be very explicit about all the exact O_xyz flags, and really write out the logic fully. For example, even your clarified version that gets rid of the "O_TMPFILE_MASK" thing still eends up doing if (flags & __O_TMPFILE) { if ((flags & O_TMPFILE) !=3D O_TMPFILE) return -EINVAL; and so when you look at that code, you don't actually realize that O_TMPFILE _cotnains_ that __O_TMPFILE bit, and what the above really means is "also check O_DIRECTORY". So considering how I couldn't remember this mess myself, despite having been involved with it personally (a decade ago..), I really do think that maybe this shoudl be open-coded with a comment, and the above code should instead be if (flags & __O_TMPFILE) { if (!(flags & O_DIRECTORY)) return -EINVAL; together with an explicit comment about how O_TMPFILE is the *combination* of __O_TMPFILE and O_DIRECTORY, along with a short explanation as to why. Now, I agree that that test for O_DIRECTORY then _looks_ odd, but the thing is, it then makes the reality of this all much more explicit. In contrast, doing that if ((flags & O_TMPFILE) !=3D O_TMPFILE) may *look* more natural in that context, but if you actually start thinking about it, that check makes no sense unless you then look up what O_TMPFILE is, and the history behind it. So I'd rather have code that looks a bit odd, but that explains itself and is explicit about what it does, than code that _tries_ to look natural but actually hides the reason for what it is doing. And then next time somebody looks at that O_DIRECTORY | O_CREAT combination, suddenly the __O_TMPFILE interaction is there, and very explicit. Hmm? I don't feel *hugely* strongly about this, so in the end I'll bow to your decision, but considering that my initial patch looked sane but was buggy because I had forgotten about O_TMPFILE, I really think we should make this more explicit at a source level.. Linus Linus