Received: by 2002:a05:6512:3d0e:0:0:0:0 with SMTP id d14csp21028lfv; Tue, 12 Apr 2022 15:33:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUEPTNihvc/S/xyjgDyXEy1fnUsXnW/k0FFZCCq+boGWzBfJOrSJTGUTFx1+pVGK6Byk4M X-Received: by 2002:a05:6a02:283:b0:342:703e:1434 with SMTP id bk3-20020a056a02028300b00342703e1434mr31986398pgb.74.1649802818938; Tue, 12 Apr 2022 15:33:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649802818; cv=none; d=google.com; s=arc-20160816; b=I9vzdIHb9pOvqaXcmTYwKkiWsMVL3HoCg7P9LvMdlgoz2JKLW6SB6XJCcy/FyArggf Jd0u82q211/VOKbu2IlGi7z8yLM/QpYhjw+nSc7Ij2A2oft5R3sOWUiEY+GHy/lRmpBv voKQ5P9pVy117/Eb1sTXjlbqyZ6Ognk9vsZLNufLVn/JXxfwJiJmqgR7EHIbKG0AG1TG VI3ar49aZl4QdzCO4yKWH5LnmHjgmnPVerjBHepZlm182FNM2yKl8bd9uw9VIQirAA5N DkGIDWOqalLw9C0qooP7uEviIU2l9i43rLAC5TlN341X1i/EDwgb9WyAd7YLR12cCKkz p2pQ== 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=RIrthwm6tdm2aQE/w3RNrvd+PErUsx9KWtS5YZPvaAw=; b=yfbEqNMq3wcRdFGbH9dtR2a0sf2ftHAUz5C7e09TL9FiesV3FEqkLAvGxsNrPpQksJ Fi9uo+7QeTho6kPgdVzz8k0kVGFnJDOkyX+Roon0u0aLTfUopgCRFFrbx6X0Haut7Xf7 VgSkpJBz0y1hX8FR4XSwaCbI9cJW/yyWybYxMYn7mAzqLB/fsIygIqIR6E129yCkaKkq tRLbOxOJ/Ks9LFYgi0Oiqel3LjIMpp4Q84y6DwnQXX6rWsIU8Ndb0ZQ+Fal+63S3g+i1 oWRfY4hlDPCQQ/uiy5pp0OfbR7Ee7RELdaWwHi6qG9Butn7dwHoFmilRhdVrfQodl+h0 ozUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=QGf3FpzY; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x12-20020a63db4c000000b0038265eb37fasi3796303pgi.780.2022.04.12.15.33.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 15:33:38 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=QGf3FpzY; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 04C20E0AC7; Tue, 12 Apr 2022 14:10:01 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231882AbiDLQdy (ORCPT + 99 others); Tue, 12 Apr 2022 12:33:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357695AbiDLQdc (ORCPT ); Tue, 12 Apr 2022 12:33:32 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 514195E769 for ; Tue, 12 Apr 2022 09:31:11 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id q14so24718480ljc.12 for ; Tue, 12 Apr 2022 09:31:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RIrthwm6tdm2aQE/w3RNrvd+PErUsx9KWtS5YZPvaAw=; b=QGf3FpzYei83T8HcSKJorhnUgZvI/5VvV6a5G+/cctmgZ7rbbAyy8V4DbgESDpmRSm 5IhZjCeNh0R39MUfLo4qjqE9YtmPT9mUmXL/HkUI+lrl1aydFAm9T+bk+e5KxKCcsLk2 MHB4LP2yINUa4X8UmpyEErsSopyrheuUpxe/I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RIrthwm6tdm2aQE/w3RNrvd+PErUsx9KWtS5YZPvaAw=; b=VRihKzOErHTTPediGbr6N46vlvtjNOEzOZZreF+Xt0I/Mu7eX0OiYHN6yuud1/ma1y FcOPNuQhXD9PeMXqpkY44eaFG85CkC2BjCSp1Tlpdfdn3XkrBqSVjeoDZyqqv6xJwqOG uJr2M4X+6A4Bk6hM4MEYJ0P7olmi+VKqpPQwBXNkkxmTLRw1pvGNyFwfyg5wBamUKEpk eOdUYETFR/5nPT1PCkORGHL9zeAn0qoRnU/gNaAqkYXYMUEBjRShJUVxh2zXX8PSl30G z52FDeCZ8wk7WCFHwWfbAJOvzgH0Non1HZl0FfgIASzMV1y43PdXf0lRg+HDblWs2MJ0 j6xA== X-Gm-Message-State: AOAM532dDN+LFssLHFisIwifFzQWAnDWsDBF8tTNSK+73SJdolgZr3Mm f04kmU2D/0fi8xQS7aRZ41L1Rh/nJbJpNde1 X-Received: by 2002:a05:651c:a09:b0:24c:7228:ae21 with SMTP id k9-20020a05651c0a0900b0024c7228ae21mr1715593ljq.397.1649781068310; Tue, 12 Apr 2022 09:31:08 -0700 (PDT) Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com. [209.85.167.43]) by smtp.gmail.com with ESMTPSA id h12-20020a19ca4c000000b00464f0760504sm1804109lfj.276.2022.04.12.09.31.05 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Apr 2022 09:31:06 -0700 (PDT) Received: by mail-lf1-f43.google.com with SMTP id bq30so20370164lfb.3 for ; Tue, 12 Apr 2022 09:31:05 -0700 (PDT) X-Received: by 2002:a05:6512:b12:b0:44a:ba81:f874 with SMTP id w18-20020a0565120b1200b0044aba81f874mr26536279lfu.449.1649781065537; Tue, 12 Apr 2022 09:31:05 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Linus Torvalds Date: Tue, 12 Apr 2022 06:30:49 -1000 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] stat: fix inconsistency between struct stat and struct compat_stat To: Mikulas Patocka Cc: Alexander Viro , linux-fsdevel , Linux Kernel Mailing List , Matthew Wilcox Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 Mon, Apr 11, 2022 at 11:41 PM Mikulas Patocka wrote: > > Also, if the st_dev and st_rdev values are 32-bit, we don't have to use > old_valid_dev to test if the value fits into them. This fixes -EOVERFLOW > on filesystems that are on NVMe because NVMe uses the major number 259. The problem with this part of the patch is that this: > @@ -353,7 +352,7 @@ static int cp_new_stat(struct kstat *sta > #endif > > INIT_STRUCT_STAT_PADDING(tmp); > - tmp.st_dev = encode_dev(stat->dev); > + tmp.st_dev = new_encode_dev(stat->dev); completely changes the format of that st_dev field. For completely insane historical reasons, we have had the rule that - 32-bit architectures encode the device into a 16 bit value - 64-bit architectures encode the device number into a 32 bit value and that has been true *despite* the fact that the actual "st_dev" field has been 32-bit and 64-bit respectively since 2003! And it doesn't help that to confuse things even more, the _naming_ of those "encode_dev" functions is "old and new", so that logically you'd think that "cp_new_stat()" would use "new_encode_dev()". Nope. So on 32-bit architectures, cp_new_stat() uses "old_encode_dev()", which historically put the minor number in bits 0..7, and the major number in bits 8..15. End result: on a 32-bit system (or in the compat syscall mode), changing to new_encode_dev() would confuse anybody (like just "ls -l /dev") that uses that old stat call and tries to print out major/minor numbers. Now,. the good news is that (a) nobody should use that old stat call, since the new world order is called "stat64" and has been for a loooong time - also since at least 2003) (b) we could just hide the bits in upper bits instead. So what I suggest we do is to make old_encode_dev() put the minor bits in bits 0..7 _and_ 16..23, and the major bits in 8..15 _and_ 24..32. And then the -EOVERFLOW should be something like unsigned int st_dev = encode_dev(stat->dev); tmp.st_dev = st_dev; if (st_dev != tmp.st_dev) return -EOVERFLOW; for the lcase that tmp.st_dev is actually 16-bit (ie the compat case for some architecture where the padding wasn't there?) NOTE: That will still screw up 'ls -l' output, but only for the devices that previously would have returned -EOVERFLOW. And it will make anybopdy who does that "stat1->st_dev == stat2->st_dev && ino == ino2" thing for testing "same inode" work just fine. Linus