Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3327044rdh; Thu, 28 Sep 2023 08:34:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFhubgH8nVDPfGOJSTKWWx0/KYmHjoLz+YgZl+RmJofVRRh7yxkxNJ1iqeC3QWI1a512Deb X-Received: by 2002:a17:90a:670d:b0:259:466:940f with SMTP id n13-20020a17090a670d00b002590466940fmr1365610pjj.22.1695915294394; Thu, 28 Sep 2023 08:34:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695915294; cv=none; d=google.com; s=arc-20160816; b=aZuUfLUseeOGiOGFovGxo0OaVRmFUbGtBZlRutTME0bRj8vz/USV1Ty+8s8wW881cC oV8r89kKaO569Bv+93Prb/h+mp1I5yRO4daU4wQvfV5UHUgtp8+tFbnhR1iVnkKXZHj1 doOqMtS+9OoA3xjaaPm0NUH9bdHPyAxOHdFxYTOxU1F7Pb67zrYSGxyFag6QAwoz9Lm+ u9uldT1VJiILHjDkeVoP8nopSqSTBqyeEIyDhzh4Vr6rJT9ihl68nT3ew5BDm7P3Y4Yw u2EgPXT0fAm2fzXg7GCwrtvqgtp0pXKsGKjeiBABGzcAbQTC2KeY2M+lgl37Wg6zSc8x QutA== 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=SWtEP6obDhInT9MlruX+BXNPufUR3rJf8VMpuhorm70=; fh=frgPBLWOZvp32JiMJOLt6aKy7B3S1iDiMKfksagzb84=; b=Gok/++flqjWTrbfVkriO/JDo7CGvBWPWn3NZ8ZDOpmrizPzc63KDz6/S4Ohf93lOPd fGESSMtESOiVbmF9m0BeLeqohLMF4AtqAJ4KlA7VByvozEZ22IgA/bhtofYrk/wL8h74 a/AWtD2uTjQOPfeujsI8jfdn+kF7SMEcjJw82U2DyMKx4+WoOnZ1IvhVfZon/QJnorQv B3lHHlwtZxZeICr9qiMR8aoONucDttMqpw8vVGc8PhAoUL9h+g7uRt0iweI4bjrLippU zua9+V/2fttgt4UZUEoP6wPH7w6escPUdQdzpb2LbGbaz77iiZzP2znMwJlqYYD2g8rw 3oZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fh78fpIM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id v11-20020a17090a898b00b0027455c727f5si18631549pjn.84.2023.09.28.08.34.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 08:34:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fh78fpIM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 4E5EA82ACAFA; Thu, 28 Sep 2023 06:03:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232682AbjI1NDo (ORCPT + 99 others); Thu, 28 Sep 2023 09:03:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232632AbjI1NDb (ORCPT ); Thu, 28 Sep 2023 09:03:31 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D0431A4 for ; Thu, 28 Sep 2023 06:01:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695906115; 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=SWtEP6obDhInT9MlruX+BXNPufUR3rJf8VMpuhorm70=; b=fh78fpIMcBy1zXbGkflppcGWCeCkqFBP0kTxoMqzQlzNIPdhgBj5fJ03//nLT28b1vLbO4 AQ8e/XNUryLl/bKhg/lusrUCOAVBzigMPBevxC7qPQyGJbSSLv/Vzx2rkxnHyLkdfYhgoP 3lSxpHy8xKejvrnDS9PBH68d2iAib/Y= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-341-53Ij-TTEOpK98XF728qHXg-1; Thu, 28 Sep 2023 09:01:53 -0400 X-MC-Unique: 53Ij-TTEOpK98XF728qHXg-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-9ae12311183so1115296366b.2 for ; Thu, 28 Sep 2023 06:01:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695906112; x=1696510912; 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=SWtEP6obDhInT9MlruX+BXNPufUR3rJf8VMpuhorm70=; b=nkZpNCX5Y7rLHxdY1yHjsZ78VvIxhjiXU21SUBGzeeTWhZO2NVjq3Hm1ijS1sTM0wL 6yskOoasdiQQIPqau6wmCdnrot+8vI4aJsTp9B0Ou9aamUfU+DSwbBA4loTg1edSa3In pTr/l2nJjjiJvoKMZHrpXO2OSTN1uOY0pi+3oT7MpkLMzngKKlIZeJDAWcK4vJ8aMOKr PJUEiXWUElJcCc86/3oFtgaTGc/3AVlkc8YHqsaiNoZ5FzoyDvlmgIZ/XulHGnd3d4+Y AwTlplhQX2Xc+nz2TgeHmPn6frx5SdDi2A3Z7FdmZpzDLPjW/mq+e2MjTH2R5Z7OqvLu +yeg== X-Gm-Message-State: AOJu0YxnhcIAJEhezuWjpNr1TsVNIIwpih8aLMcVk8DPNZbgJfo7ZSNG oQG6uD9DnSLWfeYo0wsuBg7i03Xw3ShkLeD0bXNgTwlAF3PtV6cWQGK9OQGj9tpsITUOkyDi5JP DjK01N9lllCX3KUj2JPYVH1D5 X-Received: by 2002:a17:907:7886:b0:9ae:3a68:93e8 with SMTP id ku6-20020a170907788600b009ae3a6893e8mr1305775ejc.14.1695906111917; Thu, 28 Sep 2023 06:01:51 -0700 (PDT) X-Received: by 2002:a17:907:7886:b0:9ae:3a68:93e8 with SMTP id ku6-20020a170907788600b009ae3a6893e8mr1305753ejc.14.1695906111560; Thu, 28 Sep 2023 06:01:51 -0700 (PDT) Received: from maszat.piliscsaba.szeredi.hu (94-21-53-31.pool.digikabel.hu. [94.21.53.31]) by smtp.gmail.com with ESMTPSA id v6-20020a170906380600b0099c53c4407dsm10784863ejc.78.2023.09.28.06.01.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 06:01:50 -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 v3 1/4] add unique mount ID Date: Thu, 28 Sep 2023 15:01:43 +0200 Message-ID: <20230928130147.564503-2-mszeredi@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230928130147.564503-1-mszeredi@redhat.com> References: <20230928130147.564503-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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 28 Sep 2023 06:03:56 -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 6e60389d6a15..e61e0172e191 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -280,8 +280,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