Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp140848rdb; Mon, 15 Jan 2024 15:37:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGhleIjbWjFprlCE4FUwfV0aU3DoipnKixKQew2K+4E1FnqzEJyLaEDp22XsotyL+L61LDF X-Received: by 2002:a05:6808:23cd:b0:3bd:8a84:d644 with SMTP id bq13-20020a05680823cd00b003bd8a84d644mr117205oib.9.1705361839977; Mon, 15 Jan 2024 15:37:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705361839; cv=none; d=google.com; s=arc-20160816; b=LNY7Ci+qTfpGC6+vmPkYOvChrW4uczCjIaZ1AcK9J4amODPmTRYn06mEjmC34JJM17 aA9SYcDtDnmTSgQnnWflF3sqJpiY0nV++2cHn8SdpfN1coe5uIuuIWyxGs8EmuN4NmRl NxAYReDVZCksrbozqaRMKh4sdG0ttOFbgXM2z5EGwXVbC2MUSf/jnDkyz91B/arrhMbm p9zKfRjRsmHMtsPq99/MURpMMca244LVB+MJnwR0CwBIxO8FCVJ277JkDDt5Mr0Js1dR vbGDpW3Sq4AuO0tcPjGVTdTG2FL20In/j+W7iSQC4vWq81kp8wbxFlfGV3PUSY7AHOxA /YIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=1mbPDtfInkgIg3LocePG4gMB+5ejkI3pyFSGVS5y8NQ=; fh=6OeICMtev/7yP0eGNZPeZ5cW2XXqrQPCKLnWvfcagfc=; b=sMxy8TDi6SMecRcd/0KTz1KdlGWVPyTwF57VeGJrKx03XW/UiD+Q/pa8UEX1/h1C3K 6/e8jyro3agEBaGd0oC39EBFve3r2cf+IQpdRXh2xpLEcrFlCGk+0SisgsOPoPRyiqSD kXSMNyXnS7TePPJTuB34WmQqB9Cb07xLl7kxGtff99deIcUpKK7PL9EDDQ+ZJOvC3pz9 L9CFf1WTwiJ8djO23WIlCdZQsId1Eq/jvBYn9Dx+x/FKxUt3axDO39OuApABQDUbDI7L 26U/MBI4+6KVyaccGK8NQdnkyTOWgl+Gx5Y4AhLQFM40iJGV0kEo3AO8cCBVGGeGBg6M +bng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EcFmxo0d; spf=pass (google.com: domain of linux-kernel+bounces-26568-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26568-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id y22-20020a056a00039600b006dacb3c6323si9116681pfs.327.2024.01.15.15.37.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 15:37:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26568-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EcFmxo0d; spf=pass (google.com: domain of linux-kernel+bounces-26568-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26568-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id A2186B22509 for ; Mon, 15 Jan 2024 23:35:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 14006210E3; Mon, 15 Jan 2024 23:26:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EcFmxo0d" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4184820DD8; Mon, 15 Jan 2024 23:26:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88044C433F1; Mon, 15 Jan 2024 23:26:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705361206; bh=jN95Ndv1QzVImSwNNjyljjDlK3K5RUphpFL638xT0Us=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EcFmxo0dHpPf2F2ESAmYD0DTo9kfCPiUbuDeVnuhBo0u0iYH0sbqa2475o/oLbFsg knPGNuWRdEn7lz4xOnNkYa+VoVffn95jrxbdo695kDksh/F86mR/gyOUUnOL8Dsp0p ig39+M1a7TGgguWMhtOr+0Lpm7CJW1s0slrKH26CoezHTbgM+B1GYTU8495brrVGeG 9OwV2tV6ho+d2X718UYFmVO5MFRtJQnztUKEVJuqW0zc+aAAgYX7VMcLxkGdoi/+6n uLZffF3OXhO0hPQu0/vYvC6tTw2F28yvlX01f8N9six6F+gN67x1Q1mmNnl+/grntd Hh9gpYVxwsFaw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Miklos Szeredi , Ian Kent , Christian Brauner , Sasha Levin , viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org Subject: [PATCH AUTOSEL 6.1 12/14] add unique mount ID Date: Mon, 15 Jan 2024 18:25:46 -0500 Message-ID: <20240115232611.209265-12-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240115232611.209265-1-sashal@kernel.org> References: <20240115232611.209265-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.73 Content-Transfer-Encoding: 8bit From: Miklos Szeredi [ Upstream commit 98d2b43081972abeb5bb5a087bc3e3197531c46e ] 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 Link: https://lore.kernel.org/r/20231025140205.3586473-2-mszeredi@redhat.com Reviewed-by: Ian Kent Signed-off-by: Christian Brauner Signed-off-by: Sasha Levin --- 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 e04a9e9e3f14..12c8e2eeda91 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; @@ -130,6 +133,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 ef50573c72a2..a003e891a682 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -232,8 +232,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.43.0