Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2585991rda; Wed, 25 Oct 2023 07:03:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFbyR4HdUm+C+7kU1E7eOPe65YEJZTRvAORQIGRsSlbbAjS13OqDSn87hkjOQmkpcvNGmE8 X-Received: by 2002:a05:6808:1810:b0:3ae:144f:f99b with SMTP id bh16-20020a056808181000b003ae144ff99bmr20188523oib.4.1698242636198; Wed, 25 Oct 2023 07:03:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698242636; cv=none; d=google.com; s=arc-20160816; b=dg1m6P4kOpq8M/aI/LaCehGIGJmZkg7R9X3rXQc7xDM5Pg0Ki/54ttl6Jnph9Ae5uh UyIDcb3SVwrumoHQLgCsMr7YWLhcW29hUEfOAVwjnbB83t4cPPrWPNZdPzC5d5+xVhZ+ seM9xYa4dyPg0pu6iik4U5AjVYJ3XWWbyyE/mfgDVpp8lRlfI0EwxGEO2xlRvkVdoR54 PHSCshw1RI4FxVMZhrBUAnrOaQMB8okkQW0Y4tc7J2tzhIVTF8V6/2OqLegMAOswZHzu qxzgMlTJCryHdSJJwGXIczqyD0W/9wp1PI7epxnxQRI6y04+04L7whjze2cdTkC+mMzy 8Grw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Rktb275++autG2dBh3wJ1wvqmgDO3Aq+V8t/EjWFz4M=; fh=frgPBLWOZvp32JiMJOLt6aKy7B3S1iDiMKfksagzb84=; b=NNw/gnxJ4DEwbyhUGbnbS3uPj1FgxCHroG2YVqFoe7Fa0NKssZTsTbQ2CGoLCGsnFa mAVXM3xnQ/ErjG3ZmPoRnfZkegnSyB0q2+VCXXsAyKs1dWnckkHbbYOMPcddBFy4pAw4 koRqvxluNe8tMXpsdUU+tf3KSCdETjjiauF5gXiCO6K8UbJnPILk60cu0TrjY7eqbN0f oP3mpJgC/zytU7MObGBiud/HzH45Yq4FYs4V9gilUCmkOUSeDCZLBWPh2yFx3Elipazj UBmPlke1wzuK53ArlGV+qAY53BnB/rF4e1Il/b8V7144VeWD0l9aVacmtFZaoBDFNbg+ SPqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UAVGZsqA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id h26-20020a05610202da00b00450cc922592si1197381vsh.65.2023.10.25.07.03.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 07:03:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UAVGZsqA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id CA1F5809C40D; Wed, 25 Oct 2023 07:03:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235074AbjJYODF (ORCPT + 99 others); Wed, 25 Oct 2023 10:03:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234938AbjJYODC (ORCPT ); Wed, 25 Oct 2023 10:03:02 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4734182 for ; Wed, 25 Oct 2023 07:02:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698242533; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Rktb275++autG2dBh3wJ1wvqmgDO3Aq+V8t/EjWFz4M=; b=UAVGZsqAOi8Eq9FxhzkUxWCiIdIbkHQRO4ngTdK1ymVmVyxpHPaVkdPb+v3ldO0jKeaAcF hYij+xZIsjLwzLqeQULzFpXyC0vHSadUHoAin+4sf087BQUjWAujJtGJNpY0O0yq1VnYPg 1QlPRBv47HPb9cZKNf1Eu7iSEDbGZSU= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-s9JMx6ywO_2--QHIwX6m7Q-1; Wed, 25 Oct 2023 10:02:10 -0400 X-MC-Unique: s9JMx6ywO_2--QHIwX6m7Q-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-9ae57d8b502so355647666b.2 for ; Wed, 25 Oct 2023 07:02:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698242529; x=1698847329; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Rktb275++autG2dBh3wJ1wvqmgDO3Aq+V8t/EjWFz4M=; b=ruCIFpfs4gD8rKQMFwrf9HDeNZ3Lo2vhMAcvnmRW5qiQvQHPWv853Tv6jL4JjJROmN WDJvamJkkJNLTy1epU2DZZXU1YX/IygJbqr+sLxkuymulWoSdVglcTinwoE/FuvW1iU8 +Bi3JaFNeITrHfpY9HwAz4UnCDNcabIXRt7jP3sQ6i1i07zPI1+2Q831gYap9JcTdfi9 qMoS6G/zmiVgzIKCScNprmmC7Yl7UeKD6xuCMUxmXUKzcbC2irFEh5/t62MgC+Jrkc9I uxllrRQwlStyjKbZ7kiV73OSi12ILA5Fc50i8pFdMYlf9rwjKjMKXBkKF6vtmNRulDJq z30w== X-Gm-Message-State: AOJu0YxyijNs3LutGCSx5MG2GYHzcCwbMyFxy/ACIkPIdiomRJDH6YJd oih60POQbjrkwJIgEVGdfXiG0LkzKhcyp4U8Quz3cEDDSHycE82BnoLjfcylq7o03AgTI5jHOBW TH7mQjrg3L1PuSjcQ75tD04dC X-Received: by 2002:a17:907:da3:b0:9c6:7ec2:e14e with SMTP id go35-20020a1709070da300b009c67ec2e14emr14335791ejc.50.1698242529019; Wed, 25 Oct 2023 07:02:09 -0700 (PDT) X-Received: by 2002:a17:907:da3:b0:9c6:7ec2:e14e with SMTP id go35-20020a1709070da300b009c67ec2e14emr14335764ejc.50.1698242528629; Wed, 25 Oct 2023 07:02:08 -0700 (PDT) Received: from maszat.piliscsaba.szeredi.hu (92-249-235-200.pool.digikabel.hu. [92.249.235.200]) by smtp.gmail.com with ESMTPSA id vl9-20020a170907b60900b00989828a42e8sm9857073ejc.154.2023.10.25.07.02.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 07:02:08 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-man@vger.kernel.org, linux-security-module@vger.kernel.org, Karel Zak , Ian Kent , David Howells , Linus Torvalds , Al Viro , Christian Brauner , Amir Goldstein , Matthew House , Florian Weimer , Arnd Bergmann Subject: [PATCH v4 1/6] add unique mount ID Date: Wed, 25 Oct 2023 16:01:59 +0200 Message-ID: <20231025140205.3586473-2-mszeredi@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231025140205.3586473-1-mszeredi@redhat.com> References: <20231025140205.3586473-1-mszeredi@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 25 Oct 2023 07:03:28 -0700 (PDT) If a mount is released then its mnt_id can immediately be reused. This is bad news for user interfaces that want to uniquely identify a mount. Implementing a unique mount ID is trivial (use a 64bit counter). Unfortunately userspace assumes 32bit size and would overflow after the counter reaches 2^32. Introduce a new 64bit ID alongside the old one. Initialize the counter to 2^32, this guarantees that the old and new IDs are never mixed up. Signed-off-by: Miklos Szeredi --- fs/mount.h | 3 ++- fs/namespace.c | 4 ++++ fs/stat.c | 9 +++++++-- include/uapi/linux/stat.h | 1 + 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/fs/mount.h b/fs/mount.h index 130c07c2f8d2..a14f762b3f29 100644 --- a/fs/mount.h +++ b/fs/mount.h @@ -72,7 +72,8 @@ struct mount { struct fsnotify_mark_connector __rcu *mnt_fsnotify_marks; __u32 mnt_fsnotify_mask; #endif - int mnt_id; /* mount identifier */ + int mnt_id; /* mount identifier, reused */ + u64 mnt_id_unique; /* mount ID unique until reboot */ int mnt_group_id; /* peer group identifier */ int mnt_expiry_mark; /* true if marked for expiry */ struct hlist_head mnt_pins; diff --git a/fs/namespace.c b/fs/namespace.c index e157efc54023..e02bc5f41c7b 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -68,6 +68,9 @@ static u64 event; static DEFINE_IDA(mnt_id_ida); static DEFINE_IDA(mnt_group_ida); +/* Don't allow confusion with old 32bit mount ID */ +static atomic64_t mnt_id_ctr = ATOMIC64_INIT(1ULL << 32); + static struct hlist_head *mount_hashtable __read_mostly; static struct hlist_head *mountpoint_hashtable __read_mostly; static struct kmem_cache *mnt_cache __read_mostly; @@ -131,6 +134,7 @@ static int mnt_alloc_id(struct mount *mnt) if (res < 0) return res; mnt->mnt_id = res; + mnt->mnt_id_unique = atomic64_inc_return(&mnt_id_ctr); return 0; } diff --git a/fs/stat.c b/fs/stat.c index d43a5cc1bfa4..77878ae48a0f 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -243,8 +243,13 @@ static int vfs_statx(int dfd, struct filename *filename, int flags, error = vfs_getattr(&path, stat, request_mask, flags); - stat->mnt_id = real_mount(path.mnt)->mnt_id; - stat->result_mask |= STATX_MNT_ID; + if (request_mask & STATX_MNT_ID_UNIQUE) { + stat->mnt_id = real_mount(path.mnt)->mnt_id_unique; + stat->result_mask |= STATX_MNT_ID_UNIQUE; + } else { + stat->mnt_id = real_mount(path.mnt)->mnt_id; + stat->result_mask |= STATX_MNT_ID; + } if (path.mnt->mnt_root == path.dentry) stat->attributes |= STATX_ATTR_MOUNT_ROOT; diff --git a/include/uapi/linux/stat.h b/include/uapi/linux/stat.h index 7cab2c65d3d7..2f2ee82d5517 100644 --- a/include/uapi/linux/stat.h +++ b/include/uapi/linux/stat.h @@ -154,6 +154,7 @@ struct statx { #define STATX_BTIME 0x00000800U /* Want/got stx_btime */ #define STATX_MNT_ID 0x00001000U /* Got stx_mnt_id */ #define STATX_DIOALIGN 0x00002000U /* Want/got direct I/O alignment info */ +#define STATX_MNT_ID_UNIQUE 0x00004000U /* Want/got extended stx_mount_id */ #define STATX__RESERVED 0x80000000U /* Reserved for future struct statx expansion */ -- 2.41.0