From f01e21096db037654e22b3699c4984388e9e3f9a Mon Sep 17 00:00:00 2001 From: Linux_zhang Date: Mon, 18 Aug 2025 11:06:40 +0800 Subject: [PATCH] backport community patches --- ...ibblkid-try-LUKS2-first-when-probing.patch | 45 +++++++++ ...e-return-value-of-getopt_long-in-int.patch | 33 +++++++ ...derflow-of-read_all_alloc-return-val.patch | 33 +++++++ ...y-ioctl-correctly-handle-kernel-type.patch | 93 +++++++++++++++++++ ...cept-as-escape-for-options-separator.patch | 84 +++++++++++++++++ backport-libmount-fix-umount-read-only.patch | 40 ++++++++ ...failure-to-apply-flags-as-part-of-a-.patch | 82 ++++++++++++++++ ...ibmount-improve-EPERM-interpretation.patch | 48 ++++++++++ ...ibsmartcols-fix-reduction-stages-use.patch | 58 ++++++++++++ ...dle-nameless-tables-in-export-format.patch | 31 +++++++ backport-lsfd-avoid-undefined-behavior.patch | 91 ++++++++++++++++++ util-linux.spec | 16 +++- 12 files changed, 653 insertions(+), 1 deletion(-) create mode 100644 backport-Revert-libblkid-try-LUKS2-first-when-probing.patch create mode 100644 backport-blkpr-store-return-value-of-getopt_long-in-int.patch create mode 100644 backport-lib-env-avoid-underflow-of-read_all_alloc-return-val.patch create mode 100644 backport-libblkid-topology-ioctl-correctly-handle-kernel-type.patch create mode 100644 backport-libmount-accept-as-escape-for-options-separator.patch create mode 100644 backport-libmount-fix-umount-read-only.patch create mode 100644 backport-libmount-handle-failure-to-apply-flags-as-part-of-a-.patch create mode 100644 backport-libmount-improve-EPERM-interpretation.patch create mode 100644 backport-libsmartcols-fix-reduction-stages-use.patch create mode 100644 backport-libsmartcols-handle-nameless-tables-in-export-format.patch create mode 100644 backport-lsfd-avoid-undefined-behavior.patch diff --git a/backport-Revert-libblkid-try-LUKS2-first-when-probing.patch b/backport-Revert-libblkid-try-LUKS2-first-when-probing.patch new file mode 100644 index 0000000..72883e7 --- /dev/null +++ b/backport-Revert-libblkid-try-LUKS2-first-when-probing.patch @@ -0,0 +1,45 @@ +From 4c5e1c9d17d9c42c0bdbc134dbd49f56bbb8fe3c Mon Sep 17 00:00:00 2001 +From: Fabian Vogt +Date: Wed, 12 Jul 2023 15:48:27 +0200 +Subject: [PATCH] Revert "libblkid: try LUKS2 first when probing" + +mdadm superblocks before 1.1 are placed at the end of the device, which +means that the data contained inside the array starts at offset 0. For +LUKS inside MD, blkid falsely detects this as plain LUKS instead of a +linux_raid_member. This causes e.g. dracut to not assemble the array +during boot and system startup fails. + +This reverts commit b8889c0a214aeb3dd47bf1ab280fe5534b64d2aa. + +(cherry picked from commit 93ba7961779789217a1f814ce3110ff8c040c8c3) +--- + libblkid/src/superblocks/superblocks.c | 6 +----- + 1 file changed, 1 insertion(+), 5 deletions(-) + +diff --git a/libblkid/src/superblocks/superblocks.c b/libblkid/src/superblocks/superblocks.c +index 96bc0ef89..03061f45b 100644 +--- a/libblkid/src/superblocks/superblocks.c ++++ b/libblkid/src/superblocks/superblocks.c +@@ -94,11 +94,6 @@ static int blkid_probe_set_usage(blkid_probe pr, int usage); + */ + static const struct blkid_idinfo *idinfos[] = + { +- /* In case the volume is locked with OPAL we are going to get +- * an I/O error when reading past the LUKS header, so try it +- * first. */ +- &luks_idinfo, +- + /* RAIDs */ + &linuxraid_idinfo, + &ddfraid_idinfo, +@@ -124,6 +119,7 @@ static const struct blkid_idinfo *idinfos[] = + &snapcow_idinfo, + &verity_hash_idinfo, + &integrity_idinfo, ++ &luks_idinfo, + &vmfs_volume_idinfo, + &ubi_idinfo, + &vdo_idinfo, +-- +2.43.0 + diff --git a/backport-blkpr-store-return-value-of-getopt_long-in-int.patch b/backport-blkpr-store-return-value-of-getopt_long-in-int.patch new file mode 100644 index 0000000..70384e8 --- /dev/null +++ b/backport-blkpr-store-return-value-of-getopt_long-in-int.patch @@ -0,0 +1,33 @@ +From d065ff00a36b7244842f743372099837bc61328b Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= +Date: Wed, 11 Oct 2023 07:20:43 +0200 +Subject: [PATCH] blkpr: store return value of getopt_long in int +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +getopt_long returns an int. Don't try to store it in a char. + +See #2538. + +Signed-off-by: Thomas Weißschuh +--- + sys-utils/blkpr.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/sys-utils/blkpr.c b/sys-utils/blkpr.c +index e9b50ccd6..90763db40 100644 +--- a/sys-utils/blkpr.c ++++ b/sys-utils/blkpr.c +@@ -242,7 +242,7 @@ static void __attribute__((__noreturn__)) usage(void) + + int main(int argc, char **argv) + { +- char c; ++ int c; + char *path; + uint64_t key = 0, oldkey = 0; + int command = -1, type = -1, flag = 0; +-- +2.43.0 + diff --git a/backport-lib-env-avoid-underflow-of-read_all_alloc-return-val.patch b/backport-lib-env-avoid-underflow-of-read_all_alloc-return-val.patch new file mode 100644 index 0000000..b2c7762 --- /dev/null +++ b/backport-lib-env-avoid-underflow-of-read_all_alloc-return-val.patch @@ -0,0 +1,33 @@ +From 83ba179b12d3c6c5f400bf78f2f742b1cc7ce256 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= +Date: Fri, 22 Sep 2023 11:19:37 +0200 +Subject: [PATCH] lib/env: avoid underflow of read_all_alloc() return value +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +read_all_alloc() returns a negative error on failure. +When casting this to an unsigned type the failure check "< 1" +will not work. + +Signed-off-by: Thomas Weißschuh +--- + lib/env.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lib/env.c b/lib/env.c +index 2ccabff6f..2b3395c53 100644 +--- a/lib/env.c ++++ b/lib/env.c +@@ -90,7 +90,7 @@ static struct ul_env_list *env_list_add(struct ul_env_list *ls0, const char *str + struct ul_env_list *env_from_fd(int fd) + { + char *buf = NULL, *p; +- size_t rc = 0; ++ ssize_t rc = 0; + struct ul_env_list *ls = NULL; + + if ((rc = read_all_alloc(fd, &buf)) < 1) +-- +2.43.0 + diff --git a/backport-libblkid-topology-ioctl-correctly-handle-kernel-type.patch b/backport-libblkid-topology-ioctl-correctly-handle-kernel-type.patch new file mode 100644 index 0000000..7e42908 --- /dev/null +++ b/backport-libblkid-topology-ioctl-correctly-handle-kernel-type.patch @@ -0,0 +1,93 @@ +From c5e6da31566a57567b6bf5a8e251b5da0c82bc43 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= +Date: Tue, 2 Apr 2024 18:55:29 +0200 +Subject: [PATCH] libblkid: topology/ioctl: correctly handle kernel types +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Commit 5d71d711d07a ("libblkid: topolicy/ioctl: use union for multiple data types") +incorrectly assumed that set_ulong and set_int refer to the type +returned by the kernel. Instead the different function pointer names +refer to the types of the function pointers. +However all ioctls, except for the later added BLKGETDISKSEQ, return +32bit integers. +This made libblkid also interpret the upper 32bits too, leading to +garbage values. + +Introduce a new member 'kernel_size' to also handle the 64bit +BLKGETDISKSEQ. + +Drop data.ul as it is no actually used. + +Closes #2904 +Signed-off-by: Thomas Weißschuh +(cherry picked from commit a10081a52c48a5232db30d8e0a7a7570cc8163ae) +--- + libblkid/src/topology/ioctl.c | 29 +++++++++++++++++++---------- + 1 file changed, 19 insertions(+), 10 deletions(-) + +diff --git a/libblkid/src/topology/ioctl.c b/libblkid/src/topology/ioctl.c +index 3560a2fb5..4be20e802 100644 +--- a/libblkid/src/topology/ioctl.c ++++ b/libblkid/src/topology/ioctl.c +@@ -24,6 +24,7 @@ + static const struct topology_val { + + long ioc; ++ size_t kernel_size; + + /* functions to set probing result */ + int (*set_ulong)(blkid_probe, unsigned long); +@@ -31,11 +32,16 @@ static const struct topology_val { + int (*set_u64)(blkid_probe, uint64_t); + + } topology_vals[] = { +- { BLKALIGNOFF, NULL, blkid_topology_set_alignment_offset }, +- { BLKIOMIN, blkid_topology_set_minimum_io_size }, +- { BLKIOOPT, blkid_topology_set_optimal_io_size }, +- { BLKPBSZGET, blkid_topology_set_physical_sector_size }, +- { BLKGETDISKSEQ, .set_u64 = blkid_topology_set_diskseq }, ++ { BLKALIGNOFF, sizeof(int), ++ .set_int = blkid_topology_set_alignment_offset }, ++ { BLKIOMIN, sizeof(int), ++ .set_ulong = blkid_topology_set_minimum_io_size }, ++ { BLKIOOPT, sizeof(int), ++ .set_ulong = blkid_topology_set_optimal_io_size }, ++ { BLKPBSZGET, sizeof(int), ++ .set_ulong = blkid_topology_set_physical_sector_size }, ++ { BLKGETDISKSEQ, sizeof(uint64_t), ++ .set_u64 = blkid_topology_set_diskseq }, + /* we read BLKSSZGET in topology.c */ + }; + +@@ -48,18 +54,21 @@ static int probe_ioctl_tp(blkid_probe pr, + const struct topology_val *val = &topology_vals[i]; + int rc = 1; + union { +- unsigned long ul; +- int i; ++ int s32; + uint64_t u64; +- } data; ++ } data = { 0 }; + + if (ioctl(pr->fd, val->ioc, &data) == -1) + goto nothing; + ++ /* Convert from kernel to libblkid type */ ++ if (val->kernel_size == 4) ++ data.u64 = data.s32; ++ + if (val->set_int) +- rc = val->set_int(pr, data.i); ++ rc = val->set_int(pr, data.u64); + else if (val->set_ulong) +- rc = val->set_ulong(pr, data.ul); ++ rc = val->set_ulong(pr, data.u64); + else + rc = val->set_u64(pr, data.u64); + +-- +2.43.0 + diff --git a/backport-libmount-accept-as-escape-for-options-separator.patch b/backport-libmount-accept-as-escape-for-options-separator.patch new file mode 100644 index 0000000..0dda4ba --- /dev/null +++ b/backport-libmount-accept-as-escape-for-options-separator.patch @@ -0,0 +1,84 @@ +From ec1b0eb36bd6c5a5079293ab03241163f61a8bf4 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Tue, 28 Nov 2023 14:40:48 +0100 +Subject: [PATCH] libmount: accept '\' as escape for options separator + +The libmount library can accept any characters as an option value when +the value is quoted (e.g., foo="b,a,r"). However, overlayfs users have +been using '\' as an escape character (e.g., lowerdir=foo\,bar). + +Although this escaping mechanism was never officially supported by +libmount/mount, it worked for the old mount(2) API because it kept the +options string unparsed for the mount(2) syscall. + +The introduction of the new mount API, which utilizes fsconfig(2) per +option, has brought attention to this issue. + +This patch addresses the problem by introducing official support for +'\' as an escape character for options separator. + +Suggested-by: Miklos Szeredi +References: https://lore.kernel.org/all/CAOQ4uxhgUSPkYAV8SJu-SFszkJcVO3-M4DXf46nJUtXODrPk2g@mail.gmail.com/T/#ma8e6cfc1ce7229abc089e03eed99b23b90d701e5 +Signed-off-by: Karel Zak +(cherry picked from commit f6c29efa929cb8c741591ab38061e7921d53a997) + +--- + lib/strutils.c | 2 +- + libmount/src/hook_mount.c | 18 +++++++++++++++--- + 2 files changed, 16 insertions(+), 4 deletions(-) + +diff --git a/lib/strutils.c b/lib/strutils.c +index 21751fd..6229a6e 100644 +--- a/lib/strutils.c ++++ b/lib/strutils.c +@@ -1190,7 +1190,7 @@ int ul_optstr_next(char **optstr, char **name, size_t *namesz, + continue; /* still in quoted block */ + if (!sep && p > start && *p == '=') + sep = p; /* name and value separator */ +- if (*p == ',') ++ if (*p == ',' && (p == optstr0 || *(p - 1) != '\\')) + stop = p; /* terminate the option item */ + else if (*(p + 1) == '\0') + stop = p + 1; /* end of optstr */ +diff --git a/libmount/src/hook_mount.c b/libmount/src/hook_mount.c +index ac50428..2910c58 100644 +--- a/libmount/src/hook_mount.c ++++ b/libmount/src/hook_mount.c +@@ -45,6 +45,7 @@ + + #include "mountP.h" + #include "fileutils.h" /* statx() fallback */ ++#include "strutils.h" + #include "mount-api-utils.h" + + #include +@@ -120,12 +121,23 @@ static inline int fsconfig_set_value( + const char *name, const char *value) + { + int rc; ++ char *p = NULL; + +- DBG(HOOK, ul_debugobj(hs, " fsconfig(name=%s,value=%s)", name, ++ if (value && strstr(value, "\\,")) { ++ p = strdup(value); ++ if (!p) ++ return -EINVAL; ++ ++ strrem(p, '\\'); ++ value = p; ++ } ++ ++ DBG(HOOK, ul_debugobj(hs, " fsconfig(name=\"%s\" value=\"%s\")", name, + value ? : "")); +- if (value) ++ if (value) { + rc = fsconfig(fd, FSCONFIG_SET_STRING, name, value, 0); +- else ++ free(p); ++ } else + rc = fsconfig(fd, FSCONFIG_SET_FLAG, name, NULL, 0); + + set_syscall_status(cxt, "fsconfig", rc == 0); +-- +2.43.0 + diff --git a/backport-libmount-fix-umount-read-only.patch b/backport-libmount-fix-umount-read-only.patch new file mode 100644 index 0000000..968a2b6 --- /dev/null +++ b/backport-libmount-fix-umount-read-only.patch @@ -0,0 +1,40 @@ +From 9ba8eb5d89f0ebba8b3a542c041a5838e10a0d75 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Tue, 23 Apr 2024 10:29:37 +0200 +Subject: [PATCH] libmount: fix umount --read-only +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Reported-by: Krzysztof Olędzki +Signed-off-by: Karel Zak +(cherry picked from commit a20e7e23a8565e01b1c84de6924d1fbbdb1cfccc) +--- + libmount/src/context_umount.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c +index 26394d51e..c8792874b 100644 +--- a/libmount/src/context_umount.c ++++ b/libmount/src/context_umount.c +@@ -267,6 +267,9 @@ static int lookup_umount_fs_by_statfs(struct libmnt_context *cxt, const char *tg + * So, let's use statfs() if possible (it's bad idea for --lazy/--force + * umounts as target is probably unreachable NFS, also for --detach-loop + * as this additionally needs to know the name of the loop device). ++ * ++ * For the "umount --read-only" command, we need to read the mountinfo ++ * to obtain the mount source. + */ + if (mnt_context_is_restricted(cxt) + || *tgt != '/' +@@ -275,6 +278,7 @@ static int lookup_umount_fs_by_statfs(struct libmnt_context *cxt, const char *tg + || mnt_context_is_lazy(cxt) + || mnt_context_is_nocanonicalize(cxt) + || mnt_context_is_loopdel(cxt) ++ || mnt_context_is_rdonly_umount(cxt) + || mnt_safe_stat(tgt, &st) != 0 || !S_ISDIR(st.st_mode) + || has_utab_entry(cxt, tgt)) + return 1; /* not found */ +-- +2.43.0 + diff --git a/backport-libmount-handle-failure-to-apply-flags-as-part-of-a-.patch b/backport-libmount-handle-failure-to-apply-flags-as-part-of-a-.patch new file mode 100644 index 0000000..5adac0f --- /dev/null +++ b/backport-libmount-handle-failure-to-apply-flags-as-part-of-a-.patch @@ -0,0 +1,82 @@ +From 0a9bf6166017c9623e001ece6945edb3e3bd6837 Mon Sep 17 00:00:00 2001 +From: Debarshi Ray +Date: Thu, 13 Jul 2023 11:07:27 +0200 +Subject: [PATCH] libmount: handle failure to apply flags as part of a mount + operation + +If a mount operation with extra flags runs into an EPERM when applying +the flags, then mnt_context_get_mount_excode() returns 'Unknown error +5005' and MNT_EX_FAIL. Here's an example: + +Create a mount point on the host with 'nodev,nosuid,noexec': + $ dd if=/dev/zero of=/var/tmp/loopfile bs=40960 count=1024 + $ sudo losetup --find /var/tmp/loopfile + $ sudo mkfs.ext4 /dev/loop0 + $ sudo mkdir /mnt/a + $ sudo mount -o nosuid,nodev,noexec /dev/loop0 /mnt/a + +Check the mount options to be sure: + $ findmnt --output OPTIONS,PROPAGATION /mnt/a + OPTIONS PROPAGATION + rw,nosuid,nodev,noexec,relatime,seclabel shared + +Enter a mount and user namespace: + $ podman run \ + --interactive \ + --privileged \ + --rm \ + --tty \ + --volume /:/run/host:rslave \ + registry.fedoraproject.org/fedora:38 \ + /bin/bash + +Try to bind mount the mount point from the host inside the namespace +with some extra flags: + # mkdir ~/b + # mount --bind -o ro /run/host/mnt/a ~/b + mount: /root/b: filesystem was mounted, but any subsequent operation + failed: Unknown error 5005. + # echo $? + 32 + +It will be better to show something more human-readable than 'Unknown +error 5005'. + +Secondly, an exit code of 32 means 'mount failure', which isn't quite +correct here. The mount operation is split into two mount(2) calls, +where the first one uses MS_BIND to create the bind mount, and the +second uses MS_REMOUNT | MS_BIND | MS_RDONLY to apply the 'ro' flag. +Here, the first mount(2) does succeed: + # findmnt --output OPTIONS,PROPAGATION ~/b + OPTIONS PROPAGATION + rw,nosuid,nodev,noexec,relatime,seclabel private,slave + +It's only the application of the 'ro' flag with the second mount(2) that +fails with an EPERM. Hence, an exit code of 1 that means 'incorrect +invocation or permissions' seems more appropriate. + +Signed-off-by: Debarshi Ray +--- + libmount/src/context_mount.c | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c +index 50e4a62ab..0b1e25530 100644 +--- a/libmount/src/context_mount.c ++++ b/libmount/src/context_mount.c +@@ -1517,6 +1517,12 @@ int mnt_context_get_mount_excode( + * mount(2) syscall success, but something else failed + * (probably error in utab processing). + */ ++ if (rc == -MNT_ERR_APPLYFLAGS) { ++ if (buf) ++ snprintf(buf, bufsz, _("filesystem was mounted, but failed to apply flags")); ++ return MNT_EX_USAGE; ++ } ++ + if (rc == -MNT_ERR_LOCK) { + if (buf) + snprintf(buf, bufsz, _("filesystem was mounted, but failed to update userspace mount table")); +-- +2.43.0 + diff --git a/backport-libmount-improve-EPERM-interpretation.patch b/backport-libmount-improve-EPERM-interpretation.patch new file mode 100644 index 0000000..c8836e8 --- /dev/null +++ b/backport-libmount-improve-EPERM-interpretation.patch @@ -0,0 +1,48 @@ +From d14d39cbdd41eeb17401e9e64e240d7cb54e0516 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Thu, 3 Aug 2023 13:06:30 +0200 +Subject: [PATCH] libmount: improve EPERM interpretation + +In some cases mount(2)/open_tree(2) returns EPERM for root user. In +this case libmount reports it as "mount point is not a directory". + +It does not makes sense for bind mount where target could be a +regular file. + +This patch is not ideal, the error handler is generic, but semantic +for new mount API and mount(2) is different. For example now it checks +for regular file, but the new API supports bind over symlinks, so +proper fix will require lstat() and S_ISLNK(), etc. We need to move +error messages to hook_mount.c and mount_mount_legacy.c to make it +more specific. + +Fixes: https://github.com/util-linux/util-linux/issues/2413 +Signed-off-by: Karel Zak +--- + libmount/src/context_mount.c | 9 ++++++--- + 1 file changed, 6 insertions(+), 3 deletions(-) + +diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c +index f7e280954..41986e74b 100644 +--- a/libmount/src/context_mount.c ++++ b/libmount/src/context_mount.c +@@ -1577,10 +1577,13 @@ int mnt_context_get_mount_excode( + if (!buf) + break; + if (geteuid() == 0) { +- if (mnt_safe_stat(tgt, &st) || !S_ISDIR(st.st_mode)) +- snprintf(buf, bufsz, _("mount point is not a directory")); +- else ++ ++ if (mnt_safe_stat(tgt, &st) == 0 ++ && ((mflags & MS_BIND && S_ISREG(st.st_mode)) ++ || S_ISDIR(st.st_mode))) + snprintf(buf, bufsz, _("permission denied")); ++ else ++ snprintf(buf, bufsz, _("mount point is not a directory")); + } else + snprintf(buf, bufsz, _("must be superuser to use mount")); + break; +-- +2.43.0 + diff --git a/backport-libsmartcols-fix-reduction-stages-use.patch b/backport-libsmartcols-fix-reduction-stages-use.patch new file mode 100644 index 0000000..e774e16 --- /dev/null +++ b/backport-libsmartcols-fix-reduction-stages-use.patch @@ -0,0 +1,58 @@ +From a74b911bd9f20670ead92973bcacab4ef8fa3b79 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Wed, 15 May 2024 15:45:19 +0200 +Subject: [PATCH] libsmartcols: fix reduction stages use + +There is no proper check for the number of reduction stages, so in +some cases, the code can loop indefinitely. + +The patch also fixes 'rc' variable shadowing. + +Fixes: https://github.com/util-linux/util-linux/issues/3046 +Signed-off-by: Karel Zak +(cherry picked from commit 8a01276a3c5bc09dce342e087019c704d8c56a32) +--- + libsmartcols/src/calculate.c | 10 ++++++---- + 1 file changed, 6 insertions(+), 4 deletions(-) + +diff --git a/libsmartcols/src/calculate.c b/libsmartcols/src/calculate.c +index ad0b15d92..1426d235a 100644 +--- a/libsmartcols/src/calculate.c ++++ b/libsmartcols/src/calculate.c +@@ -302,6 +302,8 @@ static int reduce_column(struct libscols_table *tb, + size_t wanted, org_width, reduce = 1; + int is_trunc = 0; + ++ if (stage > 6) ++ return -1; + if (tb->termwidth >= *width) + return 1; + /* ignore hidden columns */ +@@ -481,7 +483,7 @@ int __scols_calculate(struct libscols_table *tb, struct ul_buffer *buf) + /* reduce columns width */ + while (width > tb->termwidth) { + size_t org_width = width; +- int rc = 0, n = 0; ++ int xrc = 0, n = 0; + + if (!sorted) { + DBG(TAB, ul_debugobj(tb, "sorting by deviation")); +@@ -496,12 +498,12 @@ int __scols_calculate(struct libscols_table *tb, struct ul_buffer *buf) + scols_reset_iter(&itr, SCOLS_ITER_BACKWARD); + + while (width > tb->termwidth +- && rc == 0 ++ && xrc == 0 + && scols_table_next_column(tb, &itr, &cl) == 0) { +- rc = reduce_column(tb, cl, &width, stage, n++); ++ xrc = reduce_column(tb, cl, &width, stage, n++); + } + +- if (rc != 0) ++ if (xrc != 0) + break; + if (org_width == width) + stage++; +-- +2.43.0 + diff --git a/backport-libsmartcols-handle-nameless-tables-in-export-format.patch b/backport-libsmartcols-handle-nameless-tables-in-export-format.patch new file mode 100644 index 0000000..bf9f876 --- /dev/null +++ b/backport-libsmartcols-handle-nameless-tables-in-export-format.patch @@ -0,0 +1,31 @@ +From f368ccc759f9684338da723a93449764d0a8e312 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= +Date: Fri, 22 Sep 2023 11:20:36 +0200 +Subject: [PATCH] libsmartcols: handle nameless tables in export format +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +fputs(NULL) is not allowed. + +Signed-off-by: Thomas Weißschuh +--- + libsmartcols/src/print.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/libsmartcols/src/print.c b/libsmartcols/src/print.c +index 906df7e2a..6a7e6da04 100644 +--- a/libsmartcols/src/print.c ++++ b/libsmartcols/src/print.c +@@ -627,7 +627,7 @@ static int print_data(struct libscols_table *tb, + return 0; + + case SCOLS_FMT_EXPORT: +- fputs(name, tb->out); ++ fputs(name ?: "", tb->out); + fputc('=', tb->out); + fputs_quoted(data, tb->out); + if (!is_last) +-- +2.43.0 + diff --git a/backport-lsfd-avoid-undefined-behavior.patch b/backport-lsfd-avoid-undefined-behavior.patch new file mode 100644 index 0000000..fc26991 --- /dev/null +++ b/backport-lsfd-avoid-undefined-behavior.patch @@ -0,0 +1,91 @@ +From 192d8aaa07e088e44fcb78736a53baae1ead7ccd Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= +Date: Sun, 19 Nov 2023 17:21:25 +0100 +Subject: [PATCH] lsfd: avoid undefined behavior +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Passing a pointer to a different datatype to tfind() then were inserted +evokes undefines behavior. +This triggers UBSAN as shown below. + +Instead pass the proper structs. + +``` +../misc-utils/lsfd.c:513:27: runtime error: member access within misaligned address 0x7ffe9ee6495c for type 'struct proc', which requires 8 byte alignment +0x7ffe9ee6495c: note: pointer points here + 1a 1a 1a 1a 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 d0 49 e6 9e fe 7f 00 00 + ^ + #0 0x56159cfa4a3b in proc_tree_compare ../misc-utils/lsfd.c:513 + #1 0x7f9dd4d2d743 in __tfind (/usr/lib/libc.so.6+0x10f743) (BuildId: 8bfe03f6bf9b6a6e2591babd0bbc266837d8f658) + #2 0x56159cfa4ac3 in get_proc ../misc-utils/lsfd.c:518 + #3 0x56159cfe217b in anon_pidfd_get_name ../misc-utils/lsfd-unkn.c:203 + #4 0x56159cfe1040 in unkn_fill_column ../misc-utils/lsfd-unkn.c:93 + #5 0x56159cfaaa37 in fill_column ../misc-utils/lsfd.c:1178 + #6 0x56159cfaaac5 in convert_file ../misc-utils/lsfd.c:1193 + #7 0x56159cfaac4f in convert ../misc-utils/lsfd.c:1212 + #8 0x56159cfb2b54 in main ../misc-utils/lsfd.c:2317 + #9 0x7f9dd4c45ccf (/usr/lib/libc.so.6+0x27ccf) (BuildId: 8bfe03f6bf9b6a6e2591babd0bbc266837d8f658) + #10 0x7f9dd4c45d89 in __libc_start_main (/usr/lib/libc.so.6+0x27d89) (BuildId: 8bfe03f6bf9b6a6e2591babd0bbc266837d8f658) + #11 0x56159cfa3c34 in _start (util-linux/build-meson/lsfd+0x41c34) (BuildId: 35fece1a205f96a2dbfe7a0e93b658530de675c4) +``` + +Signed-off-by: Thomas Weißschuh +(cherry picked from commit 816109f6ffb99d3a7aee1ff6c3467803dcd7939c) +--- + misc-utils/lsfd-sock-xinfo.c | 9 ++++++--- + misc-utils/lsfd.c | 3 ++- + 2 files changed, 8 insertions(+), 4 deletions(-) + +diff --git a/misc-utils/lsfd-sock-xinfo.c b/misc-utils/lsfd-sock-xinfo.c +index 3a11b75f0..61b8607a3 100644 +--- a/misc-utils/lsfd-sock-xinfo.c ++++ b/misc-utils/lsfd-sock-xinfo.c +@@ -124,7 +124,8 @@ static void load_ifaces_from_getifaddrs(struct netns *nsobj) + + static const char *get_iface_name(ino_t netns, unsigned int iface_index) + { +- struct netns **nsobj = tfind(&netns, &netns_tree, netns_compare); ++ struct netns key = { .inode = netns }; ++ struct netns **nsobj = tfind(&key, &netns_tree, netns_compare); + if (!nsobj) + return NULL; + +@@ -138,7 +139,8 @@ static const char *get_iface_name(ino_t netns, unsigned int iface_index) + + static bool is_sock_xinfo_loaded(ino_t netns) + { +- return tfind(&netns, &netns_tree, netns_compare)? true: false; ++ struct netns key = { .inode = netns }; ++ return tfind(&key, &netns_tree, netns_compare)? true: false; + } + + static struct netns *mark_sock_xinfo_loaded(ino_t ino) +@@ -281,7 +283,8 @@ static void add_sock_info(struct sock_xinfo *xinfo) + + struct sock_xinfo *get_sock_xinfo(ino_t netns_inode) + { +- struct sock_xinfo **xinfo = tfind(&netns_inode, &xinfo_tree, xinfo_compare); ++ struct sock_xinfo key = { .inode = netns_inode }; ++ struct sock_xinfo **xinfo = tfind(&key, &xinfo_tree, xinfo_compare); + + if (xinfo) + return *xinfo; +diff --git a/misc-utils/lsfd.c b/misc-utils/lsfd.c +index 9f74862f1..3c5c01f82 100644 +--- a/misc-utils/lsfd.c ++++ b/misc-utils/lsfd.c +@@ -458,7 +458,8 @@ static int proc_tree_compare(const void *a, const void *b) + + struct proc *get_proc(pid_t pid) + { +- struct proc **node = tfind(&pid, &proc_tree, proc_tree_compare); ++ struct proc key = { .pid = pid }; ++ struct proc **node = tfind(&key, &proc_tree, proc_tree_compare); + if (node) + return *node; + return NULL; +-- +2.43.0 + diff --git a/util-linux.spec b/util-linux.spec index 80dce5d..71a17e0 100644 --- a/util-linux.spec +++ b/util-linux.spec @@ -3,7 +3,7 @@ Name: util-linux Version: 2.39.1 -Release: 25 +Release: 26 Summary: A random collection of Linux utilities License: GPLv2 and GPLv2+ and LGPLv2+ and BSD with advertising and Public Domain URL: https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git @@ -106,6 +106,17 @@ Patch6084: backport-cfdisk-fix-memory-leak-and-possible-NULL-dereference.pa Patch6085: backport-swapoff-clean-up-tag-resolution.patch Patch6086: backport-libblkid-befs-fix-underflow.patch Patch6087: backport-revert-libblkid-ext-add-checksum-support.patch +Patch6088: backport-libmount-handle-failure-to-apply-flags-as-part-of-a-.patch +Patch6089: backport-libmount-improve-EPERM-interpretation.patch +Patch6090: backport-lib-env-avoid-underflow-of-read_all_alloc-return-val.patch +Patch6091: backport-libsmartcols-handle-nameless-tables-in-export-format.patch +Patch6092: backport-blkpr-store-return-value-of-getopt_long-in-int.patch +Patch6093: backport-libmount-accept-as-escape-for-options-separator.patch +Patch6094: backport-lsfd-avoid-undefined-behavior.patch +Patch6095: backport-Revert-libblkid-try-LUKS2-first-when-probing.patch +Patch6096: backport-libblkid-topology-ioctl-correctly-handle-kernel-type.patch +Patch6097: backport-libmount-fix-umount-read-only.patch +Patch6098: backport-libsmartcols-fix-reduction-stages-use.patch Patch9000: SKIPPED-no-root-permissions-test.patch Patch9001: util-linux-Add-sw64-architecture.patch @@ -471,6 +482,9 @@ fi %endif %changelog +* Mon Aug 18 2025 Linux_zhang - 2.39.1-26 +- backport community patches + * Mon Jul 07 2025 Linux_zhang - 2.39.1-25 - Type:bugfix - CVE:NA -- Gitee