diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 14:30:36 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 14:30:36 +0000 |
commit | d731b1222e17e0081e5e4e1fc9603b67ba0b72e3 (patch) | |
tree | e0426bca9e6173cf00b0ee2573aa2c0cf96b8a25 /debian/patches/upstream | |
parent | Adding upstream version 2.38.1. (diff) | |
download | util-linux-debian/2.38.1-5.tar.xz util-linux-debian/2.38.1-5.zip |
Adding debian version 2.38.1-5.debian/2.38.1-5debian
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
31 files changed, 2145 insertions, 0 deletions
diff --git a/debian/patches/upstream/0001-lib-path-ul_path_cpuparse-fix-parsing-of-empty-sysfs.patch b/debian/patches/upstream/0001-lib-path-ul_path_cpuparse-fix-parsing-of-empty-sysfs.patch new file mode 100644 index 0000000..743a306 --- /dev/null +++ b/debian/patches/upstream/0001-lib-path-ul_path_cpuparse-fix-parsing-of-empty-sysfs.patch @@ -0,0 +1,52 @@ +From: =?utf-8?q?Petr_=C5=A0tetiar?= <ynezz@true.cz> +Date: Thu, 22 Sep 2022 11:49:13 +0200 +Subject: [PATCH 01/24] lib/path: ul_path_cpuparse: fix parsing of empty sysfs + files +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 8bit + +Kernel 5.15 returns empty content for topology/thread_siblings on +aarch64 platform, which in conjunction of uninitialized `buf` memory +buffer results in the garbage: + + (gdb) p buf + $14 = " @\377\367\177\000\000\000\275\000\347j\032\236" + +This garbage is then being later consumed by underlying helper functions +like for example cpumask_parse() and this leads to the following crash +later: + + in __libc_free (p=0x7ff7f67c00) at src/malloc/mallocng/free.c:105 + in free (p=<optimized out>) at src/malloc/free.c:5 + in add_cpuset_to_array (setsize=<optimized out>, set=<optimized out>, items=<optimized out>, ary=<optimized out>) at ../sys-utils/lscpu-topology.c:29 + in cputype_read_topology (cxt=cxt@entry=0x7ff7fffe70, ct=0x4298a0) at ../sys-utils/lscpu-topology.c:153 + in lscpu_read_topology (cxt=cxt@entry=0x7ff7fffe70) at ../sys-utils/lscpu-topology.c:629 + in main (argc=1, argv=0x7ffffffdb8) at ../sys-utils/lscpu.c:1341 + +It looks like the problem is that current logic expects fgets() to set +errno on failure, but fgets() is not documented to do so and and neither +glibc nor musl set errno. So if errno was set to 0 before fgets() call, +the failure from fgets() is ignored and then invalid buffer is being +parsed. + +Fixes: #1810 +Suggested-by: Thomas Weißschuh <thomas@t-8ch.de> +Signed-off-by: Petr Štetiar <ynezz@true.cz> +--- + lib/path.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lib/path.c b/lib/path.c +index 42b4ead..8da6c06 100644 +--- a/lib/path.c ++++ b/lib/path.c +@@ -1028,7 +1028,7 @@ static int ul_path_cpuparse(struct path_cxt *pc, cpu_set_t **set, int maxcpus, i + if (!f) + return -errno; + +- rc = fgets(buf, len, f) == NULL ? -errno : 0; ++ rc = fgets(buf, len, f) == NULL ? -EIO : 0; + fclose(f); + + if (rc) diff --git a/debian/patches/upstream/0002-libuuid-Implement-continuous-clock-handling-for-time.patch b/debian/patches/upstream/0002-libuuid-Implement-continuous-clock-handling-for-time.patch new file mode 100644 index 0000000..98553fd --- /dev/null +++ b/debian/patches/upstream/0002-libuuid-Implement-continuous-clock-handling-for-time.patch @@ -0,0 +1,332 @@ +From: Michael Trapp <michael.trapp@sap.com> +Date: Mon, 20 Jun 2022 17:10:36 +0200 +Subject: [PATCH 02/24] libuuid: Implement continuous clock handling for time + based UUIDs + +In a uuidd setup, the daemon is a singleton and can maintain it's own +resources for time based UUID generation. This requires a dedicated +'clock sequence range' but does not need any further lock/update of +the LIBUUID_CLOCK_FILE from uuidd. The range of available clock values +is extended by a continuous handling of the clock updates - instead of +updating the value to the current timestamp, it is incremented by +the number of requested UUIDs. +--- + libuuid/src/gen_uuid.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++--- + libuuid/src/libuuid.sym | 1 + + libuuid/src/uuidd.h | 1 + + misc-utils/uuidd.8.adoc | 3 ++ + misc-utils/uuidd.c | 54 ++++++++++++++++++++++++++--- + 5 files changed, 140 insertions(+), 10 deletions(-) + +diff --git a/libuuid/src/gen_uuid.c b/libuuid/src/gen_uuid.c +index 805b40d..807dcd1 100644 +--- a/libuuid/src/gen_uuid.c ++++ b/libuuid/src/gen_uuid.c +@@ -209,6 +209,8 @@ static int get_node_id(unsigned char *node_id) + + /* Assume that the gettimeofday() has microsecond granularity */ + #define MAX_ADJUSTMENT 10 ++/* Reserve a clock_seq value for the 'continuous clock' implementation */ ++#define CLOCK_SEQ_CONT 0 + + /* + * Get clock from global sequence clock counter. +@@ -275,8 +277,10 @@ static int get_clock(uint32_t *clock_high, uint32_t *clock_low, + } + + if ((last.tv_sec == 0) && (last.tv_usec == 0)) { +- ul_random_get_bytes(&clock_seq, sizeof(clock_seq)); +- clock_seq &= 0x3FFF; ++ do { ++ ul_random_get_bytes(&clock_seq, sizeof(clock_seq)); ++ clock_seq &= 0x3FFF; ++ } while (clock_seq == CLOCK_SEQ_CONT); + gettimeofday(&last, NULL); + last.tv_sec--; + } +@@ -286,7 +290,9 @@ try_again: + if ((tv.tv_sec < last.tv_sec) || + ((tv.tv_sec == last.tv_sec) && + (tv.tv_usec < last.tv_usec))) { +- clock_seq = (clock_seq+1) & 0x3FFF; ++ do { ++ clock_seq = (clock_seq+1) & 0x3FFF; ++ } while (clock_seq == CLOCK_SEQ_CONT); + adjustment = 0; + last = tv; + } else if ((tv.tv_sec == last.tv_sec) && +@@ -331,6 +337,64 @@ try_again: + return ret; + } + ++/* ++ * Get current time in 100ns ticks. ++ */ ++static uint64_t get_clock_counter(void) ++{ ++ struct timeval tv; ++ uint64_t clock_reg; ++ ++ gettimeofday(&tv, NULL); ++ clock_reg = tv.tv_usec*10; ++ clock_reg += ((uint64_t) tv.tv_sec) * 10000000ULL; ++ ++ return clock_reg; ++} ++ ++/* ++ * Get continuous clock value. ++ * ++ * Return -1 if there is no further clock counter available, ++ * otherwise return 0. ++ * ++ * This implementation doesn't deliver clock counters based on ++ * the current time because last_clock_reg is only incremented ++ * by the number of requested UUIDs. ++ * max_clock_offset is used to limit the offset of last_clock_reg. ++ */ ++static int get_clock_cont(uint32_t *clock_high, ++ uint32_t *clock_low, ++ int num, ++ uint32_t max_clock_offset) ++{ ++ /* 100ns based time offset according to RFC 4122. 4.1.4. */ ++ const uint64_t reg_offset = (((uint64_t) 0x01B21DD2) << 32) + 0x13814000; ++ static uint64_t last_clock_reg = 0; ++ uint64_t clock_reg; ++ ++ if (last_clock_reg == 0) ++ last_clock_reg = get_clock_counter(); ++ ++ clock_reg = get_clock_counter(); ++ if (max_clock_offset) { ++ uint64_t clock_offset = max_clock_offset * 10000000ULL; ++ if (last_clock_reg < (clock_reg - clock_offset)) ++ last_clock_reg = clock_reg - clock_offset; ++ } ++ ++ clock_reg += MAX_ADJUSTMENT; ++ ++ if ((last_clock_reg + num) >= clock_reg) ++ return -1; ++ ++ *clock_high = (last_clock_reg + reg_offset) >> 32; ++ *clock_low = last_clock_reg + reg_offset; ++ last_clock_reg += num; ++ ++ return 0; ++} ++ + #if defined(HAVE_UUIDD) && defined(HAVE_SYS_UN_H) + + /* +@@ -403,7 +467,7 @@ static int get_uuid_via_daemon(int op __attribute__((__unused__)), + } + #endif + +-int __uuid_generate_time(uuid_t out, int *num) ++static int __uuid_generate_time_internal(uuid_t out, int *num, uint32_t cont_offset) + { + static unsigned char node_id[6]; + static int has_init = 0; +@@ -423,7 +487,14 @@ int __uuid_generate_time(uuid_t out, int *num) + } + has_init = 1; + } +- ret = get_clock(&clock_mid, &uu.time_low, &uu.clock_seq, num); ++ if (cont_offset) { ++ ret = get_clock_cont(&clock_mid, &uu.time_low, *num, cont_offset); ++ uu.clock_seq = CLOCK_SEQ_CONT; ++ if (ret != 0) /* fallback to previous implpementation */ ++ ret = get_clock(&clock_mid, &uu.time_low, &uu.clock_seq, num); ++ } else { ++ ret = get_clock(&clock_mid, &uu.time_low, &uu.clock_seq, num); ++ } + uu.clock_seq |= 0x8000; + uu.time_mid = (uint16_t) clock_mid; + uu.time_hi_and_version = ((clock_mid >> 16) & 0x0FFF) | 0x1000; +@@ -432,6 +503,16 @@ int __uuid_generate_time(uuid_t out, int *num) + return ret; + } + ++int __uuid_generate_time(uuid_t out, int *num) ++{ ++ return __uuid_generate_time_internal(out, num, 0); ++} ++ ++int __uuid_generate_time_cont(uuid_t out, int *num, uint32_t cont_offset) ++{ ++ return __uuid_generate_time_internal(out, num, cont_offset); ++} ++ + /* + * Generate time-based UUID and store it to @out + * +diff --git a/libuuid/src/libuuid.sym b/libuuid/src/libuuid.sym +index 3424533..96372a8 100644 +--- a/libuuid/src/libuuid.sym ++++ b/libuuid/src/libuuid.sym +@@ -60,6 +60,7 @@ global: + UUIDD_PRIVATE { + global: + __uuid_generate_time; ++ __uuid_generate_time_cont; + __uuid_generate_random; + local: + *; +diff --git a/libuuid/src/uuidd.h b/libuuid/src/uuidd.h +index fbe821f..f76acc8 100644 +--- a/libuuid/src/uuidd.h ++++ b/libuuid/src/uuidd.h +@@ -49,6 +49,7 @@ + #define UUIDD_MAX_OP UUIDD_OP_BULK_RANDOM_UUID + + extern int __uuid_generate_time(uuid_t out, int *num); ++extern int __uuid_generate_time_cont(uuid_t out, int *num, uint32_t cont); + extern int __uuid_generate_random(uuid_t out, int *num); + + #endif /* _UUID_UUID_H */ +diff --git a/misc-utils/uuidd.8.adoc b/misc-utils/uuidd.8.adoc +index 49e7b63..8eee3e9 100644 +--- a/misc-utils/uuidd.8.adoc ++++ b/misc-utils/uuidd.8.adoc +@@ -24,6 +24,9 @@ The *uuidd* daemon is used by the UUID library to generate universally unique id + + == OPTIONS + ++*-C*, *--cont-clock* _opt_arg_:: ++Activate continuous clock handling for time based UUIDs. *uuidd* could use all possible clock values, beginning with the daemon's start time. The optional argument can be used to set a value for the max_clock_offset. This gurantees, that a clock value of a UUID will always be within the range of the max_clock_offset. '-C' or '--cont-clock' enables the feature with a default max_clock_offset of 2 hours. '-C<NUM>[hd]' or '--cont-clock=<NUM>[hd]' enables the feature with a max_clock_offset of NUM seconds. In case of an appended h or d, the NUM value is read in hours or days. The minimum value is 60 seconds, the maximum value is 365 days. ++ + *-d*, *--debug*:: + Run *uuidd* in debugging mode. This prevents *uuidd* from running as a daemon. + +diff --git a/misc-utils/uuidd.c b/misc-utils/uuidd.c +index dfcd148..b25439d 100644 +--- a/misc-utils/uuidd.c ++++ b/misc-utils/uuidd.c +@@ -72,6 +72,8 @@ struct uuidd_cxt_t { + const char *cleanup_pidfile; + const char *cleanup_socket; + uint32_t timeout; ++ uint32_t cont_clock_offset; ++ + unsigned int debug: 1, + quiet: 1, + no_fork: 1, +@@ -106,6 +108,8 @@ static void __attribute__((__noreturn__)) usage(void) + fputs(_(" -P, --no-pid do not create pid file\n"), out); + fputs(_(" -F, --no-fork do not daemonize using double-fork\n"), out); + fputs(_(" -S, --socket-activation do not create listening socket\n"), out); ++ fputs(_(" -C, --cont-clock[=<NUM>[hd]]\n"), out); ++ fputs(_(" activate continuous clock handling\n"), out); + fputs(_(" -d, --debug run in debugging mode\n"), out); + fputs(_(" -q, --quiet turn on quiet mode\n"), out); + fputs(USAGE_SEPARATOR, out); +@@ -438,6 +442,15 @@ static void server_loop(const char *socket_path, const char *pidfile_path, + pfd[POLLFD_SOCKET].fd = s; + pfd[POLLFD_SIGNAL].events = pfd[POLLFD_SOCKET].events = POLLIN | POLLERR | POLLHUP; + ++ num = 1; ++ if (uuidd_cxt->cont_clock_offset) { ++ /* trigger initialization */ ++ (void) __uuid_generate_time_cont(uu, &num, uuidd_cxt->cont_clock_offset); ++ if (uuidd_cxt->debug) ++ fprintf(stderr, _("max_clock_offset = %u sec\n"), ++ uuidd_cxt->cont_clock_offset); ++ } ++ + while (1) { + ret = poll(pfd, ARRAY_SIZE(pfd), + uuidd_cxt->timeout ? +@@ -494,7 +507,8 @@ static void server_loop(const char *socket_path, const char *pidfile_path, + break; + case UUIDD_OP_TIME_UUID: + num = 1; +- if (__uuid_generate_time(uu, &num) < 0 && !uuidd_cxt->quiet) ++ ret = __uuid_generate_time_cont(uu, &num, uuidd_cxt->cont_clock_offset); ++ if (ret < 0 && !uuidd_cxt->quiet) + warnx(_("failed to open/lock clock counter")); + if (uuidd_cxt->debug) { + uuid_unparse(uu, str); +@@ -505,7 +519,8 @@ static void server_loop(const char *socket_path, const char *pidfile_path, + break; + case UUIDD_OP_RANDOM_UUID: + num = 1; +- if (__uuid_generate_time(uu, &num) < 0 && !uuidd_cxt->quiet) ++ ret = __uuid_generate_time_cont(uu, &num, uuidd_cxt->cont_clock_offset); ++ if (ret < 0 && !uuidd_cxt->quiet) + warnx(_("failed to open/lock clock counter")); + if (uuidd_cxt->debug) { + uuid_unparse(uu, str); +@@ -515,7 +530,8 @@ static void server_loop(const char *socket_path, const char *pidfile_path, + reply_len = sizeof(uu); + break; + case UUIDD_OP_BULK_TIME_UUID: +- if (__uuid_generate_time(uu, &num) < 0 && !uuidd_cxt->quiet) ++ ret = __uuid_generate_time_cont(uu, &num, uuidd_cxt->cont_clock_offset); ++ if (ret < 0 && !uuidd_cxt->quiet) + warnx(_("failed to open/lock clock counter")); + if (uuidd_cxt->debug) { + uuid_unparse(uu, str); +@@ -567,6 +583,27 @@ static void __attribute__ ((__noreturn__)) unexpected_size(int size) + errx(EXIT_FAILURE, _("Unexpected reply length from server %d"), size); + } + ++static uint32_t parse_cont_clock(char *arg) ++{ ++ uint32_t min_val = 60, ++ max_val = (3600 * 24 * 365), ++ factor = 1; ++ char *p = &arg[strlen(arg)-1]; ++ ++ if ('h' == *p) { ++ *p = '\0'; ++ factor = 3600; ++ min_val = 1; ++ } ++ if ('d' == *p) { ++ *p = '\0'; ++ factor = 24 * 3600; ++ min_val = 1; ++ } ++ return factor * str2num_or_err(optarg, 10, _("failed to parse --cont-clock/-C"), ++ min_val, max_val / factor); ++} ++ + static void parse_options(int argc, char **argv, struct uuidd_cxt_t *uuidd_cxt, + struct uuidd_options_t *uuidd_opts) + { +@@ -581,6 +618,7 @@ static void parse_options(int argc, char **argv, struct uuidd_cxt_t *uuidd_cxt, + {"no-pid", no_argument, NULL, 'P'}, + {"no-fork", no_argument, NULL, 'F'}, + {"socket-activation", no_argument, NULL, 'S'}, ++ {"cont-clock", optional_argument, NULL, 'C'}, + {"debug", no_argument, NULL, 'd'}, + {"quiet", no_argument, NULL, 'q'}, + {"version", no_argument, NULL, 'V'}, +@@ -596,9 +634,15 @@ static void parse_options(int argc, char **argv, struct uuidd_cxt_t *uuidd_cxt, + int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT; + int c; + +- while ((c = getopt_long(argc, argv, "p:s:T:krtn:PFSdqVh", longopts, NULL)) != -1) { ++ while ((c = getopt_long(argc, argv, "p:s:T:krtn:PFSC::dqVh", longopts, NULL)) != -1) { + err_exclusive_options(c, longopts, excl, excl_st); + switch (c) { ++ case 'C': ++ if (optarg != NULL) ++ uuidd_cxt->cont_clock_offset = parse_cont_clock(optarg); ++ else ++ uuidd_cxt->cont_clock_offset = 7200; /* default 2h */ ++ break; + case 'd': + uuidd_cxt->debug = 1; + break; +@@ -673,7 +717,7 @@ int main(int argc, char **argv) + char *cp; + int ret; + +- struct uuidd_cxt_t uuidd_cxt = { .timeout = 0 }; ++ struct uuidd_cxt_t uuidd_cxt = { .timeout = 0, .cont_clock_offset = 0 }; + struct uuidd_options_t uuidd_opts = { .socket_path = UUIDD_SOCKET_PATH }; + + setlocale(LC_ALL, ""); diff --git a/debian/patches/upstream/0003-uuidd-fix-random-UUIDs.patch b/debian/patches/upstream/0003-uuidd-fix-random-UUIDs.patch new file mode 100644 index 0000000..a94e967 --- /dev/null +++ b/debian/patches/upstream/0003-uuidd-fix-random-UUIDs.patch @@ -0,0 +1,28 @@ +From: Karel Zak <kzak@redhat.com> +Date: Mon, 10 Oct 2022 09:37:51 +0200 +Subject: [PATCH 03/24] uuidd: fix random UUIDs + +Commit f27876f introduces copy & past bug and replaces +__uuid_generate_random() with __uuid_generate_time(). + +Fixes: https://github.com/util-linux/util-linux/issues/1837 +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + misc-utils/uuidd.c | 4 +--- + 1 file changed, 1 insertion(+), 3 deletions(-) + +diff --git a/misc-utils/uuidd.c b/misc-utils/uuidd.c +index b25439d..18fbbb6 100644 +--- a/misc-utils/uuidd.c ++++ b/misc-utils/uuidd.c +@@ -519,9 +519,7 @@ static void server_loop(const char *socket_path, const char *pidfile_path, + break; + case UUIDD_OP_RANDOM_UUID: + num = 1; +- ret = __uuid_generate_time_cont(uu, &num, uuidd_cxt->cont_clock_offset); +- if (ret < 0 && !uuidd_cxt->quiet) +- warnx(_("failed to open/lock clock counter")); ++ __uuid_generate_random(uu, &num); + if (uuidd_cxt->debug) { + uuid_unparse(uu, str); + fprintf(stderr, _("Generated random UUID: %s\n"), str); diff --git a/debian/patches/upstream/0004-libuuid-check-clock-value-from-LIBUUID_CLOCK_FILE.patch b/debian/patches/upstream/0004-libuuid-check-clock-value-from-LIBUUID_CLOCK_FILE.patch new file mode 100644 index 0000000..342752e --- /dev/null +++ b/debian/patches/upstream/0004-libuuid-check-clock-value-from-LIBUUID_CLOCK_FILE.patch @@ -0,0 +1,29 @@ +From: Michael Trapp <michael.trapp@sap.com> +Date: Tue, 2 Aug 2022 14:16:43 +0200 +Subject: [PATCH 04/24] libuuid: check clock value from LIBUUID_CLOCK_FILE + +The clock value from the LIBUUID_CLOCK_FILE must be checked in +case of an update of libuuid. If clock==CLOCK_SEQ_CONT it must +be set to a new value. + +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + libuuid/src/gen_uuid.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/libuuid/src/gen_uuid.c b/libuuid/src/gen_uuid.c +index 807dcd1..e1ba3c3 100644 +--- a/libuuid/src/gen_uuid.c ++++ b/libuuid/src/gen_uuid.c +@@ -274,6 +274,11 @@ static int get_clock(uint32_t *clock_high, uint32_t *clock_low, + last.tv_usec = tv2; + adjustment = a; + } ++ // reset in case of reserved CLOCK_SEQ_CONT ++ if (clock_seq == CLOCK_SEQ_CONT) { ++ last.tv_sec = 0; ++ last.tv_usec = 0; ++ } + } + + if ((last.tv_sec == 0) && (last.tv_usec == 0)) { diff --git a/debian/patches/upstream/0005-lsblk-fix-endless-loop-if-device-specified-more-than.patch b/debian/patches/upstream/0005-lsblk-fix-endless-loop-if-device-specified-more-than.patch new file mode 100644 index 0000000..8d3c8f7 --- /dev/null +++ b/debian/patches/upstream/0005-lsblk-fix-endless-loop-if-device-specified-more-than.patch @@ -0,0 +1,41 @@ +From: Karel Zak <kzak@redhat.com> +Date: Mon, 19 Sep 2022 14:23:25 +0200 +Subject: [PATCH 05/24] lsblk: fix endless loop if device specified more than + once + +Fixes: https://github.com/util-linux/util-linux/issues/1814 +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + misc-utils/lsblk-devtree.c | 17 +++++++++++++++++ + 1 file changed, 17 insertions(+) + +diff --git a/misc-utils/lsblk-devtree.c b/misc-utils/lsblk-devtree.c +index ce9d3e8..6f9dc54 100644 +--- a/misc-utils/lsblk-devtree.c ++++ b/misc-utils/lsblk-devtree.c +@@ -282,8 +282,25 @@ void lsblk_unref_devtree(struct lsblk_devtree *tr) + } + } + ++static int has_root(struct lsblk_devtree *tr, struct lsblk_device *dev) ++{ ++ struct lsblk_iter itr; ++ struct lsblk_device *x = NULL; ++ ++ lsblk_reset_iter(&itr, LSBLK_ITER_FORWARD); ++ ++ while (lsblk_devtree_next_root(tr, &itr, &x) == 0) { ++ if (x == dev) ++ return 1; ++ } ++ return 0; ++} ++ + int lsblk_devtree_add_root(struct lsblk_devtree *tr, struct lsblk_device *dev) + { ++ if (has_root(tr, dev)) ++ return 0; ++ + if (!lsblk_devtree_has_device(tr, dev)) + lsblk_devtree_add_device(tr, dev); + diff --git a/debian/patches/upstream/0006-lib-procfs-add-function-to-parse-proc-stat.patch b/debian/patches/upstream/0006-lib-procfs-add-function-to-parse-proc-stat.patch new file mode 100644 index 0000000..54ca955 --- /dev/null +++ b/debian/patches/upstream/0006-lib-procfs-add-function-to-parse-proc-stat.patch @@ -0,0 +1,112 @@ +From: Karel Zak <kzak@redhat.com> +Date: Thu, 11 Aug 2022 10:56:02 +0200 +Subject: [PATCH 06/24] lib/procfs: add function to parse /proc/#/stat + +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + include/procfs.h | 1 + + lib/procfs.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- + 2 files changed, 58 insertions(+), 1 deletion(-) + +diff --git a/include/procfs.h b/include/procfs.h +index 5a730c9..825689b 100644 +--- a/include/procfs.h ++++ b/include/procfs.h +@@ -30,6 +30,7 @@ extern ssize_t procfs_process_get_cmdline(struct path_cxt *pc, char *buf, size_t + extern ssize_t procfs_process_get_cmdname(struct path_cxt *pc, char *buf, size_t bufsz); + extern ssize_t procfs_process_get_stat(struct path_cxt *pc, char *buf, size_t bufsz); + ++extern int procfs_process_get_stat_nth(struct path_cxt *pc, int n, uintmax_t *re); + + static inline ssize_t procfs_process_get_exe(struct path_cxt *pc, char *buf, size_t bufsz) + { +diff --git a/lib/procfs.c b/lib/procfs.c +index 4d6d25b..16a8c04 100644 +--- a/lib/procfs.c ++++ b/lib/procfs.c +@@ -166,6 +166,35 @@ ssize_t procfs_process_get_stat(struct path_cxt *pc, char *buf, size_t bufsz) + return procfs_process_get_line_for(pc, buf, bufsz, "stat"); + } + ++int procfs_process_get_stat_nth(struct path_cxt *pc, int n, uintmax_t *re) ++{ ++ ssize_t rc; ++ char *key = NULL, *tok, *p; ++ char buf[BUFSIZ]; ++ int i; ++ ++ if (n == 2 || n == 3) /* process name and status (strings) */ ++ return -EINVAL; ++ ++ rc = procfs_process_get_line_for(pc, buf, sizeof(buf), "stat"); ++ if (rc < 0) ++ return rc; ++ ++ for (i = 0, tok = strtok_r(buf, " ", &key); tok; ++ tok = strtok_r(NULL, " ", &key)) { ++ ++ i++; ++ if (i == n) ++ return ul_strtou64(tok, re, 10); ++ ++ /* skip rest of the process name */ ++ if (i == 2 && (p = strchr(key, ')'))) ++ key = p + 2; ++ } ++ ++ return -EINVAL; ++} ++ + int procfs_process_get_uid(struct path_cxt *pc, uid_t *uid) + { + struct stat sb; +@@ -536,6 +565,30 @@ static int test_isprocfs(int argc, char *argv[]) + return is ? EXIT_SUCCESS : EXIT_FAILURE; + } + ++static int test_process_stat_nth(int argc, char *argv[]) ++{ ++ pid_t pid; ++ struct path_cxt *pc; ++ uintmax_t num = 0; ++ int n; ++ ++ if (argc != 3) ++ return EXIT_FAILURE; ++ pid = strtol(argv[1], (char **) NULL, 10); ++ n = strtol(argv[2], (char **) NULL, 10); ++ ++ pc = ul_new_procfs_path(pid, NULL); ++ if (!pc) ++ err(EXIT_FAILURE, "cannot alloc procfs handler"); ++ ++ if (procfs_process_get_stat_nth(pc, n, &num) != 0) ++ err(EXIT_FAILURE, "read %dth number failed", n); ++ ++ printf("%d: %dth %ju\n", (int) pid, n, num); ++ ul_unref_path(pc); ++ return EXIT_SUCCESS; ++} ++ + int main(int argc, char *argv[]) + { + if (argc < 2) { +@@ -543,7 +596,8 @@ int main(int argc, char *argv[]) + " %1$s --fds <pid>\n" + " %1$s --is-procfs [<dir>]\n" + " %1$s --processes [---name <name>] [--uid <uid>]\n" +- " %1$s --one <pid>\n", ++ " %1$s --one <pid>\n" ++ " %1$s --stat-nth <pid> <n>\n", + program_invocation_short_name); + return EXIT_FAILURE; + } +@@ -558,6 +612,8 @@ int main(int argc, char *argv[]) + return test_isprocfs(argc - 1, argv + 1); + if (strcmp(argv[1], "--one") == 0) + return test_one_process(argc - 1, argv + 1); ++ if (strcmp(argv[1], "--stat-nth") == 0) ++ return test_process_stat_nth(argc - 1, argv + 1); + + return EXIT_FAILURE; + } diff --git a/debian/patches/upstream/0007-kill-Support-mandating-the-presence-of-a-userspace-s.patch b/debian/patches/upstream/0007-kill-Support-mandating-the-presence-of-a-userspace-s.patch new file mode 100644 index 0000000..7fcd490 --- /dev/null +++ b/debian/patches/upstream/0007-kill-Support-mandating-the-presence-of-a-userspace-s.patch @@ -0,0 +1,147 @@ +From: Chris Down <chris@chrisdown.name> +Date: Wed, 26 Oct 2022 15:47:36 +0100 +Subject: [PATCH 07/24] kill: Support mandating the presence of a userspace + signal handler + +In production we've had several incidents over the years where a process +has a signal handler registered for SIGHUP or one of the SIGUSR signals +which can be used to signal a request to reload configs, rotate log +files, and the like. While this may seem harmless enough, what we've +seen happen repeatedly is something like the following: + +1. A process is using SIGHUP/SIGUSR[12] to request some + application-handled state change -- reloading configs, rotating a log + file, etc; +2. This kind of request is deprecated and removed, so the signal handler + is removed. However, a site where the signal might be sent from is + missed (often logrotate or a service manager); +3. Because the default disposition of these signals is terminal, sooner + or later these applications are going to be sent SIGHUP or similar + and end up unexpectedly killed. + +I know for a fact that we're not the only organistion experiencing this: +in general, signal use is pretty tricky to reason about and safely +remove because of the fairly aggressive SIG_DFL behaviour for some +common signals, especially for SIGHUP which has a particularly ambiguous +meaning. Especially in a large, highly interconnected codebase, +reasoning about signal interactions between system configuration and +applications can be highly complex, and it's inevitable that on occasion +a callsite will be missed. + +In some cases the right call to avoid this will be to migrate services +towards other forms of IPC for this purpose, but inevitably there will +be some services which must continue using signals, so we need a safe +way to support them. + +This patch adds support for the -r/--require-handler flag, which checks +if a userspace handler is present for the signal being sent. If it is +not, the process will be skipped. + +With this flag we can enforce that all SIGHUP reload cases and SIGUSR +equivalents use --require-handler. This effectively mitigates the case +we've seen time and time again where SIGHUP is used to rotate log files +or reload configs, but the sending site is mistakenly left present after +the removal of signal handler, resulting in unintended termination of +the process. + +Signed-off-by: Chris Down <chris@chrisdown.name> +--- + misc-utils/kill.1.adoc | 2 ++ + misc-utils/kill.c | 36 ++++++++++++++++++++++++++++++++++++ + 2 files changed, 38 insertions(+) + +diff --git a/misc-utils/kill.1.adoc b/misc-utils/kill.1.adoc +index 4a6996a..40ab024 100644 +--- a/misc-utils/kill.1.adoc ++++ b/misc-utils/kill.1.adoc +@@ -62,6 +62,8 @@ Similar to *-l*, but it will print signal names and their corresponding numbers. + Do not restrict the command-name-to-PID conversion to processes with the same UID as the present process. + *-p*, *--pid*:: + Only print the process ID (PID) of the named processes, do not send any signals. ++*-r*, *--require-handler*:: ++Do not send the signal if it is not caught in userspace by the signalled process. + *--verbose*:: + Print PID(s) that will be signaled with *kill* along with the signal. + *-q*, *--queue* _value_:: +diff --git a/misc-utils/kill.c b/misc-utils/kill.c +index f557aac..c469074 100644 +--- a/misc-utils/kill.c ++++ b/misc-utils/kill.c +@@ -95,6 +95,7 @@ struct kill_control { + check_all:1, + do_kill:1, + do_pid:1, ++ require_handler:1, + use_sigval:1, + #ifdef UL_HAVE_PIDFD + timeout:1, +@@ -212,6 +213,7 @@ static void __attribute__((__noreturn__)) usage(void) + fputs(_(" -p, --pid print pids without signaling them\n"), out); + fputs(_(" -l, --list[=<signal>] list signal names, or convert a signal number to a name\n"), out); + fputs(_(" -L, --table list signal names and numbers\n"), out); ++ fputs(_(" -r, --require-handler do not send signal if signal handler is not present\n"), out); + fputs(_(" --verbose print pids that will be signaled\n"), out); + + fputs(USAGE_SEPARATOR, out); +@@ -302,6 +304,10 @@ static char **parse_arguments(int argc, char **argv, struct kill_control *ctl) + print_all_signals(stdout, 1); + exit(EXIT_SUCCESS); + } ++ if (!strcmp(arg, "-r") || !strcmp(arg, "--require-handler")) { ++ ctl->require_handler = 1; ++ continue; ++ } + if (!strcmp(arg, "-p") || !strcmp(arg, "--pid")) { + ctl->do_pid = 1; + if (ctl->do_kill) +@@ -448,6 +454,32 @@ static int kill_verbose(const struct kill_control *ctl) + return rc; + } + ++static int check_signal_handler(const struct kill_control *ctl) ++{ ++ uintmax_t sigcgt = 0; ++ int rc = 0, has_hnd = 0; ++ struct path_cxt *pc; ++ ++ if (!ctl->require_handler) ++ return 1; ++ ++ pc = ul_new_procfs_path(ctl->pid, NULL); ++ if (!pc) ++ return -ENOMEM; ++ ++ rc = procfs_process_get_stat_nth(pc, 34, &sigcgt); ++ if (rc) ++ return -EINVAL; ++ ++ ul_unref_path(pc); ++ ++ has_hnd = ((1UL << (ctl->numsig - 1)) & sigcgt) != 0; ++ if (ctl->verbose && !has_hnd) ++ printf(_("not signalling pid %d, it has no userspace handler for signal %d\n"), ctl->pid, ctl->numsig); ++ ++ return has_hnd; ++} ++ + int main(int argc, char **argv) + { + struct kill_control ctl = { .numsig = SIGTERM }; +@@ -470,6 +502,8 @@ int main(int argc, char **argv) + errno = 0; + ctl.pid = strtol(ctl.arg, &ep, 10); + if (errno == 0 && ep && *ep == '\0' && ctl.arg < ep) { ++ if (check_signal_handler(&ctl) <= 0) ++ continue; + if (kill_verbose(&ctl) != 0) + nerrs++; + ct++; +@@ -491,6 +525,8 @@ int main(int argc, char **argv) + continue; + if (procfs_dirent_get_pid(d, &ctl.pid) != 0) + continue; ++ if (check_signal_handler(&ctl) <= 0) ++ continue; + + if (kill_verbose(&ctl) != 0) + nerrs++; diff --git a/debian/patches/upstream/0008-fdisk-fix-output-option-parsing.patch b/debian/patches/upstream/0008-fdisk-fix-output-option-parsing.patch new file mode 100644 index 0000000..badf3d9 --- /dev/null +++ b/debian/patches/upstream/0008-fdisk-fix-output-option-parsing.patch @@ -0,0 +1,24 @@ +From: Karel Zak <kzak@redhat.com> +Date: Mon, 24 Oct 2022 09:57:07 +0200 +Subject: [PATCH 08/24] fdisk: fix --output option parsing + +Fixes: https://github.com/util-linux/util-linux/issues/1859 +Addresses: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1022249 +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + disk-utils/fdisk.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c +index 2bd2ef4..79b904f 100644 +--- a/disk-utils/fdisk.c ++++ b/disk-utils/fdisk.c +@@ -928,7 +928,7 @@ int main(int argc, char **argv) + { "type", required_argument, NULL, 't' }, + { "units", optional_argument, NULL, 'u' }, + { "version", no_argument, NULL, 'V' }, +- { "output", no_argument, NULL, 'o' }, ++ { "output", required_argument, NULL, 'o' }, + { "protect-boot", no_argument, NULL, 'B' }, + { "wipe", required_argument, NULL, 'w' }, + { "wipe-partitions",required_argument, NULL, 'W' }, diff --git a/debian/patches/upstream/0009-fdisk-make-it-more-obvious-that-DOS-means-MBR.patch b/debian/patches/upstream/0009-fdisk-make-it-more-obvious-that-DOS-means-MBR.patch new file mode 100644 index 0000000..328ca6b --- /dev/null +++ b/debian/patches/upstream/0009-fdisk-make-it-more-obvious-that-DOS-means-MBR.patch @@ -0,0 +1,46 @@ +From: Karel Zak <kzak@redhat.com> +Date: Thu, 10 Nov 2022 09:24:23 +0100 +Subject: [PATCH 09/24] fdisk: make it more obvious that DOS means MBR + +Fixes: https://github.com/util-linux/util-linux/issues/1890 +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + disk-utils/fdisk-menu.c | 4 ++-- + libfdisk/src/dos.c | 2 +- + 2 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/disk-utils/fdisk-menu.c b/disk-utils/fdisk-menu.c +index 2f22e59..b41754b 100644 +--- a/disk-utils/fdisk-menu.c ++++ b/disk-utils/fdisk-menu.c +@@ -122,7 +122,7 @@ static const struct menu menu_generic = { + MENU_BENT ('q', N_("quit without saving changes")), + MENU_XENT ('r', N_("return to main menu")), + +- MENU_ENT_NEST('r', N_("return from BSD to DOS"), FDISK_DISKLABEL_BSD, FDISK_DISKLABEL_DOS), ++ MENU_ENT_NEST('r', N_("return from BSD to DOS (MBR)"), FDISK_DISKLABEL_BSD, FDISK_DISKLABEL_DOS), + + MENU_ENT_NEST('r', N_("return from protective/hybrid MBR to GPT"), FDISK_DISKLABEL_DOS, FDISK_DISKLABEL_GPT), + +@@ -138,7 +138,7 @@ static const struct menu menu_createlabel = { + MENU_SEP(N_("Create a new label")), + MENU_ENT('g', N_("create a new empty GPT partition table")), + MENU_ENT('G', N_("create a new empty SGI (IRIX) partition table")), +- MENU_ENT('o', N_("create a new empty DOS partition table")), ++ MENU_ENT('o', N_("create a new empty MBR (DOS) partition table")), + MENU_ENT('s', N_("create a new empty Sun partition table")), + + /* backward compatibility -- be sensitive to 'g', but don't +diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c +index 98bc614..7970ae1 100644 +--- a/libfdisk/src/dos.c ++++ b/libfdisk/src/dos.c +@@ -708,7 +708,7 @@ static int dos_create_disklabel(struct fdisk_context *cxt) + /* Put MBR signature */ + mbr_set_magic(cxt->firstsector); + +- fdisk_info(cxt, _("Created a new DOS disklabel with disk " ++ fdisk_info(cxt, _("Created a new DOS (MBR) disklabel with disk " + "identifier 0x%08x."), id); + return 0; + } diff --git a/debian/patches/upstream/0010-libfdisk-make-scripts-portable-between-different-sec.patch b/debian/patches/upstream/0010-libfdisk-make-scripts-portable-between-different-sec.patch new file mode 100644 index 0000000..98039a2 --- /dev/null +++ b/debian/patches/upstream/0010-libfdisk-make-scripts-portable-between-different-sec.patch @@ -0,0 +1,130 @@ +From: Karel Zak <kzak@redhat.com> +Date: Mon, 11 Jul 2022 14:02:30 +0200 +Subject: [PATCH 10/24] libfdisk: make scripts portable between different + sector sizes + +Fixes: https://github.com/util-linux/util-linux/issues/1744 +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + libfdisk/src/script.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++- + 1 file changed, 70 insertions(+), 1 deletion(-) + +diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c +index d93b981..b620eda 100644 +--- a/libfdisk/src/script.c ++++ b/libfdisk/src/script.c +@@ -63,6 +63,8 @@ struct fdisk_script { + size_t nlines; + struct fdisk_label *label; + ++ unsigned long sector_size; /* as defined by script */ ++ + unsigned int json : 1, /* JSON output */ + force_label : 1; /* label: <name> specified */ + }; +@@ -806,6 +808,19 @@ static int parse_line_header(struct fdisk_script *dp, char *s) + return -EINVAL; /* unknown label name */ + dp->force_label = 1; + ++ } else if (strcmp(name, "sector-size") == 0) { ++ uint64_t x = 0; ++ ++ if (ul_strtou64(value, &x, 10) != 0) ++ return -EINVAL; ++ if (x > ULONG_MAX || x % 512) ++ return -ERANGE; ++ dp->sector_size = (unsigned long) x; ++ ++ if (dp->cxt && dp->sector_size && dp->cxt->sector_size ++ && dp->sector_size != dp->cxt->sector_size) ++ fdisk_warnx(dp->cxt, _("The script and device sector size differ; the sizes will be recalculated to match the device.")); ++ + } else if (strcmp(name, "unit") == 0) { + if (strcmp(value, "sectors") != 0) + return -EINVAL; /* only "sectors" supported */ +@@ -966,6 +981,27 @@ static int skip_optional_sign(char **str) + return 0; + } + ++static int recount_script2device_sectors(struct fdisk_script *dp, uint64_t *num) ++{ ++ if (!dp->cxt || ++ !dp->sector_size || ++ !dp->cxt->sector_size) ++ return 0; ++ ++ if (dp->sector_size > dp->cxt->sector_size) ++ *num *= (dp->sector_size / dp->cxt->sector_size); ++ ++ else if (dp->sector_size < dp->cxt->sector_size) { ++ uint64_t x = dp->cxt->sector_size / dp->sector_size; ++ ++ if (*num % x) ++ return -EINVAL; ++ *num /= x; ++ } ++ ++ return 0; ++} ++ + static int parse_start_value(struct fdisk_script *dp, struct fdisk_partition *pa, char **str) + { + char *tk; +@@ -997,7 +1033,14 @@ static int parse_start_value(struct fdisk_script *dp, struct fdisk_partition *pa + goto done; + } + num /= dp->cxt->sector_size; ++ } else { ++ rc = recount_script2device_sectors(dp, &num); ++ if (rc) { ++ fdisk_warnx(dp->cxt, _("Can't recalculate partition start to the device sectors")); ++ goto done; ++ } + } ++ + fdisk_partition_set_start(pa, num); + + pa->movestart = sign == '-' ? FDISK_MOVE_DOWN : +@@ -1046,8 +1089,15 @@ static int parse_size_value(struct fdisk_script *dp, struct fdisk_partition *pa, + goto done; + } + num /= dp->cxt->sector_size; +- } else /* specified as number of sectors */ ++ } else { ++ /* specified as number of sectors */ + fdisk_partition_size_explicit(pa, 1); ++ rc = recount_script2device_sectors(dp, &num); ++ if (rc) { ++ fdisk_warnx(dp->cxt, _("Can't recalculate partition size to the device sectors")); ++ goto done; ++ } ++ } + + fdisk_partition_set_size(pa, num); + pa->resize = sign == '-' ? FDISK_RESIZE_REDUCE : +@@ -1492,6 +1542,25 @@ int fdisk_apply_script_headers(struct fdisk_context *cxt, struct fdisk_script *d + DBG(SCRIPT, ul_debugobj(dp, "applying script headers")); + fdisk_set_script(cxt, dp); + ++ if (dp->sector_size && dp->cxt->sector_size != dp->sector_size) { ++ /* ++ * Ignore last and first LBA if device sector size mismatch ++ * with sector size in script. It would be possible to ++ * recalculate it, but for GPT it will not work in some cases ++ * as these offsets are calculated by relative number of ++ * sectors. It's better to use library defaults than try ++ * to be smart ... ++ */ ++ if (fdisk_script_get_header(dp, "first-lba")) { ++ fdisk_script_set_header(dp, "first-lba", NULL); ++ fdisk_info(dp->cxt, _("Ingnore \"first-lba\" header due to sector size mismatch.")); ++ } ++ if (fdisk_script_get_header(dp, "last-lba")) { ++ fdisk_script_set_header(dp, "last-lba", NULL); ++ fdisk_info(dp->cxt, _("Ingnore \"last-lba\" header due to sector size mismatch.")); ++ } ++ } ++ + str = fdisk_script_get_header(dp, "grain"); + if (str) { + uintmax_t sz; diff --git a/debian/patches/upstream/0011-sfdisk-improve-code-readability-for-coverity-scan.patch b/debian/patches/upstream/0011-sfdisk-improve-code-readability-for-coverity-scan.patch new file mode 100644 index 0000000..dc707cb --- /dev/null +++ b/debian/patches/upstream/0011-sfdisk-improve-code-readability-for-coverity-scan.patch @@ -0,0 +1,40 @@ +From: Karel Zak <kzak@redhat.com> +Date: Thu, 11 Aug 2022 13:04:58 +0200 +Subject: [PATCH 11/24] sfdisk: improve code readability for coverity scan + +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + disk-utils/sfdisk.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c +index 38c7b17..112bc7c 100644 +--- a/disk-utils/sfdisk.c ++++ b/disk-utils/sfdisk.c +@@ -435,7 +435,6 @@ static int move_partition_data(struct sfdisk *sf, size_t partno, struct fdisk_pa + from = fdisk_partition_get_start(orig_pa); + to = fdisk_partition_get_start(pa); + +- + if ((to >= from && from + nsectors >= to) || + (from >= to && to + nsectors >= from)) { + /* source and target overlay, check if we need to copy +@@ -462,7 +461,8 @@ static int move_partition_data(struct sfdisk *sf, size_t partno, struct fdisk_pa + + #if defined(POSIX_FADV_SEQUENTIAL) && defined(HAVE_POSIX_FADVISE) + if (!backward) +- posix_fadvise(fd, from * ss, nsectors * ss, POSIX_FADV_SEQUENTIAL); ++ ignore_result( posix_fadvise(fd, from * ss, ++ nsectors * ss, POSIX_FADV_SEQUENTIAL) ); + #endif + devname = fdisk_partname(fdisk_get_devname(sf->cxt), partno+1); + if (sf->move_typescript) +@@ -608,7 +608,7 @@ next: + src += step_bytes, dst += step_bytes; + } + +- if (progress) { ++ if (progress && nsectors) { + int x = get_terminal_width(80); + for (; x > 0; x--) + fputc(' ', stdout); diff --git a/debian/patches/upstream/0012-libfdisk-gpt-don-t-ignore-fsync-errors.patch b/debian/patches/upstream/0012-libfdisk-gpt-don-t-ignore-fsync-errors.patch new file mode 100644 index 0000000..80dc3b3 --- /dev/null +++ b/debian/patches/upstream/0012-libfdisk-gpt-don-t-ignore-fsync-errors.patch @@ -0,0 +1,23 @@ +From: Karel Zak <kzak@redhat.com> +Date: Thu, 11 Aug 2022 13:09:05 +0200 +Subject: [PATCH 12/24] libfdisk: (gpt) don't ignore fsync() errors + +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + libfdisk/src/gpt.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c +index 72370a1..8a91d7a 100644 +--- a/libfdisk/src/gpt.c ++++ b/libfdisk/src/gpt.c +@@ -2032,7 +2032,8 @@ static int gpt_write(struct fdisk_context *cxt, off_t offset, void *buf, size_t + if (write_all(cxt->dev_fd, buf, count)) + return -errno; + +- fsync(cxt->dev_fd); ++ if (fsync(cxt->dev_fd) != 0) ++ return -errno; + + DBG(GPT, ul_debug(" write OK [offset=%zu, size=%zu]", + (size_t) offset, count)); diff --git a/debian/patches/upstream/0013-sfdisk-inform-about-failed-fsync-coverity-scan.patch b/debian/patches/upstream/0013-sfdisk-inform-about-failed-fsync-coverity-scan.patch new file mode 100644 index 0000000..08281af --- /dev/null +++ b/debian/patches/upstream/0013-sfdisk-inform-about-failed-fsync-coverity-scan.patch @@ -0,0 +1,25 @@ +From: Karel Zak <kzak@redhat.com> +Date: Thu, 11 Aug 2022 13:14:18 +0200 +Subject: [PATCH 13/24] sfdisk: inform about failed fsync() [coverity scan] + +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + disk-utils/sfdisk.c | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c +index 112bc7c..0e85e63 100644 +--- a/disk-utils/sfdisk.c ++++ b/disk-utils/sfdisk.c +@@ -566,8 +566,9 @@ static int move_partition_data(struct sfdisk *sf, size_t partno, struct fdisk_pa + ioerr++; + goto next; + } +- if (sf->movefsync) +- fsync(fd); ++ if (sf->movefsync && fsync(fd) != 0) ++ fdisk_warn(sf->cxt, ++ _("cannot fsync at offset: %ju; continue"), dst); + } + + /* write log */ diff --git a/debian/patches/upstream/0014-lscpu-Add-Snapdragon-parts.patch b/debian/patches/upstream/0014-lscpu-Add-Snapdragon-parts.patch new file mode 100644 index 0000000..63cfd72 --- /dev/null +++ b/debian/patches/upstream/0014-lscpu-Add-Snapdragon-parts.patch @@ -0,0 +1,26 @@ +From: Jeremy Linton <jeremy.linton@arm.com> +Date: Wed, 4 May 2022 12:30:34 -0500 +Subject: [PATCH 14/24] lscpu: Add Snapdragon parts + +QC updated the kernel cputype.h to include the Kyro 4xx and 3xx Silver +part numbers's. Lets sync that commit and naming. + +Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> +--- + sys-utils/lscpu-arm.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c +index 86e5ea7..57b4bba 100644 +--- a/sys-utils/lscpu-arm.c ++++ b/sys-utils/lscpu-arm.c +@@ -129,6 +129,9 @@ static const struct id_part qcom_part[] = { + { 0x211, "Kryo" }, + { 0x800, "Falkor V1/Kryo" }, + { 0x801, "Kryo V2" }, ++ { 0x803, "Kryo 3XX Silver" }, ++ { 0x804, "Kryo 4XX Gold" }, ++ { 0x805, "Kryo 4XX Silver" }, + { 0xc00, "Falkor" }, + { 0xc01, "Saphira" }, + { -1, "unknown" }, diff --git a/debian/patches/upstream/0015-Add-Makalu-Makalu-ELP-A715-X3.patch b/debian/patches/upstream/0015-Add-Makalu-Makalu-ELP-A715-X3.patch new file mode 100644 index 0000000..2fb4f83 --- /dev/null +++ b/debian/patches/upstream/0015-Add-Makalu-Makalu-ELP-A715-X3.patch @@ -0,0 +1,30 @@ +From: ThomasKaiser <ThomasKaiser@users.noreply.github.com> +Date: Thu, 30 Jun 2022 07:32:40 +0200 +Subject: [PATCH 15/24] Add Makalu/Makalu-ELP (A715/X3) + +Also fix names of A510/A710 cores +--- + sys-utils/lscpu-arm.c | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c +index 57b4bba..30977cd 100644 +--- a/sys-utils/lscpu-arm.c ++++ b/sys-utils/lscpu-arm.c +@@ -83,12 +83,14 @@ static const struct id_part arm_part[] = { + { 0xd41, "Cortex-A78" }, + { 0xd42, "Cortex-A78AE" }, + { 0xd44, "Cortex-X1" }, +- { 0xd46, "Cortex-510" }, +- { 0xd47, "Cortex-710" }, ++ { 0xd46, "Cortex-A510" }, ++ { 0xd47, "Cortex-A710" }, + { 0xd48, "Cortex-X2" }, + { 0xd49, "Neoverse-N2" }, + { 0xd4a, "Neoverse-E1" }, + { 0xd4b, "Cortex-A78C" }, ++ { 0xd4d, "Cortex-A715" }, ++ { 0xd4e, "Cortex-X3" }, + { -1, "unknown" }, + }; + diff --git a/debian/patches/upstream/0016-Adding-Apple-core-names-distinguish-by-SoC-SiP-name.patch b/debian/patches/upstream/0016-Adding-Apple-core-names-distinguish-by-SoC-SiP-name.patch new file mode 100644 index 0000000..530ad9d --- /dev/null +++ b/debian/patches/upstream/0016-Adding-Apple-core-names-distinguish-by-SoC-SiP-name.patch @@ -0,0 +1,31 @@ +From: ThomasKaiser <ThomasKaiser@users.noreply.github.com> +Date: Fri, 1 Jul 2022 11:24:04 +0200 +Subject: [PATCH 16/24] Adding Apple core names, distinguish by SoC/SiP name + +--- + sys-utils/lscpu-arm.c | 12 +++++++++--- + 1 file changed, 9 insertions(+), 3 deletions(-) + +diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c +index 30977cd..7b9b364 100644 +--- a/sys-utils/lscpu-arm.c ++++ b/sys-utils/lscpu-arm.c +@@ -159,9 +159,15 @@ static const struct id_part marvell_part[] = { + }; + + static const struct id_part apple_part[] = { +- { 0x022, "Icestorm" }, +- { 0x023, "Firestorm" }, +- { -1, "unknown" }, ++ { 0x020, "Icestorm-T8101" }, ++ { 0x021, "Firestorm-T8101" }, ++ { 0x022, "Icestorm-T8103" }, ++ { 0x023, "Firestorm-T8103" }, ++ { 0x030, "Blizzard-T8110" }, ++ { 0x031, "Avalanche-T8110" }, ++ { 0x032, "Blizzard-T8112" }, ++ { 0x033, "Avalanche-T8112" }, ++ { -1, "unknown" }, + }; + + static const struct id_part faraday_part[] = { diff --git a/debian/patches/upstream/0017-Fix-formatting.patch b/debian/patches/upstream/0017-Fix-formatting.patch new file mode 100644 index 0000000..a7c0a0a --- /dev/null +++ b/debian/patches/upstream/0017-Fix-formatting.patch @@ -0,0 +1,21 @@ +From: Thomas Kaiser <ThomasKaiser@users.noreply.github.com> +Date: Fri, 1 Jul 2022 14:16:49 +0200 +Subject: [PATCH 17/24] Fix formatting. + +--- + sys-utils/lscpu-arm.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c +index 7b9b364..7986fa3 100644 +--- a/sys-utils/lscpu-arm.c ++++ b/sys-utils/lscpu-arm.c +@@ -167,7 +167,7 @@ static const struct id_part apple_part[] = { + { 0x031, "Avalanche-T8110" }, + { 0x032, "Blizzard-T8112" }, + { 0x033, "Avalanche-T8112" }, +- { -1, "unknown" }, ++ { -1, "unknown" }, + }; + + static const struct id_part faraday_part[] = { diff --git a/debian/patches/upstream/0018-lscpu-make-Apple-part-names-human-friendly.patch b/debian/patches/upstream/0018-lscpu-make-Apple-part-names-human-friendly.patch new file mode 100644 index 0000000..a9aa2a4 --- /dev/null +++ b/debian/patches/upstream/0018-lscpu-make-Apple-part-names-human-friendly.patch @@ -0,0 +1,41 @@ +From: James Calligeros <jcalligeros99@gmail.com> +Date: Sat, 9 Jul 2022 14:52:35 +1000 +Subject: [PATCH 18/24] lscpu: make Apple part names human-friendly + +The internal Apple model numbers for the SoCs are somewhat +confusing given that they are mostly similar and differ by only +one or two digits. Instead, use the public nomenclature for these +chips to avoid ambiguity and beautify the output. + +Signed-off-by: James Calligeros <jcalligeros99@gmail.com> +--- + sys-utils/lscpu-arm.c | 16 ++++++++-------- + 1 file changed, 8 insertions(+), 8 deletions(-) + +diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c +index 7986fa3..a266015 100644 +--- a/sys-utils/lscpu-arm.c ++++ b/sys-utils/lscpu-arm.c +@@ -159,14 +159,14 @@ static const struct id_part marvell_part[] = { + }; + + static const struct id_part apple_part[] = { +- { 0x020, "Icestorm-T8101" }, +- { 0x021, "Firestorm-T8101" }, +- { 0x022, "Icestorm-T8103" }, +- { 0x023, "Firestorm-T8103" }, +- { 0x030, "Blizzard-T8110" }, +- { 0x031, "Avalanche-T8110" }, +- { 0x032, "Blizzard-T8112" }, +- { 0x033, "Avalanche-T8112" }, ++ { 0x020, "Icestorm (A14)" }, ++ { 0x021, "Firestorm (A14)" }, ++ { 0x022, "Icestorm (M1)" }, ++ { 0x023, "Firestorm (M1)" }, ++ { 0x030, "Blizzard (A15)" }, ++ { 0x031, "Avalanche (A15)" }, ++ { 0x032, "Blizzard (M2)" }, ++ { 0x033, "Avalanche (M2)" }, + { -1, "unknown" }, + }; + diff --git a/debian/patches/upstream/0019-lscpu-add-missing-Apple-parts.patch b/debian/patches/upstream/0019-lscpu-add-missing-Apple-parts.patch new file mode 100644 index 0000000..194613f --- /dev/null +++ b/debian/patches/upstream/0019-lscpu-add-missing-Apple-parts.patch @@ -0,0 +1,24 @@ +From: James Calligeros <jcalligeros99@gmail.com> +Date: Sat, 9 Jul 2022 15:08:41 +1000 +Subject: [PATCH 19/24] lscpu: add missing Apple parts + +Signed-off-by: James Calligeros <jcalligeros99@gmail.com> +--- + sys-utils/lscpu-arm.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c +index a266015..7d60f37 100644 +--- a/sys-utils/lscpu-arm.c ++++ b/sys-utils/lscpu-arm.c +@@ -163,6 +163,10 @@ static const struct id_part apple_part[] = { + { 0x021, "Firestorm (A14)" }, + { 0x022, "Icestorm (M1)" }, + { 0x023, "Firestorm (M1)" }, ++ { 0x024, "Icestorm (M1 Pro)" }, ++ { 0x025, "Firestorm (M1 Pro)" }, ++ { 0x028, "Icestorm (M1 Max)" }, ++ { 0x029, "Firestorm (M1 Max)" }, + { 0x030, "Blizzard (A15)" }, + { 0x031, "Avalanche (A15)" }, + { 0x032, "Blizzard (M2)" }, diff --git a/debian/patches/upstream/0020-lscpu-arm-don-t-use-space-in-names.patch b/debian/patches/upstream/0020-lscpu-arm-don-t-use-space-in-names.patch new file mode 100644 index 0000000..c1f1350 --- /dev/null +++ b/debian/patches/upstream/0020-lscpu-arm-don-t-use-space-in-names.patch @@ -0,0 +1,98 @@ +From: Karel Zak <kzak@redhat.com> +Date: Mon, 18 Jul 2022 12:37:25 +0200 +Subject: [PATCH 20/24] lscpu: (arm) don't use space in names + +It's seems better to be consistent and use the same convention for all +the names. + +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + sys-utils/lscpu-arm.c | 48 ++++++++++++++++++++++++------------------------ + 1 file changed, 24 insertions(+), 24 deletions(-) + +diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c +index 7d60f37..8b70669 100644 +--- a/sys-utils/lscpu-arm.c ++++ b/sys-utils/lscpu-arm.c +@@ -95,8 +95,8 @@ static const struct id_part arm_part[] = { + }; + + static const struct id_part brcm_part[] = { +- { 0x0f, "Brahma B15" }, +- { 0x100, "Brahma B53" }, ++ { 0x0f, "Brahma-B15" }, ++ { 0x100, "Brahma-B53" }, + { 0x516, "ThunderX2" }, + { -1, "unknown" }, + }; +@@ -109,10 +109,10 @@ static const struct id_part dec_part[] = { + + static const struct id_part cavium_part[] = { + { 0x0a0, "ThunderX" }, +- { 0x0a1, "ThunderX 88XX" }, +- { 0x0a2, "ThunderX 81XX" }, +- { 0x0a3, "ThunderX 83XX" }, +- { 0x0af, "ThunderX2 99xx" }, ++ { 0x0a1, "ThunderX-88XX" }, ++ { 0x0a2, "ThunderX-81XX" }, ++ { 0x0a3, "ThunderX-83XX" }, ++ { 0x0af, "ThunderX2-99xx" }, + { -1, "unknown" }, + }; + +@@ -129,11 +129,11 @@ static const struct id_part qcom_part[] = { + { 0x201, "Kryo" }, + { 0x205, "Kryo" }, + { 0x211, "Kryo" }, +- { 0x800, "Falkor V1/Kryo" }, +- { 0x801, "Kryo V2" }, +- { 0x803, "Kryo 3XX Silver" }, +- { 0x804, "Kryo 4XX Gold" }, +- { 0x805, "Kryo 4XX Silver" }, ++ { 0x800, "Falkor-V1/Kryo" }, ++ { 0x801, "Kryo-V2" }, ++ { 0x803, "Kryo-3XX-Silver" }, ++ { 0x804, "Kryo-4XX-Gold" }, ++ { 0x805, "Kryo-4XX-Silver" }, + { 0xc00, "Falkor" }, + { 0xc01, "Saphira" }, + { -1, "unknown" }, +@@ -152,25 +152,25 @@ static const struct id_part nvidia_part[] = { + }; + + static const struct id_part marvell_part[] = { +- { 0x131, "Feroceon 88FR131" }, ++ { 0x131, "Feroceon-88FR131" }, + { 0x581, "PJ4/PJ4b" }, + { 0x584, "PJ4B-MP" }, + { -1, "unknown" }, + }; + + static const struct id_part apple_part[] = { +- { 0x020, "Icestorm (A14)" }, +- { 0x021, "Firestorm (A14)" }, +- { 0x022, "Icestorm (M1)" }, +- { 0x023, "Firestorm (M1)" }, +- { 0x024, "Icestorm (M1 Pro)" }, +- { 0x025, "Firestorm (M1 Pro)" }, +- { 0x028, "Icestorm (M1 Max)" }, +- { 0x029, "Firestorm (M1 Max)" }, +- { 0x030, "Blizzard (A15)" }, +- { 0x031, "Avalanche (A15)" }, +- { 0x032, "Blizzard (M2)" }, +- { 0x033, "Avalanche (M2)" }, ++ { 0x020, "Icestorm-A14)" }, ++ { 0x021, "Firestorm-A14)" }, ++ { 0x022, "Icestorm-M1)" }, ++ { 0x023, "Firestorm-M1)" }, ++ { 0x024, "Icestorm-M1-Pro)" }, ++ { 0x025, "Firestorm-M1-Pro)" }, ++ { 0x028, "Icestorm-M1-Max)" }, ++ { 0x029, "Firestorm-M1-Max)" }, ++ { 0x030, "Blizzard-A15" }, ++ { 0x031, "Avalanche-A15" }, ++ { 0x032, "Blizzard-M2" }, ++ { 0x033, "Avalanche-M2" }, + { -1, "unknown" }, + }; + diff --git a/debian/patches/upstream/0021-Remove-closing-braces-in-Apple-cores-names.patch b/debian/patches/upstream/0021-Remove-closing-braces-in-Apple-cores-names.patch new file mode 100644 index 0000000..e3473c4 --- /dev/null +++ b/debian/patches/upstream/0021-Remove-closing-braces-in-Apple-cores-names.patch @@ -0,0 +1,35 @@ +From: ThomasKaiser <ThomasKaiser@users.noreply.github.com> +Date: Mon, 18 Jul 2022 12:56:44 +0200 +Subject: [PATCH 21/24] Remove closing braces in Apple cores names + +--- + sys-utils/lscpu-arm.c | 16 ++++++++-------- + 1 file changed, 8 insertions(+), 8 deletions(-) + +diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c +index 8b70669..ac3703e 100644 +--- a/sys-utils/lscpu-arm.c ++++ b/sys-utils/lscpu-arm.c +@@ -159,14 +159,14 @@ static const struct id_part marvell_part[] = { + }; + + static const struct id_part apple_part[] = { +- { 0x020, "Icestorm-A14)" }, +- { 0x021, "Firestorm-A14)" }, +- { 0x022, "Icestorm-M1)" }, +- { 0x023, "Firestorm-M1)" }, +- { 0x024, "Icestorm-M1-Pro)" }, +- { 0x025, "Firestorm-M1-Pro)" }, +- { 0x028, "Icestorm-M1-Max)" }, +- { 0x029, "Firestorm-M1-Max)" }, ++ { 0x020, "Icestorm-A14" }, ++ { 0x021, "Firestorm-A14" }, ++ { 0x022, "Icestorm-M1" }, ++ { 0x023, "Firestorm-M1" }, ++ { 0x024, "Icestorm-M1-Pro" }, ++ { 0x025, "Firestorm-M1-Pro" }, ++ { 0x028, "Icestorm-M1-Max" }, ++ { 0x029, "Firestorm-M1-Max" }, + { 0x030, "Blizzard-A15" }, + { 0x031, "Avalanche-A15" }, + { 0x032, "Blizzard-M2" }, diff --git a/debian/patches/upstream/0022-lscpu-Even-more-Arm-part-numbers.patch b/debian/patches/upstream/0022-lscpu-Even-more-Arm-part-numbers.patch new file mode 100644 index 0000000..3587520 --- /dev/null +++ b/debian/patches/upstream/0022-lscpu-Even-more-Arm-part-numbers.patch @@ -0,0 +1,42 @@ +From: Jeremy Linton <jeremy.linton@arm.com> +Date: Thu, 1 Sep 2022 16:52:30 -0500 +Subject: [PATCH 22/24] lscpu: Even more Arm part numbers + +Arm has published further MIDR/part numbers on +https://developer.arm.com/ip-products/processors/cortex-a. +Some of the new ones have already been merged, so lets +fill in the gaps with A34, A65AE and X1C. + +Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> +--- + sys-utils/lscpu-arm.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c +index ac3703e..9222b77 100644 +--- a/sys-utils/lscpu-arm.c ++++ b/sys-utils/lscpu-arm.c +@@ -64,6 +64,7 @@ static const struct id_part arm_part[] = { + { 0xc27, "Cortex-M7" }, + { 0xc60, "Cortex-M0+" }, + { 0xd01, "Cortex-A32" }, ++ { 0xd02, "Cortex-A34" }, + { 0xd03, "Cortex-A53" }, + { 0xd04, "Cortex-A35" }, + { 0xd05, "Cortex-A55" }, +@@ -82,6 +83,7 @@ static const struct id_part arm_part[] = { + { 0xd40, "Neoverse-V1" }, + { 0xd41, "Cortex-A78" }, + { 0xd42, "Cortex-A78AE" }, ++ { 0xd43, "Cortex-A65AE" }, + { 0xd44, "Cortex-X1" }, + { 0xd46, "Cortex-A510" }, + { 0xd47, "Cortex-A710" }, +@@ -89,6 +91,7 @@ static const struct id_part arm_part[] = { + { 0xd49, "Neoverse-N2" }, + { 0xd4a, "Neoverse-E1" }, + { 0xd4b, "Cortex-A78C" }, ++ { 0xd4c, "Cortex-X1C" }, + { 0xd4d, "Cortex-A715" }, + { 0xd4e, "Cortex-X3" }, + { -1, "unknown" }, diff --git a/debian/patches/upstream/0023-lscpu-Add-Kryo-3XX-Gold-core.patch b/debian/patches/upstream/0023-lscpu-Add-Kryo-3XX-Gold-core.patch new file mode 100644 index 0000000..8cb6575 --- /dev/null +++ b/debian/patches/upstream/0023-lscpu-Add-Kryo-3XX-Gold-core.patch @@ -0,0 +1,23 @@ +From: ThomasKaiser <ThomasKaiser@users.noreply.github.com> +Date: Fri, 30 Sep 2022 10:53:25 +0200 +Subject: [PATCH 23/24] lscpu: Add Kryo 3XX Gold core + +[kzak@redhat.com: - update patch to use '-' between words in CPU name] + +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + sys-utils/lscpu-arm.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c +index 9222b77..b30e0e7 100644 +--- a/sys-utils/lscpu-arm.c ++++ b/sys-utils/lscpu-arm.c +@@ -134,6 +134,7 @@ static const struct id_part qcom_part[] = { + { 0x211, "Kryo" }, + { 0x800, "Falkor-V1/Kryo" }, + { 0x801, "Kryo-V2" }, ++ { 0x802, "Kryo-3XX-Gold" }, + { 0x803, "Kryo-3XX-Silver" }, + { 0x804, "Kryo-4XX-Gold" }, + { 0x805, "Kryo-4XX-Silver" }, diff --git a/debian/patches/upstream/0024-fsck-Processes-may-kill-other-processes.patch b/debian/patches/upstream/0024-fsck-Processes-may-kill-other-processes.patch new file mode 100644 index 0000000..8820780 --- /dev/null +++ b/debian/patches/upstream/0024-fsck-Processes-may-kill-other-processes.patch @@ -0,0 +1,31 @@ +From: zhanchengbin <zhanchengbin1@huawei.com> +Date: Mon, 10 Oct 2022 17:23:24 +0800 +Subject: [PATCH 24/24] fsck: Processes may kill other processes. + +A error in disk-utils/fsck.c, if run the fsck -N command, processes +don't execute, just show what would be done. However, the pid whose +value is -1 is added to the instance_list list in the execute +function,if the kill_all function is called later, kill(-1, signum) +is executed, Signals are sent to all processes except the number one +process and itself. Other processes will be killed if they use the +default signal processing function. + +Signed-off-by: zhanchengbin <zhanchengbin1@huawei.com> +Reviewed-by: Lukas Czerner <lczerner@redhat.com> +--- + disk-utils/fsck.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/disk-utils/fsck.c b/disk-utils/fsck.c +index 505952c..800d3ce 100644 +--- a/disk-utils/fsck.c ++++ b/disk-utils/fsck.c +@@ -730,6 +730,8 @@ static int kill_all(int signum) + for (inst = instance_list; inst; inst = inst->next) { + if (inst->flags & FLAG_DONE) + continue; ++ if (inst->pid <= 0) ++ continue; + kill(inst->pid, signum); + n++; + } diff --git a/debian/patches/upstream/0025-libblkid-ntfs-avoid-UB-in-signed-shift.patch b/debian/patches/upstream/0025-libblkid-ntfs-avoid-UB-in-signed-shift.patch new file mode 100644 index 0000000..a212b04 --- /dev/null +++ b/debian/patches/upstream/0025-libblkid-ntfs-avoid-UB-in-signed-shift.patch @@ -0,0 +1,33 @@ +From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= <thomas@t-8ch.de> +Date: Thu, 10 Nov 2022 18:35:00 +0100 +Subject: [PATCH 25/26] libblkid: ntfs: avoid UB in signed shift + +Fix OSS-Fuzz issue 53142 ( #1886 ) +Fix OSS-Fuzz issue 53160 ( #1888 ) +--- + libblkid/src/superblocks/ntfs.c | 10 +++++++--- + 1 file changed, 7 insertions(+), 3 deletions(-) + +diff --git a/libblkid/src/superblocks/ntfs.c b/libblkid/src/superblocks/ntfs.c +index dced699..217e7e8 100644 +--- a/libblkid/src/superblocks/ntfs.c ++++ b/libblkid/src/superblocks/ntfs.c +@@ -135,11 +135,15 @@ static int __probe_ntfs(blkid_probe pr, const struct blkid_idmag *mag, int save_ + } + } + +- if (ns->clusters_per_mft_record > 0) ++ if (ns->clusters_per_mft_record > 0) { + mft_record_size = ns->clusters_per_mft_record * + sectors_per_cluster * sector_size; +- else +- mft_record_size = 1 << (0 - ns->clusters_per_mft_record); ++ } else { ++ int8_t mft_record_size_shift = 0 - ns->clusters_per_mft_record; ++ if (mft_record_size_shift < 0 || mft_record_size_shift >= 31) ++ return 1; ++ mft_record_size = 1 << mft_record_size_shift; ++ } + + nr_clusters = le64_to_cpu(ns->number_of_sectors) / sectors_per_cluster; + diff --git a/debian/patches/upstream/0026-libblkid-iso9660-allocate-enough-space-for-UTF16-dec.patch b/debian/patches/upstream/0026-libblkid-iso9660-allocate-enough-space-for-UTF16-dec.patch new file mode 100644 index 0000000..abaeed2 --- /dev/null +++ b/debian/patches/upstream/0026-libblkid-iso9660-allocate-enough-space-for-UTF16-dec.patch @@ -0,0 +1,120 @@ +From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= <thomas@t-8ch.de> +Date: Thu, 10 Nov 2022 19:48:20 +0100 +Subject: [PATCH 26/26] libblkid: iso9660: allocate enough space for UTF16 + decoding + +When merge_utf16be_ascii() encounters high-codepoint surrogate pairs it +emits four bytes of output for one byte of ascii input. +In addition with the remaining ascii characters from the second loop we +need up to 5 * sizeof(input) / 2 bytes as output buffer. + +As we decode up to 128 ascii characters with merge_utf16be_ascii() we +need 320 bytes of buffer available. + +Furthermore adapt merge_utf16be_ascii() to not write paste the output +buffer end. + +Fix OSS-Fuzz issue 53149 ( #1887 ) +--- + libblkid/src/superblocks/iso9660.c | 23 +++++++++++++---------- + 1 file changed, 13 insertions(+), 10 deletions(-) + +diff --git a/libblkid/src/superblocks/iso9660.c b/libblkid/src/superblocks/iso9660.c +index 289a325..8c3addc 100644 +--- a/libblkid/src/superblocks/iso9660.c ++++ b/libblkid/src/superblocks/iso9660.c +@@ -70,6 +70,8 @@ struct boot_record { + #define ISO_VD_SUPPLEMENTARY 0x2 + #define ISO_VD_END 0xff + #define ISO_VD_MAX 16 ++/* maximal string field size used anywhere in ISO; update if necessary */ ++#define ISO_MAX_FIELDSIZ sizeof(((struct iso_volume_descriptor *)0)->volume_set_id) + + struct high_sierra_volume_descriptor { + unsigned char foo[8]; +@@ -168,11 +170,11 @@ static int is_utf16be_str_empty(unsigned char *utf16, size_t len) + /* if @utf16 is prefix of @ascii (ignoring non-representable characters and upper-case conversion) + * then reconstruct prefix from @utf16 and @ascii, append suffix from @ascii, fill it into @out + * and returns length of bytes written into @out; otherwise returns zero */ +-static size_t merge_utf16be_ascii(unsigned char *out, const unsigned char *utf16, const unsigned char *ascii, size_t len) ++static size_t merge_utf16be_ascii(unsigned char *out, size_t out_len, const unsigned char *utf16, const unsigned char *ascii, size_t len) + { + size_t o, a, u; + +- for (o = 0, a = 0, u = 0; u + 1 < len && a < len; o += 2, a++, u += 2) { ++ for (o = 0, a = 0, u = 0; u + 1 < len && a < len && o + 1 < out_len; o += 2, a++, u += 2) { + /* Surrogate pair with code point above U+FFFF */ + if (utf16[u] >= 0xD8 && utf16[u] <= 0xDB && u + 3 < len && + utf16[u + 2] >= 0xDC && utf16[u + 2] <= 0xDF) { +@@ -194,7 +196,7 @@ static size_t merge_utf16be_ascii(unsigned char *out, const unsigned char *utf16 + } + } + +- for (; a < len; o += 2, a++) { ++ for (; a < len && o + 1 < out_len; o += 2, a++) { + out[o] = 0x00; + out[o + 1] = ascii[a]; + } +@@ -208,7 +210,8 @@ static int probe_iso9660(blkid_probe pr, const struct blkid_idmag *mag) + struct boot_record *boot = NULL; + struct iso_volume_descriptor *pvd = NULL; + struct iso_volume_descriptor *joliet = NULL; +- unsigned char buf[256]; ++ /* space for merge_utf16be_ascii(ISO_ID_BUFSIZ bytes) */ ++ unsigned char buf[ISO_MAX_FIELDSIZ * 5 / 2]; + size_t len; + int is_unicode_empty; + int is_ascii_empty; +@@ -251,14 +254,14 @@ static int probe_iso9660(blkid_probe pr, const struct blkid_idmag *mag) + + blkid_probe_set_block_size(pr, ISO_SECTOR_SIZE); + +- if (joliet && (len = merge_utf16be_ascii(buf, joliet->system_id, pvd->system_id, sizeof(pvd->system_id))) != 0) ++ if (joliet && (len = merge_utf16be_ascii(buf, sizeof(buf), joliet->system_id, pvd->system_id, sizeof(pvd->system_id))) != 0) + blkid_probe_set_utf8_id_label(pr, "SYSTEM_ID", buf, len, UL_ENCODE_UTF16BE); + else if (joliet) + blkid_probe_set_utf8_id_label(pr, "SYSTEM_ID", joliet->system_id, sizeof(joliet->system_id), UL_ENCODE_UTF16BE); + else + blkid_probe_set_id_label(pr, "SYSTEM_ID", pvd->system_id, sizeof(pvd->system_id)); + +- if (joliet && (len = merge_utf16be_ascii(buf, joliet->volume_set_id, pvd->volume_set_id, sizeof(pvd->volume_set_id))) != 0) ++ if (joliet && (len = merge_utf16be_ascii(buf, sizeof(buf), joliet->volume_set_id, pvd->volume_set_id, sizeof(pvd->volume_set_id))) != 0) + blkid_probe_set_utf8_id_label(pr, "VOLUME_SET_ID", buf, len, UL_ENCODE_UTF16BE); + else if (joliet) + blkid_probe_set_utf8_id_label(pr, "VOLUME_SET_ID", joliet->volume_set_id, sizeof(joliet->volume_set_id), UL_ENCODE_UTF16BE); +@@ -267,7 +270,7 @@ static int probe_iso9660(blkid_probe pr, const struct blkid_idmag *mag) + + is_ascii_empty = (is_str_empty(pvd->publisher_id, sizeof(pvd->publisher_id)) || pvd->publisher_id[0] == '_'); + is_unicode_empty = (!joliet || is_utf16be_str_empty(joliet->publisher_id, sizeof(joliet->publisher_id)) || (joliet->publisher_id[0] == 0x00 && joliet->publisher_id[1] == '_')); +- if (!is_unicode_empty && !is_ascii_empty && (len = merge_utf16be_ascii(buf, joliet->publisher_id, pvd->publisher_id, sizeof(pvd->publisher_id))) != 0) ++ if (!is_unicode_empty && !is_ascii_empty && (len = merge_utf16be_ascii(buf, sizeof(buf), joliet->publisher_id, pvd->publisher_id, sizeof(pvd->publisher_id))) != 0) + blkid_probe_set_utf8_id_label(pr, "PUBLISHER_ID", buf, len, UL_ENCODE_UTF16BE); + else if (!is_unicode_empty) + blkid_probe_set_utf8_id_label(pr, "PUBLISHER_ID", joliet->publisher_id, sizeof(joliet->publisher_id), UL_ENCODE_UTF16BE); +@@ -276,7 +279,7 @@ static int probe_iso9660(blkid_probe pr, const struct blkid_idmag *mag) + + is_ascii_empty = (is_str_empty(pvd->data_preparer_id, sizeof(pvd->data_preparer_id)) || pvd->data_preparer_id[0] == '_'); + is_unicode_empty = (!joliet || is_utf16be_str_empty(joliet->data_preparer_id, sizeof(joliet->data_preparer_id)) || (joliet->data_preparer_id[0] == 0x00 && joliet->data_preparer_id[1] == '_')); +- if (!is_unicode_empty && !is_ascii_empty && (len = merge_utf16be_ascii(buf, joliet->data_preparer_id, pvd->data_preparer_id, sizeof(pvd->data_preparer_id))) != 0) ++ if (!is_unicode_empty && !is_ascii_empty && (len = merge_utf16be_ascii(buf, sizeof(buf), joliet->data_preparer_id, pvd->data_preparer_id, sizeof(pvd->data_preparer_id))) != 0) + blkid_probe_set_utf8_id_label(pr, "DATA_PREPARER_ID", buf, len, UL_ENCODE_UTF16BE); + else if (!is_unicode_empty) + blkid_probe_set_utf8_id_label(pr, "DATA_PREPARER_ID", joliet->data_preparer_id, sizeof(joliet->data_preparer_id), UL_ENCODE_UTF16BE); +@@ -285,7 +288,7 @@ static int probe_iso9660(blkid_probe pr, const struct blkid_idmag *mag) + + is_ascii_empty = (is_str_empty(pvd->application_id, sizeof(pvd->application_id)) || pvd->application_id[0] == '_'); + is_unicode_empty = (!joliet || is_utf16be_str_empty(joliet->application_id, sizeof(joliet->application_id)) || (joliet->application_id[0] == 0x00 && joliet->application_id[1] == '_')); +- if (!is_unicode_empty && !is_ascii_empty && (len = merge_utf16be_ascii(buf, joliet->application_id, pvd->application_id, sizeof(pvd->application_id))) != 0) ++ if (!is_unicode_empty && !is_ascii_empty && (len = merge_utf16be_ascii(buf, sizeof(buf), joliet->application_id, pvd->application_id, sizeof(pvd->application_id))) != 0) + blkid_probe_set_utf8_id_label(pr, "APPLICATION_ID", buf, len, UL_ENCODE_UTF16BE); + else if (!is_unicode_empty) + blkid_probe_set_utf8_id_label(pr, "APPLICATION_ID", joliet->application_id, sizeof(joliet->application_id), UL_ENCODE_UTF16BE); +@@ -310,7 +313,7 @@ static int probe_iso9660(blkid_probe pr, const struct blkid_idmag *mag) + * version of label in PVD. Based on these facts try to reconstruct original label if label + * in Joliet is prefix of the label in PVD (ignoring non-representable characters). + */ +- if (joliet && (len = merge_utf16be_ascii(buf, joliet->volume_id, pvd->volume_id, sizeof(pvd->volume_id))) != 0) ++ if (joliet && (len = merge_utf16be_ascii(buf, sizeof(buf), joliet->volume_id, pvd->volume_id, sizeof(pvd->volume_id))) != 0) + blkid_probe_set_utf8label(pr, buf, len, UL_ENCODE_UTF16BE); + else if (joliet) + blkid_probe_set_utf8label(pr, joliet->volume_id, sizeof(joliet->volume_id), UL_ENCODE_UTF16BE); diff --git a/debian/patches/upstream/PATCH-1-2-lib-pty-Put-master-PTY-into-non-blocking-mode-a.patch b/debian/patches/upstream/PATCH-1-2-lib-pty-Put-master-PTY-into-non-blocking-mode-a.patch new file mode 100644 index 0000000..341e29b --- /dev/null +++ b/debian/patches/upstream/PATCH-1-2-lib-pty-Put-master-PTY-into-non-blocking-mode-a.patch @@ -0,0 +1,269 @@ +From: =?utf-8?b?0L3QsNCx?= <nabijaczleweli@nabijaczleweli.xyz> +Date: Tue, 12 Apr 2022 16:25:14 +0200 +Subject: [PATCH 1/2] lib/pty: Put master PTY into non-blocking mode and + buffer its output to avoid deadlock + +If we filled the script->child buffer before the child had a chance to read any +input, we'd sleep forever in write_all(pty->master), and the child would sleep +forever in write(1<pty->slave>) + +By putting the master PTY in non-blocking mode, we can poll(pty->master, +POLLOUT) and keep supplying more data as the child reads from the buffer + +Fixes Debian bug #1003095 + +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + include/pty-session.h | 7 +++ + lib/pty-session.c | 126 +++++++++++++++++++++++++++++++++++++++++--------- + 2 files changed, 110 insertions(+), 23 deletions(-) + +diff --git a/include/pty-session.h b/include/pty-session.h +index 09eff43..7176d6b 100644 +--- a/include/pty-session.h ++++ b/include/pty-session.h +@@ -81,6 +81,13 @@ struct ul_pty { + + struct timeval next_callback_time; + ++ struct ul_pty_child_buffer { ++ struct ul_pty_child_buffer *next; ++ char buf[BUFSIZ]; ++ size_t size, cursor; ++ unsigned int final_input:1; /* drain child before writing */ ++ } *child_buffer_head, *child_buffer_tail, *free_buffers; ++ + unsigned int isterm:1, /* is stdin terminal? */ + slave_echo:1; /* keep ECHO on pty slave */ + }; +diff --git a/lib/pty-session.c b/lib/pty-session.c +index 6f038e1..880f08d 100644 +--- a/lib/pty-session.c ++++ b/lib/pty-session.c +@@ -69,6 +69,15 @@ struct ul_pty *ul_new_pty(int is_stdin_tty) + + void ul_free_pty(struct ul_pty *pty) + { ++ struct ul_pty_child_buffer *hd; ++ while((hd = pty->child_buffer_head)) { ++ pty->child_buffer_head = hd->next; ++ free(hd); ++ } ++ while((hd = pty->free_buffers)) { ++ pty->free_buffers = hd->next; ++ free(hd); ++ } + free(pty); + } + +@@ -182,7 +191,7 @@ int ul_pty_setup(struct ul_pty *pty) + cfmakeraw(&attrs); + tcsetattr(STDIN_FILENO, TCSANOW, &attrs); + } else { +- DBG(SETUP, ul_debugobj(pty, "create for non-terminal")); ++ DBG(SETUP, ul_debugobj(pty, "create for non-terminal")); + + rc = openpty(&pty->master, &pty->slave, NULL, NULL, NULL); + if (rc) +@@ -198,6 +207,8 @@ int ul_pty_setup(struct ul_pty *pty) + tcsetattr(pty->slave, TCSANOW, &attrs); + } + ++ fcntl(pty->master, F_SETFL, O_NONBLOCK); ++ + sigfillset(&ourset); + if (sigprocmask(SIG_BLOCK, &ourset, NULL)) { + rc = -errno; +@@ -290,9 +301,27 @@ static int write_output(char *obuf, ssize_t bytes) + return 0; + } + +-static int write_to_child(struct ul_pty *pty, char *buf, size_t bufsz) ++static int schedule_child_write(struct ul_pty *pty, char *buf, size_t bufsz, int final) + { +- return write_all(pty->master, buf, bufsz); ++ struct ul_pty_child_buffer *stash; ++ if (pty->free_buffers) { ++ stash = pty->free_buffers; ++ pty->free_buffers = stash->next; ++ memset(stash, 0, sizeof(*stash)); ++ } else ++ stash = calloc(1, sizeof(*stash)); ++ if (!stash) ++ return -1; ++ ++ memcpy(stash->buf, buf, bufsz); ++ stash->size = bufsz; ++ stash->final_input = final ? 1 : 0; ++ ++ if (pty->child_buffer_head) ++ pty->child_buffer_tail = pty->child_buffer_tail->next = stash; ++ else ++ pty->child_buffer_head = pty->child_buffer_tail = stash; ++ return 0; + } + + /* +@@ -311,16 +340,13 @@ static int write_to_child(struct ul_pty *pty, char *buf, size_t bufsz) + * maintains master+slave tty stuff within the session. Use pipe to write to + * pty and assume non-interactive (tee-like) behavior is NOT well supported. + */ +-void ul_pty_write_eof_to_child(struct ul_pty *pty) ++static void drain_child_buffers(struct ul_pty *pty) + { + unsigned int tries = 0; +- struct pollfd fds[] = { +- { .fd = pty->slave, .events = POLLIN } +- }; +- char c = DEF_EOF; ++ struct pollfd fd = { .fd = pty->slave, .events = POLLIN }; + + DBG(IO, ul_debugobj(pty, " waiting for empty slave")); +- while (poll(fds, 1, 10) == 1 && tries < 8) { ++ while (poll(&fd, 1, 10) == 1 && tries < 8) { + DBG(IO, ul_debugobj(pty, " slave is not empty")); + xusleep(250000); + tries++; +@@ -329,7 +355,53 @@ void ul_pty_write_eof_to_child(struct ul_pty *pty) + DBG(IO, ul_debugobj(pty, " slave is empty now")); + + DBG(IO, ul_debugobj(pty, " sending EOF to master")); +- write_to_child(pty, &c, sizeof(char)); ++} ++ ++static int flush_child_buffers(struct ul_pty *pty, int *anything) ++{ ++ int ret = 0, any = 0; ++ while (pty->child_buffer_head) { ++ struct ul_pty_child_buffer *hd = pty->child_buffer_head; ++ ++ if(hd->final_input) ++ drain_child_buffers(pty); ++ ++ DBG(IO, ul_debugobj(hd, " stdin --> master trying %zu bytes", hd->size - hd->cursor)); ++ ssize_t ret = write(pty->master, hd->buf + hd->cursor, hd->size - hd->cursor); ++ if (ret == -1) { ++ DBG(IO, ul_debugobj(hd, " EAGAIN")); ++ if (!(errno == EINTR || errno == EAGAIN)) ++ ret = -errno; ++ goto out; ++ } ++ DBG(IO, ul_debugobj(hd, " wrote %zd", ret)); ++ any = 1; ++ hd->cursor += ret; ++ if (hd->cursor == hd->size) { ++ pty->child_buffer_head = hd->next; ++ if(!hd->next) ++ pty->child_buffer_tail = NULL; ++ ++ hd->next = pty->free_buffers; ++ pty->free_buffers = hd; ++ } ++ } ++ ++out: ++ /* without sync write_output() will write both input & ++ * shell output that looks like double echoing */ ++ if (any) ++ fdatasync(pty->master); ++ ++ if (anything) ++ *anything = any; ++ return ret; ++} ++ ++void ul_pty_write_eof_to_child(struct ul_pty *pty) ++{ ++ char c = DEF_EOF; ++ schedule_child_write(pty, &c, sizeof(char), 1); + } + + static int mainloop_callback(struct ul_pty *pty) +@@ -362,7 +434,7 @@ static int handle_io(struct ul_pty *pty, int fd, int *eof) + /* read from active FD */ + bytes = read(fd, buf, sizeof(buf)); + sigprocmask(SIG_BLOCK, &set, NULL); +- if (bytes < 0) { ++ if (bytes == -1) { + if (errno == EAGAIN || errno == EINTR) + return 0; + return -errno; +@@ -375,15 +447,11 @@ static int handle_io(struct ul_pty *pty, int fd, int *eof) + + /* from stdin (user) to command */ + if (fd == STDIN_FILENO) { +- DBG(IO, ul_debugobj(pty, " stdin --> master %zd bytes", bytes)); ++ DBG(IO, ul_debugobj(pty, " stdin --> master %zd bytes queued", bytes)); + +- if (write_to_child(pty, buf, bytes)) ++ if (schedule_child_write(pty, buf, bytes, 0)) + return -errno; + +- /* without sync write_output() will write both input & +- * shell output that looks like double echoing */ +- fdatasync(pty->master); +- + /* from command (master) to stdout */ + } else if (fd == pty->master) { + DBG(IO, ul_debugobj(pty, " master --> stdout %zd bytes", bytes)); +@@ -567,6 +635,11 @@ int ul_pty_proxy_master(struct ul_pty *pty) + } else + timeout = pty->poll_timeout; + ++ if (pty->child_buffer_head) ++ pfd[POLLFD_MASTER].events |= POLLOUT; ++ else ++ pfd[POLLFD_MASTER].events &= ~POLLOUT; ++ + /* wait for input, signal or timeout */ + DBG(IO, ul_debugobj(pty, "calling poll() [timeout=%dms]", timeout)); + ret = poll(pfd, ARRAY_SIZE(pfd), timeout); +@@ -600,23 +673,30 @@ int ul_pty_proxy_master(struct ul_pty *pty) + if (pfd[i].revents == 0) + continue; + +- DBG(IO, ul_debugobj(pty, " active pfd[%s].fd=%d %s %s %s %s", ++ DBG(IO, ul_debugobj(pty, " active pfd[%s].fd=%d %s %s %s %s %s", + i == POLLFD_STDIN ? "stdin" : + i == POLLFD_MASTER ? "master" : + i == POLLFD_SIGNAL ? "signal" : "???", + pfd[i].fd, + pfd[i].revents & POLLIN ? "POLLIN" : "", ++ pfd[i].revents & POLLOUT ? "POLLOUT" : "", + pfd[i].revents & POLLHUP ? "POLLHUP" : "", + pfd[i].revents & POLLERR ? "POLLERR" : "", + pfd[i].revents & POLLNVAL ? "POLLNVAL" : "")); + + if (i == POLLFD_SIGNAL) + rc = handle_signal(pty, pfd[i].fd); +- else if (pfd[i].revents & POLLIN) +- rc = handle_io(pty, pfd[i].fd, &eof); /* data */ ++ else { ++ if (pfd[i].revents & POLLIN) ++ rc = handle_io(pty, pfd[i].fd, &eof); /* data */ ++ if (pfd[i].revents & POLLOUT) /* i == POLLFD_MASTER */ ++ rc = flush_child_buffers(pty, NULL); ++ } + + if (rc) { + ul_pty_write_eof_to_child(pty); ++ for (int anything = 1; anything;) ++ flush_child_buffers(pty, &anything); + break; + } + +@@ -631,11 +711,11 @@ int ul_pty_proxy_master(struct ul_pty *pty) + */ + if ((pfd[i].revents & POLLHUP) || (pfd[i].revents & POLLNVAL) || eof) { + DBG(IO, ul_debugobj(pty, " ignore FD")); +- pfd[i].fd = -1; + if (i == POLLFD_STDIN) { ++ pfd[i].fd = -1; + ul_pty_write_eof_to_child(pty); +- DBG(IO, ul_debugobj(pty, " ignore STDIN")); +- } ++ } else /* i == POLLFD_MASTER */ ++ pfd[i].revents &= ~POLLIN; + } + } + if (rc) diff --git a/debian/patches/upstream/PATCH-2-2-lib-pty-minor-cleanups.patch b/debian/patches/upstream/PATCH-2-2-lib-pty-minor-cleanups.patch new file mode 100644 index 0000000..e41f11d --- /dev/null +++ b/debian/patches/upstream/PATCH-2-2-lib-pty-minor-cleanups.patch @@ -0,0 +1,119 @@ +From: Karel Zak <kzak@redhat.com> +Date: Tue, 19 Apr 2022 12:28:09 +0200 +Subject: [PATCH 2/2] lib/pty: minor cleanups + +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + lib/pty-session.c | 31 +++++++++++++++++++++---------- + 1 file changed, 21 insertions(+), 10 deletions(-) + +diff --git a/lib/pty-session.c b/lib/pty-session.c +index 880f08d..360adb6 100644 +--- a/lib/pty-session.c ++++ b/lib/pty-session.c +@@ -70,11 +70,13 @@ struct ul_pty *ul_new_pty(int is_stdin_tty) + void ul_free_pty(struct ul_pty *pty) + { + struct ul_pty_child_buffer *hd; +- while((hd = pty->child_buffer_head)) { ++ ++ while ((hd = pty->child_buffer_head)) { + pty->child_buffer_head = hd->next; + free(hd); + } +- while((hd = pty->free_buffers)) { ++ ++ while ((hd = pty->free_buffers)) { + pty->free_buffers = hd->next; + free(hd); + } +@@ -304,6 +306,7 @@ static int write_output(char *obuf, ssize_t bytes) + static int schedule_child_write(struct ul_pty *pty, char *buf, size_t bufsz, int final) + { + struct ul_pty_child_buffer *stash; ++ + if (pty->free_buffers) { + stash = pty->free_buffers; + pty->free_buffers = stash->next; +@@ -313,6 +316,8 @@ static int schedule_child_write(struct ul_pty *pty, char *buf, size_t bufsz, int + if (!stash) + return -1; + ++ assert(bufsz <= sizeof(stash->buf)); ++ + memcpy(stash->buf, buf, bufsz); + stash->size = bufsz; + stash->final_input = final ? 1 : 0; +@@ -359,34 +364,37 @@ static void drain_child_buffers(struct ul_pty *pty) + + static int flush_child_buffers(struct ul_pty *pty, int *anything) + { +- int ret = 0, any = 0; ++ int rc = 0, any = 0; ++ + while (pty->child_buffer_head) { + struct ul_pty_child_buffer *hd = pty->child_buffer_head; ++ ssize_t ret; + +- if(hd->final_input) ++ if (hd->final_input) + drain_child_buffers(pty); + + DBG(IO, ul_debugobj(hd, " stdin --> master trying %zu bytes", hd->size - hd->cursor)); +- ssize_t ret = write(pty->master, hd->buf + hd->cursor, hd->size - hd->cursor); ++ ++ ret = write(pty->master, hd->buf + hd->cursor, hd->size - hd->cursor); + if (ret == -1) { + DBG(IO, ul_debugobj(hd, " EAGAIN")); + if (!(errno == EINTR || errno == EAGAIN)) +- ret = -errno; ++ rc = -errno; + goto out; + } + DBG(IO, ul_debugobj(hd, " wrote %zd", ret)); + any = 1; + hd->cursor += ret; ++ + if (hd->cursor == hd->size) { + pty->child_buffer_head = hd->next; +- if(!hd->next) ++ if (!hd->next) + pty->child_buffer_tail = NULL; + + hd->next = pty->free_buffers; + pty->free_buffers = hd; + } + } +- + out: + /* without sync write_output() will write both input & + * shell output that looks like double echoing */ +@@ -395,7 +403,7 @@ out: + + if (anything) + *anything = any; +- return ret; ++ return rc; + } + + void ul_pty_write_eof_to_child(struct ul_pty *pty) +@@ -635,6 +643,7 @@ int ul_pty_proxy_master(struct ul_pty *pty) + } else + timeout = pty->poll_timeout; + ++ /* use POLLOUT (aka "writing is now possible") if data queued */ + if (pty->child_buffer_head) + pfd[POLLFD_MASTER].events |= POLLOUT; + else +@@ -694,8 +703,10 @@ int ul_pty_proxy_master(struct ul_pty *pty) + } + + if (rc) { ++ int anything = 1; ++ + ul_pty_write_eof_to_child(pty); +- for (int anything = 1; anything;) ++ for (anything = 1; anything;) + flush_child_buffers(pty, &anything); + break; + } diff --git a/debian/patches/upstream/PATCH-rfkill-man-List-options-for-supported-device-types.patch b/debian/patches/upstream/PATCH-rfkill-man-List-options-for-supported-device-types.patch new file mode 100644 index 0000000..9762a84 --- /dev/null +++ b/debian/patches/upstream/PATCH-rfkill-man-List-options-for-supported-device-types.patch @@ -0,0 +1,23 @@ +From: Karel Zak <kzak@redhat.com> +Date: Mon, 5 Sep 2022 09:14:45 +0200 +Subject: [PATCH] rfkill: (man) List options for supported device types + +Fixes: https://github.com/util-linux/util-linux/issues/1790 +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + sys-utils/rfkill.8.adoc | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/sys-utils/rfkill.8.adoc b/sys-utils/rfkill.8.adoc +index 2086798..e58fc75 100644 +--- a/sys-utils/rfkill.8.adoc ++++ b/sys-utils/rfkill.8.adoc +@@ -50,7 +50,7 @@ Display help text and exit. + Listen for rfkill events and display them on stdout. + + *list* [__id__|__type__ ...]:: +-List the current state of all available devices. The command output format is deprecated, see the *DESCRIPTION* section. It is a good idea to check with *list* command _id_ or _type_ scope is appropriate before setting *block* or *unblock*. Special _all_ type string will match everything. Use of multiple _ID_ or _type_ arguments is supported. ++List the current state of all available devices. The command output format is deprecated, see the *DESCRIPTION* section. It is a good idea to check with *list* command _id_ or _type_ scope is appropriate before setting *block* or *unblock*. Special _all_ type string will match everything. Use of multiple _ID_ or _type_ arguments is supported. Possible types are all, {wlan | wifi}, bluetooth, {uwb | ultrawideband}, wimax, wwan, gps, fm, nfc. + + **block** __id__|__type__ [...]:: + Disable the corresponding device. diff --git a/debian/patches/upstream/PATCH-script-abort-if-unused-arguments-are-given.patch b/debian/patches/upstream/PATCH-script-abort-if-unused-arguments-are-given.patch new file mode 100644 index 0000000..98b2668 --- /dev/null +++ b/debian/patches/upstream/PATCH-script-abort-if-unused-arguments-are-given.patch @@ -0,0 +1,56 @@ +From: Chris Hofstaedtler <zeha@debian.org> +Date: Fri, 18 Nov 2022 13:23:37 +0000 +Subject: [PATCH] script: abort if unused arguments are given +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 8bit + +scripts uses either a free-standing "file" argument, or the value +passed as --log-out "file". Additional filenames are ignored. +They are also ignored if --log-in "file" is given, as it turns off +output logging by default (can still be overriden by adding --log-out). +Avoid surprises when passing multiple filenames by writing usage +message instead. + +[kzak@redhat.com: - use errtryhelp() rather than usage()] + +Signed-off-by: Chris Hofstaedtler <zeha@debian.org> +Reported-by: наб <nabijaczleweli@nabijaczleweli.xyz> +Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1016193 +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + term-utils/script.c | 13 +++++++++++-- + 1 file changed, 11 insertions(+), 2 deletions(-) + +diff --git a/term-utils/script.c b/term-utils/script.c +index c918ecd..e03a1c3 100644 +--- a/term-utils/script.c ++++ b/term-utils/script.c +@@ -889,9 +889,11 @@ int main(int argc, char **argv) + + /* default if no --log-* specified */ + if (!outfile && !infile) { +- if (argc > 0) ++ if (argc > 0) { + outfile = argv[0]; +- else { ++ argc--; ++ argv++; ++ } else { + die_if_link(&ctl, DEFAULT_TYPESCRIPT_FILENAME); + outfile = DEFAULT_TYPESCRIPT_FILENAME; + } +@@ -900,6 +902,13 @@ int main(int argc, char **argv) + log_associate(&ctl, &ctl.out, outfile, SCRIPT_FMT_RAW); + } + ++ if (argc > 0) { ++ /* only one filename is accepted. if --log-out was given, ++ * freestanding filename is ignored */ ++ warnx(_("unexpected number of arguments")); ++ errtryhelp(EXIT_FAILURE); ++ } ++ + if (timingfile) { + /* the old SCRIPT_FMT_TIMING_SIMPLE should be used when + * recoding output only (just for backward compatibility), diff --git a/debian/patches/upstream/logger-always-update-header-when-read-from-stdin.patch b/debian/patches/upstream/logger-always-update-header-when-read-from-stdin.patch new file mode 100644 index 0000000..02e0bd8 --- /dev/null +++ b/debian/patches/upstream/logger-always-update-header-when-read-from-stdin.patch @@ -0,0 +1,94 @@ +From: Karel Zak <kzak@redhat.com> +Date: Tue, 1 Nov 2022 10:30:06 +0100 +Subject: logger: always update header when read from stdin + +The current code updates the header only when the priority has been +changed. It's incorrect because wanted is a valid header or each entry +(don't forget that logger for stdin use-case is used in pipe to log +long-time running processes). + +This patch also fixes the initial timestamp; it was originally generated +on logger startup, it now generates the header on the first message. + +$ (sleep 2; date; sleep 2; date; sleep 2; date) | logger --stderr --no-act + +old: +<13>Nov 1 10:42:14 kzak: Tue Nov 1 10:42:16 AM CET 2022 +<13>Nov 1 10:42:14 kzak: Tue Nov 1 10:42:18 AM CET 2022 +<13>Nov 1 10:42:14 kzak: Tue Nov 1 10:42:20 AM CET 2022 + +new: +<13>Nov 1 10:19:02 kzak: Tue Nov 1 10:19:02 AM CET 2022 +<13>Nov 1 10:19:04 kzak: Tue Nov 1 10:19:04 AM CET 2022 +<13>Nov 1 10:19:06 kzak: Tue Nov 1 10:19:06 AM CET 2022 + +Fixes: https://github.com/util-linux/util-linux/issues/1866 +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + misc-utils/logger.c | 18 +++++++----------- + 1 file changed, 7 insertions(+), 11 deletions(-) + +diff --git a/misc-utils/logger.c b/misc-utils/logger.c +index bec684f..e2b0b41 100644 +--- a/misc-utils/logger.c ++++ b/misc-utils/logger.c +@@ -945,8 +945,6 @@ static void logger_open(struct logger_ctl *ctl) + ctl->tag = ctl->login = xgetlogin(); + if (!ctl->tag) + ctl->tag = "<someone>"; +- +- generate_syslog_header(ctl); + } + + /* re-open; usually after failed connection */ +@@ -996,10 +994,8 @@ static void logger_stdin(struct logger_ctl *ctl) + { + /* note: we re-generate the syslog header for each log message to + * update header timestamps and to reflect possible priority changes. +- * The initial header is generated by logger_open(). + */ + int default_priority = ctl->pri; +- int last_pri = default_priority; + char *buf = xmalloc(ctl->max_message_size + 2 + 2); + int pri; + int c; +@@ -1026,10 +1022,6 @@ static void logger_stdin(struct logger_ctl *ctl) + } else + ctl->pri = default_priority; + +- if (ctl->pri != last_pri) { +- generate_syslog_header(ctl); +- last_pri = ctl->pri; +- } + if (c != EOF && c != '\n') + c = getchar(); + } +@@ -1040,8 +1032,10 @@ static void logger_stdin(struct logger_ctl *ctl) + } + buf[i] = '\0'; + +- if (i > 0 || !ctl->skip_empty_lines) ++ if (i > 0 || !ctl->skip_empty_lines) { ++ generate_syslog_header(ctl); + write_output(ctl, buf); ++ } + + if (c == '\n') /* discard line terminator */ + c = getchar(); +@@ -1317,12 +1311,14 @@ int main(int argc, char **argv) + abort(); + } + logger_open(&ctl); +- if (0 < argc) ++ if (0 < argc) { ++ generate_syslog_header(&ctl); + logger_command_line(&ctl, argv); +- else ++ } else + /* Note. --file <arg> reopens stdin making the below + * function to be used for file inputs. */ + logger_stdin(&ctl); ++ + logger_close(&ctl); + return EXIT_SUCCESS; + } |