lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20260114-tonyk-get_disk_uuid-v1-2-e6a319e25d57@igalia.com>
Date: Wed, 14 Jan 2026 01:31:42 -0300
From: André Almeida <andrealmeid@...lia.com>
To: Christoph Hellwig <hch@....de>, Chuck Lever <chuck.lever@...cle.com>, 
 Jeff Layton <jlayton@...nel.org>, NeilBrown <neil@...wn.name>, 
 Olga Kornievskaia <okorniev@...hat.com>, Dai Ngo <Dai.Ngo@...cle.com>, 
 Tom Talpey <tom@...pey.com>, Carlos Maiolino <cem@...nel.org>, 
 Amir Goldstein <amir73il@...il.com>, Chris Mason <clm@...com>, 
 David Sterba <dsterba@...e.com>, Miklos Szeredi <miklos@...redi.hu>, 
 Christian Brauner <brauner@...nel.org>, 
 Alexander Viro <viro@...iv.linux.org.uk>, Jan Kara <jack@...e.cz>
Cc: linux-nfs@...r.kernel.org, linux-kernel@...r.kernel.org, 
 linux-xfs@...r.kernel.org, linux-fsdevel@...r.kernel.org, 
 linux-btrfs@...r.kernel.org, linux-unionfs@...r.kernel.org, 
 kernel-dev@...lia.com, 
 André Almeida <andrealmeid@...lia.com>
Subject: [PATCH 2/3] btrfs: Implement get_disk_uuid()

Every time btrfs mounts a image that it's already mounted (cloned
images), it will assign a new random UUID to it to avoid conflicts.
However, for some internal kernel usage, it's important to access the
original UUID of a given image.

For instance, overlayfs' "index" feature keeps track of the UUID of the
mounted filesystem on it's upper layer, to avoid being remounted with a
different filesystem. However, overlayfs uses the same random UUID
exposed to userspace, so the "index" check will fail when trying to
remount the very same filesystem.

Implement export operation get_disk_uuid() to export the real image
UUID.

Signed-off-by: André Almeida <andrealmeid@...lia.com>
---
 fs/btrfs/export.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/fs/btrfs/export.c b/fs/btrfs/export.c
index 230d9326b685..09f9ef8c1b1e 100644
--- a/fs/btrfs/export.c
+++ b/fs/btrfs/export.c
@@ -8,6 +8,7 @@
 #include "export.h"
 #include "accessors.h"
 #include "super.h"
+#include "volumes.h"
 
 #define BTRFS_FID_SIZE_NON_CONNECTABLE (offsetof(struct btrfs_fid, \
 						 parent_objectid) / 4)
@@ -298,10 +299,29 @@ static int btrfs_get_name(struct dentry *parent, char *name,
 	return 0;
 }
 
+static int btrfs_get_disk_uuid(struct super_block *sb, u8 *buf, u32 *len,
+			       u64 *offset)
+{
+	struct btrfs_fs_devices *fs_dev = btrfs_sb(sb)->fs_devices;
+
+	if (fs_dev->temp_fsid)
+		return -ENODATA;
+
+	if (*len < sizeof(uuid_t))
+		return -EINVAL;
+
+	memcpy(buf, &fs_dev->metadata_uuid, sizeof(uuid_t));
+	*offset = offsetof(struct btrfs_fs_devices, metadata_uuid);
+	*len = sizeof(uuid_t);
+
+	return 0;
+}
+
 const struct export_operations btrfs_export_ops = {
 	.encode_fh	= btrfs_encode_fh,
 	.fh_to_dentry	= btrfs_fh_to_dentry,
 	.fh_to_parent	= btrfs_fh_to_parent,
 	.get_parent	= btrfs_get_parent,
 	.get_name	= btrfs_get_name,
+	.get_disk_uuid  = btrfs_get_disk_uuid,
 };

-- 
2.52.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ