From nobody Tue Mar 4 20:58:57 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Z6p293sQpz5qhgT; Tue, 04 Mar 2025 20:58:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Z6p293H5Fz3k6C; Tue, 04 Mar 2025 20:58:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1741121937; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FJ719O/nZuqam/ImAtuD8BzGIQs5Ac5yPuL1G9IQZJ8=; b=VZfBK6Qagbs7eoN5zBfHAcPrgrPr8sk7U/lyZxA6dtwQb6n54RGM0c2tYNfkB0M9VKc9Ow J9K8iLRHeSc06X5Q8+GkChJst6fFNB57CmmqbWLqaNU3y4jjQWuRsv+B9QcLwkE0aLbG66 ndNzLXdbEFgNYqCHA2+3Vak0t+hQ8pPWVI00Fa6TmUFiZCc3HEBtdK2sDUsLixA06eGH/1 jYDtgq7bZpuSdRPoYWAwXJngiF3XTLHFqLm+qlZGKEz0BaT9nBs5Vz0BmgfEhuGQhrxLhB /1H1RCR4HMqaQARsRpL3Vak/DI4qSdLEIjAns5zL+LKk/qf5ec86KIu1VAc+QQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1741121937; a=rsa-sha256; cv=none; b=w6M+3GUp1qYIMktaq1S0/ZprK/xq9y8oe1FBGu7OxROvdrZtmLmq46GAmL3UDC30fZU33Z XX1n4N4kM7YXiNLeMlJC1k/LELWLopLZdbto192m5lgNqjVJwJFRPVbt0XAkhwo2vlXbfi R9ZuPD9HNJ5u8SFEsRYwKoE1uhCKG0N9ATz2dbLijP7CfJTGsOwvbrEFbMicAj0Ki/nAil FSHbG7m8q+6jpoFNyZhe56q1pKRCabgA9G6QgIo8HgTVhfAPo8zE0ExmTo+ew6Aya0mlTZ bPoO/LUH0VgWuOcWeW8v1LGM7WRSC9HeoFzxiMP5qvqDhzt3Kd+B7T6xVVyzlw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1741121937; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FJ719O/nZuqam/ImAtuD8BzGIQs5Ac5yPuL1G9IQZJ8=; b=D4ckAcR+kat4bRAwC0cwLgN4Y+ubKEHBm7kTW8YZgz7R7Mq0Y3PMfN0++eYWiOSjRE2r3V 8ubQRyEk7CszHxHInMg3xqmIPohePHz+FpEFS+dnNmdqs4UjNB8fYsFNb/+hF7AvaR6ril 1ojMhYPnMPejSYoEOsivvxnFL3NbAaxh+j8HW4x2KNFZZ7FtKFCAmOdVFlnhfWEy5w3GiG j8LenmL9TSLIE1Q2749vhEny0ECAWV4elpkCg22HT2oHDhr83Bymh1C4fUoA9qycsdFnrI eGknlkO6iIxtgT4MbOhjk5sAlXdJjWhd4uw2MAuGpmDwWUTpiarUIac9SJgFwg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Z6p292PWCzbHW; Tue, 04 Mar 2025 20:58:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 524Kwv8m030060; Tue, 4 Mar 2025 20:58:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 524KwvZk030057; Tue, 4 Mar 2025 20:58:57 GMT (envelope-from git) Date: Tue, 4 Mar 2025 20:58:57 GMT Message-Id: <202503042058.524KwvZk030057@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: e4bcef6daba7 - stable/14 - makefs: Make cd9660 Rock Ridge inodes reproducible List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: e4bcef6daba71546570c623e6091fdef982a596b Auto-Submitted: auto-generated The branch stable/14 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=e4bcef6daba71546570c623e6091fdef982a596b commit e4bcef6daba71546570c623e6091fdef982a596b Author: Ed Maste AuthorDate: 2025-02-26 16:44:12 +0000 Commit: Ed Maste CommitDate: 2025-03-04 20:57:26 +0000 makefs: Make cd9660 Rock Ridge inodes reproducible Rock Ridge extensions include an inode field: "POSIX File Serial Number" shall have the same meaning as and may be used for the st_ino field of POSIX:5.6.1. This field shall be recorded according to ISO 9660:7.3.3. Directory Records which share the value of this field are defined as links (see POSIX:2.2.2.17) and, by definition, point to the same file or directory. Previously we'd store the source file's st_ino (except that in metalog mode we'd record 0 for files with nlink = 1). This had two issues: the generated ISO image was nonreproducible due to the arbitrary inode numbers, and files without hard links would falsely be detected (by certain tools) as hard links to each other. Note that the kernel's cd9660(5) file system ignores the Rock Ridge PX File Serial Number, so this issue isn't observed by mounting such a file system. Instead of using the source inode directly, assign target inode numbers sequentially. Use a map so that files with the same source inode (hard links) still receive the same target inode number. PR: 284795 PR: 285027 Reviewed by: brooks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D49141 (cherry picked from commit 518cdd344ec51584478f39b9a9cac77fc0766ce1) (cherry picked from commit 337f5e7a44c4d5ac29e0b0c0fe957bb3b9bae222) (cherry picked from commit a18be39aafc1b55fd67603ee6a6d820d0fcd877f) --- usr.sbin/makefs/cd9660.h | 13 +++++++ usr.sbin/makefs/cd9660/iso9660_rrip.c | 73 ++++++++++++++++++++++++++++++----- usr.sbin/makefs/cd9660/iso9660_rrip.h | 2 +- 3 files changed, 78 insertions(+), 10 deletions(-) diff --git a/usr.sbin/makefs/cd9660.h b/usr.sbin/makefs/cd9660.h index 2892d6d206c2..1ff37f9fa433 100644 --- a/usr.sbin/makefs/cd9660.h +++ b/usr.sbin/makefs/cd9660.h @@ -51,6 +51,7 @@ #include #include #include +#include #include "makefs.h" #include "iso.h" @@ -203,6 +204,12 @@ typedef struct _volume_descriptor struct _volume_descriptor *next; } volume_descriptor; +struct inode_map_node { + RB_ENTRY(inode_map_node) entry; + uint64_t key; + uint64_t value; +}; + typedef struct _iso9660_disk { int sectorSize; struct iso_primary_descriptor primaryDescriptor; @@ -249,7 +256,11 @@ typedef struct _iso9660_disk { unsigned rock_ridge_move_count; cd9660node *rr_moved_dir; + uint64_t rr_inode_next; + RB_HEAD(inode_map_tree, inode_map_node) rr_inode_map; + int archimedes_enabled; + int chrp_boot; /* Spec breaking options */ @@ -276,6 +287,8 @@ typedef struct _iso9660_disk { } iso9660_disk; +RB_PROTOTYPE(inode_map_tree, inode_map_node, entry, inode_map_node_cmp); + /************ FUNCTIONS **************/ int cd9660_valid_a_chars(const char *); int cd9660_valid_d_chars(const char *); diff --git a/usr.sbin/makefs/cd9660/iso9660_rrip.c b/usr.sbin/makefs/cd9660/iso9660_rrip.c index a4ce5c09b24b..31c6e38a96fe 100644 --- a/usr.sbin/makefs/cd9660/iso9660_rrip.c +++ b/usr.sbin/makefs/cd9660/iso9660_rrip.c @@ -47,7 +47,7 @@ #include "iso9660_rrip.h" #include -static void cd9660_rrip_initialize_inode(cd9660node *); +static void cd9660_rrip_initialize_inode(iso9660_disk *, cd9660node *); static int cd9660_susp_handle_continuation(iso9660_disk *, cd9660node *); static int cd9660_susp_handle_continuation_common(iso9660_disk *, cd9660node *, int); @@ -70,6 +70,11 @@ cd9660_susp_initialize(iso9660_disk *diskStructure, cd9660node *node, if (node->dot_dot_record != 0) TAILQ_INIT(&(node->dot_dot_record->head)); + if (diskStructure->rr_inode_next == 0) { + RB_INIT(&diskStructure->rr_inode_map); + diskStructure->rr_inode_next = 1; + } + /* SUSP specific entries here */ if ((r = cd9660_susp_initialize_node(diskStructure, node)) < 0) return r; @@ -101,6 +106,7 @@ int cd9660_susp_finalize(iso9660_disk *diskStructure, cd9660node *node) { cd9660node *temp; + struct inode_map_node *mapnode, *mapnodetmp; int r; assert(node != NULL); @@ -117,6 +123,16 @@ cd9660_susp_finalize(iso9660_disk *diskStructure, cd9660node *node) if ((r = cd9660_susp_finalize(diskStructure, temp)) < 0) return r; } + + if (diskStructure->rr_inode_next != 0) { + RB_FOREACH_SAFE(mapnode, inode_map_tree, + &(diskStructure->rr_inode_map), mapnodetmp) { + RB_REMOVE(inode_map_tree, + &(diskStructure->rr_inode_map), mapnode); + free(mapnode); + } + diskStructure->rr_inode_next = 0; + } return 1; } @@ -323,7 +339,7 @@ cd9660_susp_initialize_node(iso9660_disk *diskStructure, cd9660node *node) } static void -cd9660_rrip_initialize_inode(cd9660node *node) +cd9660_rrip_initialize_inode(iso9660_disk *diskStructure, cd9660node *node) { struct ISO_SUSP_ATTRIBUTES *attr; @@ -337,7 +353,7 @@ cd9660_rrip_initialize_inode(cd9660node *node) /* PX - POSIX attributes */ attr = cd9660node_susp_create_node(SUSP_TYPE_RRIP, SUSP_ENTRY_RRIP_PX, "PX", SUSP_LOC_ENTRY); - cd9660node_rrip_px(attr, node->node); + cd9660node_rrip_px(diskStructure, attr, node->node); TAILQ_INSERT_TAIL(&node->head, attr, rr_ll); @@ -390,7 +406,8 @@ cd9660_rrip_initialize_node(iso9660_disk *diskStructure, cd9660node *node, /* PX - POSIX attributes */ current = cd9660node_susp_create_node(SUSP_TYPE_RRIP, SUSP_ENTRY_RRIP_PX, "PX", SUSP_LOC_ENTRY); - cd9660node_rrip_px(current, parent->node); + cd9660node_rrip_px(diskStructure, current, + parent->node); TAILQ_INSERT_TAIL(&node->head, current, rr_ll); /* TF - timestamp */ @@ -405,7 +422,8 @@ cd9660_rrip_initialize_node(iso9660_disk *diskStructure, cd9660node *node, /* PX - POSIX attributes */ current = cd9660node_susp_create_node(SUSP_TYPE_RRIP, SUSP_ENTRY_RRIP_PX, "PX", SUSP_LOC_ENTRY); - cd9660node_rrip_px(current, grandparent->node); + cd9660node_rrip_px(diskStructure, current, + grandparent->node); TAILQ_INSERT_TAIL(&node->head, current, rr_ll); /* TF - timestamp */ @@ -422,7 +440,7 @@ cd9660_rrip_initialize_node(iso9660_disk *diskStructure, cd9660node *node, TAILQ_INSERT_TAIL(&node->head, current, rr_ll); } } else { - cd9660_rrip_initialize_inode(node); + cd9660_rrip_initialize_inode(diskStructure, node); if (node == diskStructure->rr_moved_dir) { cd9660_rrip_add_NM(node, RRIP_DEFAULT_MOVE_DIR_NAME); @@ -630,8 +648,45 @@ cd9660_createSL(cd9660node *node) } } +static int +inode_map_node_cmp(struct inode_map_node *a, struct inode_map_node *b) +{ + if (a->key < b->key) + return (-1); + if (a->key > b->key) + return (1); + return (0); +} + +RB_GENERATE(inode_map_tree, inode_map_node, entry, inode_map_node_cmp); + +static uint64_t +inode_map(iso9660_disk *diskStructure, uint64_t in) +{ + struct inode_map_node lookup = { .key = in }; + struct inode_map_node *node; + + /* + * Always assign an inode number if src inode unset. mtree mode leaves + * src inode unset for files with st_nlink == 1. + */ + if (in != 0) { + node = RB_FIND(inode_map_tree, &(diskStructure->rr_inode_map), + &lookup); + if (node != NULL) + return (node->value); + } + + node = emalloc(sizeof(struct inode_map_node)); + node->key = in; + node->value = diskStructure->rr_inode_next++; + RB_INSERT(inode_map_tree, &(diskStructure->rr_inode_map), node); + return (node->value); +} + int -cd9660node_rrip_px(struct ISO_SUSP_ATTRIBUTES *v, fsnode *pxinfo) +cd9660node_rrip_px(iso9660_disk *diskStructure, struct ISO_SUSP_ATTRIBUTES *v, + fsnode *pxinfo) { v->attr.rr_entry.PX.h.length[0] = 44; v->attr.rr_entry.PX.h.version[0] = 1; @@ -643,8 +698,8 @@ cd9660node_rrip_px(struct ISO_SUSP_ATTRIBUTES *v, fsnode *pxinfo) v->attr.rr_entry.PX.uid); cd9660_bothendian_dword(pxinfo->inode->st.st_gid, v->attr.rr_entry.PX.gid); - cd9660_bothendian_dword(pxinfo->inode->st.st_ino, - v->attr.rr_entry.PX.serial); + cd9660_bothendian_dword(inode_map(diskStructure, + pxinfo->inode->st.st_ino), v->attr.rr_entry.PX.serial); return 1; } diff --git a/usr.sbin/makefs/cd9660/iso9660_rrip.h b/usr.sbin/makefs/cd9660/iso9660_rrip.h index 5e1e8b5130f0..4c738d27ba45 100644 --- a/usr.sbin/makefs/cd9660/iso9660_rrip.h +++ b/usr.sbin/makefs/cd9660/iso9660_rrip.h @@ -224,7 +224,7 @@ int cd9660_susp_finalize_node(iso9660_disk *, cd9660node *); int cd9660_rrip_finalize_node(cd9660node *); /* POSIX File attribute */ -int cd9660node_rrip_px(struct ISO_SUSP_ATTRIBUTES *, fsnode *); +int cd9660node_rrip_px(iso9660_disk *, struct ISO_SUSP_ATTRIBUTES *, fsnode *); /* Device number */ int cd9660node_rrip_pn(struct ISO_SUSP_ATTRIBUTES *, fsnode *);