Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1436503rwb; Thu, 19 Jan 2023 10:33:34 -0800 (PST) X-Google-Smtp-Source: AMrXdXu8R3QbN8u8+lvz1AzZ1JmxYpCgSAjIRTZDxEAbKOK6cnGpqiWYxsRjMnlgXmfYsNQ8s3sb X-Received: by 2002:a17:902:8d8e:b0:194:9324:7084 with SMTP id v14-20020a1709028d8e00b0019493247084mr11801947plo.36.1674153214307; Thu, 19 Jan 2023 10:33:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674153214; cv=none; d=google.com; s=arc-20160816; b=pC6E6la2QzFrmMjAQ8zoYWrnRQUnuBi5TCxCj6gEsIn65fw2UwFUXqOjRTbHHES30d qN3lqYNJvX460jRCsjObs9TlZ9ldfSF8RKEi4ZlRFMgw3ltUzFawZWQwV5vB/NeThoCo UKJ0lfpHiagMD6rakJ3if349h2zfC5gyoiCtYpmF0UICxfGhO/keK7z0tg4D6VzaGqhA jwAmpeGokJHignKBoryPKFtjBs2SL2pFe5MU7gaIjSdSAL9X8slhbx82BNnq7j22SJ+M Z/winkMqVj9fwlqs1hEwd4H77XkIirljvp8I5uWw9fdKXeDsBvSkuU5aApsgAgGGIuAt pCjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=BVU3lcJ1W9NU2wT8Hm8eV0/TWVb/x/i77jlSHkdBSX0=; b=f5idZyAgZiJbGLeKPnNkTw5csoBYP7ovPDl0lEFj1Go5kNR0Q5UWmi+Iv0aljr7Yb1 6w86GYSVqxamNIkIkzO1f057dJA0yyX/8o8Xbsha3l5OMlpNWChBuQrcE3uzwENwXpKj lEt46IHHgQ6IAbQ3Mt1vKB9D1Gw9bcuwPe+nTMQ+VIIDlfpGT0sVWqTD4CZkV0Ydx1Q8 1D/dxjXhXHUkdzb6r1xDkm1w9EJmDzVX00fGBNQN5aXcrWHEXtGEgzD3m0xtPFhXYtuI Fq7I30F6cIyl61jcpE3hXjGTdCCogVLhOBz0BgQZH05YkgE88lf+KpDU2A7mz4ExSk+A H0CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=X8uOxnpc; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-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 w4-20020a170902e88400b0018958008877si43876087plg.39.2023.01.19.10.33.11; Thu, 19 Jan 2023 10:33:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-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=X8uOxnpc; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229712AbjASSYj (ORCPT + 99 others); Thu, 19 Jan 2023 13:24:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229689AbjASSYi (ORCPT ); Thu, 19 Jan 2023 13:24:38 -0500 Received: from mail-vs1-xe2b.google.com (mail-vs1-xe2b.google.com [IPv6:2607:f8b0:4864:20::e2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65BA97C844 for ; Thu, 19 Jan 2023 10:24:37 -0800 (PST) Received: by mail-vs1-xe2b.google.com with SMTP id d66so3070695vsd.9 for ; Thu, 19 Jan 2023 10:24:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=BVU3lcJ1W9NU2wT8Hm8eV0/TWVb/x/i77jlSHkdBSX0=; b=X8uOxnpcOYcn+tIHKB6hg729w4beVgxFLf5xAktSPr4Em61svIdbOxlVLaqSvYF6TT H3vf3deBuCDnLIkUBMyf3mZzOoW1yIyKjkwKbbSKAygRRuobaWMlvDYuAK8EjfwMJCt2 c5Q/qDF8rOdmFFwzp80BEOyX7vvIv0SYf8ekc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=BVU3lcJ1W9NU2wT8Hm8eV0/TWVb/x/i77jlSHkdBSX0=; b=702kV+tTZX3d1+sse62zrlI3BUI/QZuQ5QHu2SvInCRvKlo4vFcXZEXQE+BNbEksZ+ R2dsrebMOOe9SAYnJ9ZWbzhKptIOWUFGQo5oG5+GQZGkbrgVtgeRjRDSK/lifA7xhiH0 oqz3kJLzTXyTl1p3Kxf3rZ4yNEwEQyWyC6s3r9cQyiCcOy9MFW71B5T4IpHo9lNBsYNV bDzhxCA9mMssctXcJglUByNhYF5FADcJWV5n3wblWuiaJ/yRX7Op10qoz/s7BoTJFT7J SDvj5N0iUsM1UCwuGah79iSSDqLxyCOW1ZPahDZW9eRVbyGRFR1g82vGhIQshenI1OKz 0CjQ== X-Gm-Message-State: AFqh2konXTrp8DazzcgrEFQP3XdguxRNoCvFy4FoWH+EiP8lhSYKrcSN 3HzIzJ4XmuiT8so01D/89d6bwibi0bUx5agm X-Received: by 2002:a05:6102:7d1:b0:3d4:540:785a with SMTP id y17-20020a05610207d100b003d40540785amr7448042vsg.19.1674152676211; Thu, 19 Jan 2023 10:24:36 -0800 (PST) Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com. [209.85.222.179]) by smtp.gmail.com with ESMTPSA id l13-20020a05620a28cd00b0070531c5d655sm2261587qkp.90.2023.01.19.10.24.35 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Jan 2023 10:24:35 -0800 (PST) Received: by mail-qk1-f179.google.com with SMTP id d13so1600257qkk.12 for ; Thu, 19 Jan 2023 10:24:35 -0800 (PST) X-Received: by 2002:ae9:efd8:0:b0:706:e593:2598 with SMTP id d207-20020ae9efd8000000b00706e5932598mr197935qkg.216.1674152674832; Thu, 19 Jan 2023 10:24:34 -0800 (PST) MIME-Version: 1.0 References: <7DE6598D-B60D-466F-8771-5FEC0FDEC57F@dilger.ca> <3A9E6D2E-F98F-461C-834D-D4E269CC737F@dilger.ca> In-Reply-To: <3A9E6D2E-F98F-461C-834D-D4E269CC737F@dilger.ca> From: Linus Torvalds Date: Thu, 19 Jan 2023 10:24:18 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Detecting default signedness of char in ext4 (despite -funsigned-char) To: Andreas Dilger Cc: "Theodore Ts'o" , Eric Biggers , Ext4 Developers List , Eric Whitney , "Jason A. Donenfeld" , Masahiro Yamada Content-Type: multipart/mixed; boundary="0000000000007c12fc05f2a20bc5" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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-ext4@vger.kernel.org --0000000000007c12fc05f2a20bc5 Content-Type: text/plain; charset="UTF-8" On Wed, Jan 18, 2023 at 2:20 PM Andreas Dilger wrote: > > It makes sense to use the existing UNSIGNED/SIGNED flag in the superblock > for the dir hash also for the xattr hash. No. As Eric says, the existing flag for this - while related to a very similar issue - just doesn't work. It's for a different hash, and the flag has been set (or not) based on previous history of that particular filesystem that isn't necessarily at all relevant. The "signedness" of the xattrs hash simply doesn't necessarily match the signedness of the existing flag. Also, honestly, it's just entirely POINTLESS. Here's the deal: these kinds of flags simply SHOULD NOT EXIST. A filesystem that has dynamic byte order flags is an INCOMPETENT filesystem. Yes, I know they exist. The people involved should be ashamed of them. For things like byte order flags, it's simply unambiguously better to just have an unconditional on-disk byte order, even when that byte order doesn't match the "native" byte order of the machine. Doing an unconditional 'bswap' operation is literally smaller, simpler and faster than conditionally doing nothing, and makes for much easier verification (because you can use static typing rules, like we use for "__le32" and types like that). The EXACT same thing is true of architecture-specific signedness. Yes, you can add flags to dynamically choose one or the other, but that's actively *worse* then just picking one statically and saying "this is the correct one". And honestly, the unsigned version was always the correct one. It's not even half-way ambiguous like the whole little-endian vs big-endian discussion used to be. In this very thread Ted made clear that he hadn't even realized that this signed case could happen and would matter. The signed case is surprising and unintentional. So, given that (a) it's just a *fact* that the static choice is better (b) of the two choices, one is clearly correct I'm just going to put my foot down and say that right way forward is clearly to just make that be the de-facto rule. And honestly, it's the simpler patch too, since "-funsigned-char" has already done all the actual "pick the right hash" for us. We have four levels of "how much do we care" and simplicity: (1) do nothing, see if anybody actually ever notices outside of generic/454 (2) just remove the hash check entirely, it's not doing anything semantically meaningful (3) keep the hash check, replace the "return -EFSCORRUPTED" with a "pr_warn_once()" and returning zero (4) the "keep the hash check, if it fails, test it the other way, always write the correct new hash" patch I already posted but the thing I refuse to do is to either just maintain the bug as-is with extra complexity (Eric's patch) or add a new flag (or erroneously re-use an existing flag) to make it dynamic. The e2fsck argument is bugus, because *every* case requires e2fsck changes. Even if we maintain the completely bogus historical behavior of "the on-disk filesystem representation depends on architecture", e2fsck had better start warning about it. And again, I guarantee that the "fix the signedness" is the simpler thing even for e2fsck, since at least then there is one unambiguously correct version and one incorrect one, instead of some wishy-washy "oh, this filesystem is correct for *THESE* architectures". I'm attaching my suggested patch here again - this time with a commit message - because while I'm ok with any of options 1-4 above, I already wrote the patch for the most complicated case, and it's not *that* complex. We could possibly add a "pr_warn_once()" so that we have a combination of (3) and (4). In the longer term, we should (a) remove the #ifdef __CHAR_UNSIGNED__ in ext4 as always true (happily, I grepped - it's the only case in the whole source tree) (b) probably plan on _eventually_ just remove my disgusting "calculate signed version" thing, once we think it's all blown over and we have never seen one of those pr_warn_on() messages outside of generic/454 but I *really* don't want to add some new filesystem flag to deal with this situation when a non-flag version is just simpler. Hmm? Linus --0000000000007c12fc05f2a20bc5 Content-Type: text/x-patch; charset="US-ASCII"; name="0001-ext4-deal-with-legacy-signed-xattr-name-hash-values.patch" Content-Disposition: attachment; filename="0001-ext4-deal-with-legacy-signed-xattr-name-hash-values.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_ld3f8yay0 RnJvbSBhOWMwYWUyODYzODc1NDQ2ZmEzZDAwZWRhZTJjY2FkNGRhNzVmZWI1IE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBMaW51cyBUb3J2YWxkcyA8dG9ydmFsZHNAbGludXgtZm91bmRh dGlvbi5vcmc+CkRhdGU6IFRodSwgMTkgSmFuIDIwMjMgMDk6NTA6MzggLTA4MDAKU3ViamVjdDog W1BBVENIXSBleHQ0OiBkZWFsIHdpdGggbGVnYWN5IHNpZ25lZCB4YXR0ciBuYW1lIGhhc2ggdmFs dWVzCgpXZSBwb3RlbnRpYWxseSBoYXZlIG9sZCBoYXNoZXMgb2YgdGhlIHhhdHRyIG5hbWVzIGdl bmVyYXRlZCBvbiBzeXN0ZW1zCndpdGggc2lnbmVkICdjaGFyJyB0eXBlcy4gIE5vdyB0aGF0IGV2 ZXJ5Ym9keSB1c2VzICctZnVuc2lnbmVkLWNoYXInLAp0aG9zZSBoYXNoZXMgd2lsbCBubyBsb25n ZXIgbWF0Y2guCgpUaGlzIG9ubHkgaGFwcGVucyBpZiB5b3UgdXNlIHhhdHRycyBuYW1lcyB0aGF0 IGhhdmUgdGhlIGhpZ2ggYml0IHNldCwKd2hp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