From 440a048f0f3aab9cfcb7be716a501766e32a8793 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Sat, 14 May 2022 03:14:50 +0800 Subject: [PATCH 1/8] Add support for /bin/static-sh as fallback if the regular shell fails to execute Bug-Ubuntu: https://launchpad.net/bugs/505887 Gbp-Pq: Name sulogin-fallback-static-sh.patch --- login-utils/sulogin.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/login-utils/sulogin.c b/login-utils/sulogin.c index 9091caf..2341cff 100644 --- a/login-utils/sulogin.c +++ b/login-utils/sulogin.c @@ -795,6 +795,11 @@ static void sushell(struct passwd *pwd) xsetenv("SHELL", "/bin/sh", 1); execl("/bin/sh", profile ? "-sh" : "sh", NULL); warn(_("failed to execute %s"), "/bin/sh"); + + /* Fall back to static shell */ + setenv("SHELL", "/bin/static-sh", 1); + execl("/bin/static-sh", profile ? "-sh" : "sh", NULL); + warn(_("failed to execute %s"), "/bin/static-sh"); } static void usage(void) From 847bb97f4282b188c88bbc1aeb7da702f76af494 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Sat, 14 May 2022 03:14:50 +0800 Subject: [PATCH 2/8] Make sure file systems can be fixed on machines with locked root accounts (as Ubuntu does by default). Don't require --force for sulogin. Bug-Debian: https://bugs.debian.org/326678 Gbp-Pq: Name sulogin-lockedpwd.patch --- login-utils/sulogin.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/login-utils/sulogin.c b/login-utils/sulogin.c index 2341cff..eb2c2a0 100644 --- a/login-utils/sulogin.c +++ b/login-utils/sulogin.c @@ -983,7 +983,8 @@ int main(int argc, char **argv) const char *passwd = pwd->pw_passwd; const char *answer; int doshell = 0; - int deny = !opt_e && locked_account_password(pwd->pw_passwd); + /* Ubuntu's root account is locked by default allow access without --force */ + int deny = 0; doprompt(passwd, con, deny); From 2581103b715bd06e78f38a7684b9da41439de6f3 Mon Sep 17 00:00:00 2001 From: Ubuntu Developers Date: Sat, 14 May 2022 03:14:50 +0800 Subject: [PATCH 3/8] fstrim shouldn't run inside a container Container type implies the following products: openvz OpenVZ/Virtuozzo lxc Linux container implementation by LXC lxc-libvirt Linux container implementation by libvirt systemd-nspawn systemd's minimal container implementation, see systemd-nspawn(1) docker Docker container manager podman Podman container manager rkt rkt app container runtime wsl Windows Subsystem for Linux References: https://www.freedesktop.org/software/systemd/man/systemd.unit.html https://www.freedesktop.org/software/systemd/man/systemd-detect-virt.html# Fix: #840 Author: Eric Desrochers Origin: upstream, https://github.com/karelzak/util-linux/commit/0280d31a2bd6292acd9a4b86d0f6b5feb275a618 Bug: https://github.com/karelzak/util-linux/issues/840 Bug-Ubuntu: https://launchpad.net/bugs/1589289 Gbp-Pq: Name prevent-fstrim-inside-container.patch --- sys-utils/fstrim.service.in | 1 + sys-utils/fstrim.timer | 1 + 2 files changed, 2 insertions(+) diff --git a/sys-utils/fstrim.service.in b/sys-utils/fstrim.service.in index 516023e..c0090e1 100644 --- a/sys-utils/fstrim.service.in +++ b/sys-utils/fstrim.service.in @@ -1,6 +1,7 @@ [Unit] Description=Discard unused blocks on filesystems from /etc/fstab Documentation=man:fstrim(8) +ConditionVirtualization=!container [Service] Type=oneshot diff --git a/sys-utils/fstrim.timer b/sys-utils/fstrim.timer index 3a3762d..563dd45 100644 --- a/sys-utils/fstrim.timer +++ b/sys-utils/fstrim.timer @@ -1,6 +1,7 @@ [Unit] Description=Discard unused blocks once a week Documentation=man:fstrim +ConditionVirtualization=!container [Timer] OnCalendar=weekly From 8de924cffcfb00899f2014c020ee12d2122c3798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Mollier?= Date: Sat, 14 May 2022 03:14:50 +0800 Subject: [PATCH 4/8] Reimplement umount completion to not use gawk's gensub. Gbp-Pq: Name umount-completion.patch --- bash-completion/umount | 61 +++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/bash-completion/umount b/bash-completion/umount index 7fc2bd3..55d3102 100644 --- a/bash-completion/umount +++ b/bash-completion/umount @@ -1,3 +1,33 @@ +_umount_points_list() +{ + # List of characters to escape, shamelessly stolen from "scp" comp. + local escape_chars='[][(){}<>\",:;^&!$=?`|\\'\'' \t\f\n\r\v]' + + # This is most odd, but we are adding artifically a space after the + # file name because, somehow, it enables proper escaping of dangerous + # characters, e.g. "|" -> "\|". Without space, it is possible to get + # either 0 "|" or 2 "\\|" backslashes, but 1 does not work. Also, + # sticking to sub() and gsub(), instead of gensub(), allows to be AWK + # implementation agnostic. + findmnt -lno TARGET | awk '{ + if ($0 ~ "^"ENVIRON["HOME"]) { + homeless = $0 + sub("^"ENVIRON["HOME"], "~", homeless) + gsub("'"$escape_chars"'", "\\\\&", homeless) + print homeless " " + } + if ($0 ~ "^"ENVIRON["PWD"]) { + reldir = $0 + sub("^"ENVIRON["PWD"]"/?", "", reldir) + gsub("'"$escape_chars"'", "\\\\&", reldir) + print "./" reldir " " + print reldir " " + } + gsub("'"$escape_chars"'", "\\\\&") + print $0 " " + }' +} + _umount_module() { local cur prev OPTS @@ -48,28 +78,11 @@ _umount_module() return 0 ;; esac - - local oldifs=$IFS - IFS=$'\n' - COMPREPLY=( $( compgen -W "$(findmnt -lno TARGET | awk \ - '{ - if ($0 ~ ENVIRON["HOME"]) { - homeless = $0 - homeless = gensub(ENVIRON["HOME"], "\\\\~", "g", homeless) - homeless = gensub(/(\s)/, "\\\\\\1", "g", homeless) - print homeless - } - if ($0 ~ ENVIRON["PWD"]) { - reldir = $0 - reldir = gensub(ENVIRON["PWD"]"/", "", "g", reldir) - reldir = gensub(/(\s)/, "\\\\\\1", "g", reldir) - print "./" reldir - print reldir - } - gsub(/\s/, "\\\\&") - print $0 - }' - )" -- "$cur" ) ) - IFS=$oldifs + local IFS=$'\n' + COMPREPLY=( $( compgen -W '$( _umount_points_list )' -- "$cur" ) ) } -complete -F _umount_module umount + +# counteract the artificial addition of " " in _gen_mount_points() by +# disabling spaces automatically appended to the end of the file name +# completion via "-o nospace". +complete -F _umount_module -o nospace umount From 38aa4e64b845e58b04d21872ed6e1ec0f269a7e0 Mon Sep 17 00:00:00 2001 From: Mauricio Faria de Oliveira Date: Tue, 7 Jan 2020 18:53:51 -0300 Subject: [PATCH 5/8] [PATCH] libblkid: (xfs) external log: check for regular xfs on more sectors The xfs external log probe only checks for regular xfs on sector zero, but then checks for valid log record headers on all first 512 sectors. This can incorrectly detect an xfs external log if a regular xfs (i.e. with internal log) is shifted by up to 512 sectors; it may happen with bcache and LVM1 for example, as the regular xfs is found later in disk. This results in ambivalent filesystem detection, thus no UUID for udev. Fix this problem by checking for regular xfs on all sectors considered by the xfs external log probe. Test-case with bcache: Gbp-Pq: Name libblkid-xfs-log-check-for-reg-xfs-on-more-sectors.patch --- libblkid/src/superblocks/xfs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libblkid/src/superblocks/xfs.c b/libblkid/src/superblocks/xfs.c index 99848f9..7e87020 100644 --- a/libblkid/src/superblocks/xfs.c +++ b/libblkid/src/superblocks/xfs.c @@ -252,11 +252,12 @@ static int probe_xfs_log(blkid_probe pr, if (!buf) return errno ? -errno : 1; - if (memcmp(buf, "XFSB", 4) == 0) - return 1; /* this is regular XFS, ignore */ - /* check the first 512 512-byte sectors */ for (i = 0; i < 512; i++) { + /* this is regular XFS (maybe with some sectors shift), ignore */ + if (memcmp(&buf[i*512], "XFSB", 4) == 0) + return 1; + rhead = (struct xlog_rec_header *)&buf[i*512]; if (xlog_valid_rec_header(rhead)) { From f29e698f8a07d352b8daac0459f8683630f797d3 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 27 Jun 2019 09:22:18 +0200 Subject: [PATCH 6/8] lsblk: force to print PKNAME for partition PKNAME (parent kernel device name) is based on printed tree according to parent -> child relationship. The tree is optional and not printed if partition specified (.e.g "lsblk -o+PKNAME /dev/sda1"), but old versions print the PKNAME also in this case. Addresses: https://github.com/karelzak/util-linux/issues/813 Signed-off-by: Karel Zak Gbp-Pq: Name lsblk-force-to-print-PKNAME-for-partition.patch --- misc-utils/lsblk.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index e95af7a..3ce6da7 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -1019,6 +1019,9 @@ static void device_to_scols( DBG(DEV, ul_debugobj(dev, "add '%s' to scols", dev->name)); ON_DBG(DEV, if (ul_path_isopen_dirfd(dev->sysfs)) ul_debugobj(dev, " %s ---> is open!", dev->name)); + if (!parent && dev->wholedisk) + parent = dev->wholedisk; + /* Do not print device more than one in --list mode */ if (!(lsblk->flags & LSBLK_TREE) && dev->is_printed) return; From 9de229d149ba4b7d5beb1a4e4bfa54b03524a3d7 Mon Sep 17 00:00:00 2001 From: Ubuntu Developers Date: Sat, 14 May 2022 03:14:50 +0800 Subject: [PATCH 7/8] hwclock_fix_audit_status hwclock: fix audit exit status According to audit_log_user_message(3) result 1 is "success" and 0 is "failed", we use standard EXIT_{SUCCESS,FAILURE} macros with reverse status. Addresses: https://github.com/karelzak/util-linux/issues/966 Signed-off-by: Karel Zak Gbp-Pq: Name hwclock_fix_audit_status.patch --- sys-utils/hwclock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c index a2c5cc2..95ce643 100644 --- a/sys-utils/hwclock.c +++ b/sys-utils/hwclock.c @@ -1442,7 +1442,7 @@ hwclock_exit(const struct hwclock_control *ctl if (ctl->hwaudit_on && !ctl->testing) { audit_log_user_message(hwaudit_fd, AUDIT_USYS_CONFIG, "op=change-system-time", NULL, NULL, NULL, - status); + status == EXIT_SUCCESS ? 1 : 0); } close(hwaudit_fd); #endif From 3c45559264a2e791d24c35d4720018a2b8db92c3 Mon Sep 17 00:00:00 2001 From: J William Piggott Date: Fri, 21 Feb 2020 20:03:47 -0500 Subject: [PATCH 8/8] [PATCH] hwclock: make glibc 2.31 compatible ______________________________________________________ GNU C Library NEWS -- history of user-visible changes. Version 2.31 Deprecated and removed features, and other changes affecting compatibility: * The settimeofday function can still be used to set a system-wide time zone when the operating system supports it. This is because the Linux kernel reused the API, on some architectures, to describe a system-wide time-zone-like offset between the software clock maintained by the kernel, and the "RTC" clock that keeps time when the system is shut down. However, to reduce the odds of this offset being set by accident, settimeofday can no longer be used to set the time and the offset simultaneously. If both of its two arguments are non-null, the call will fail (setting errno to EINVAL). Callers attempting to set this offset should also be prepared for the call to fail and set errno to ENOSYS; this already happens on the Hurd and on some Linux architectures. The Linux kernel maintainers are discussing a more principled replacement for the reused API. After a replacement becomes available, we will change settimeofday to fail with ENOSYS on all platforms when its 'tzp' argument is not a null pointer. settimeofday itself is obsolescent according to POSIX. Programs that set the system time should use clock_settime and/or the adjtime family of functions instead. We may cease to make settimeofday available to newly linked binaries after there is a replacement for Linux's time-zone-like offset API. ______________________________________________________ hwclock(8) had one settimeofday(2) call where both args were set for --hctosys when the RTC was ticking UTC. This allowed setting the system time, timezone, and locking the warp_clock function with a single call. That operation now takes 3 calls of settimeofday(2). Although this common operation now takes three calls, the overall logic for the set_system_clock() function was simplified. Co-Author: Karel Zak Signed-off-by: J William Piggott Gbp-Pq: Name hwclock-make-glibc-2.31-compatible.patch --- sys-utils/hwclock.c | 71 +++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c index 95ce643..c39d680 100644 --- a/sys-utils/hwclock.c +++ b/sys-utils/hwclock.c @@ -638,28 +638,28 @@ display_time(struct timeval hwctime) * tz.tz_minuteswest argument and sets PCIL (see below). At boot settimeofday(2) * has one-shot access to this function as shown in the table below. * - * +-------------------------------------------------------------------+ - * | settimeofday(tv, tz) | - * |-------------------------------------------------------------------| - * | Arguments | System Time | PCIL | | warp_clock | - * | tv | tz | set | warped | set | firsttime | locked | - * |---------|---------|---------------|------|-----------|------------| - * | pointer | NULL | yes | no | no | 1 | no | - * | pointer | pointer | yes | no | no | 0 | yes | - * | NULL | ptr2utc | no | no | no | 0 | yes | - * | NULL | pointer | no | yes | yes | 0 | yes | - * +-------------------------------------------------------------------+ + * +-------------------------------------------------------------------------+ + * | settimeofday(tv, tz) | + * |-------------------------------------------------------------------------| + * | Arguments | System Time | TZ | PCIL | | warp_clock | + * | tv | tz | set | warped | set | set | firsttime | locked | + * |---------|---------|---------------|-----|------|-----------|------------| + * | pointer | NULL | yes | no | no | no | 1 | no | + * | NULL | ptr2utc | no | no | yes | no | 0 | yes | + * | NULL | pointer | no | yes | yes | yes | 0 | yes | + * +-------------------------------------------------------------------------+ * ptr2utc: tz.tz_minuteswest is zero (UTC). * PCIL: persistent_clock_is_local, sets the "11 minute mode" timescale. * firsttime: locks the warp_clock function (initialized to 1 at boot). + * Since glibc v2.31 settimeofday() will fail if both args are non NULL * * +---------------------------------------------------------------------------+ * | op | RTC scale | settimeofday calls | * |---------|-----------|-----------------------------------------------------| * | systz | Local | 1) warps system time*, sets PCIL* and kernel tz | * | systz | UTC | 1st) locks warp_clock* 2nd) sets kernel tz | - * | hctosys | Local | 1st) sets PCIL* 2nd) sets system time and kernel tz | - * | hctosys | UTC | 1) sets system time and kernel tz | + * | hctosys | Local | 1st) sets PCIL* & kernel tz 2nd) sets system time | + * | hctosys | UTC | 1st) locks warp* 2nd) sets tz 3rd) sets system time | * +---------------------------------------------------------------------------+ * * only on first call after boot */ @@ -670,42 +670,45 @@ set_system_clock(const struct hwclock_control *ctl, struct tm broken; int minuteswest; int rc = 0; - const struct timezone tz_utc = { 0 }; localtime_r(&newtime.tv_sec, &broken); minuteswest = -get_gmtoff(&broken) / 60; if (ctl->verbose) { - if (ctl->hctosys && !ctl->universal) - printf(_("Calling settimeofday(NULL, %d) to set " - "persistent_clock_is_local.\n"), minuteswest); - if (ctl->systz && ctl->universal) + if (ctl->universal) { puts(_("Calling settimeofday(NULL, 0) " - "to lock the warp function.")); + "to lock the warp_clock function.")); + if (!( ctl->universal && !minuteswest )) + printf(_("Calling settimeofday(NULL, %d) " + "to set the kernel timezone.\n"), + minuteswest); + } else + printf(_("Calling settimeofday(NULL, %d) to warp " + "System time, set PCIL and the kernel tz.\n"), + minuteswest); + if (ctl->hctosys) - printf(_("Calling settimeofday(%ld.%06ld, %d)\n"), - newtime.tv_sec, newtime.tv_usec, minuteswest); - else { - printf(_("Calling settimeofday(NULL, %d) "), minuteswest); - if (ctl->universal) - puts(_("to set the kernel timezone.")); - else - puts(_("to warp System time.")); - } + printf(_("Calling settimeofday(%ld.%06ld, NULL) " + "to set the System time.\n"), + newtime.tv_sec, newtime.tv_usec); } if (!ctl->testing) { + const struct timezone tz_utc = { 0 }; const struct timezone tz = { minuteswest }; - if (ctl->hctosys && !ctl->universal) /* set PCIL */ - rc = settimeofday(NULL, &tz); - if (ctl->systz && ctl->universal) /* lock warp_clock */ + /* If UTC RTC: lock warp_clock and PCIL */ + if (ctl->universal) rc = settimeofday(NULL, &tz_utc); - if (!rc && ctl->hctosys) - rc = settimeofday(&newtime, &tz); - else if (!rc) + + /* Set kernel tz; if localtime RTC: warp_clock and set PCIL */ + if (!rc && !( ctl->universal && !minuteswest )) rc = settimeofday(NULL, &tz); + /* Set the System Clock */ + if ((!rc || errno == ENOSYS) && ctl->hctosys) + rc = settimeofday(&newtime, NULL); + if (rc) { warn(_("settimeofday() failed")); return EXIT_FAILURE;