From f135e72e023693e9ec90ca00fb876dbfef042bae Mon Sep 17 00:00:00 2001 From: Davide Cavalca Date: Oct 20 2021 22:46:16 +0000 Subject: Backport three losetup upstream fixes --- diff --git a/SOURCES/1001-losetup-avoid-infinite-busy-loop.patch b/SOURCES/1001-losetup-avoid-infinite-busy-loop.patch new file mode 100644 index 0000000..26fdc77 --- /dev/null +++ b/SOURCES/1001-losetup-avoid-infinite-busy-loop.patch @@ -0,0 +1,55 @@ +diff -Naur a/sys-utils/losetup.8 b/sys-utils/losetup.8 +--- a/sys-utils/losetup.8 2021-10-20 15:23:28.983136437 -0700 ++++ b/sys-utils/losetup.8 2021-10-20 15:23:54.314264432 -0700 +@@ -68,6 +68,13 @@ + file. + .B This setup may be dangerous, can cause data loss, corruption and overwrites. + Use \fB\-\-nooverlap\fR with \fB\-\-find\fR during setup to avoid this problem. ++.sp ++The loop device setup is not an atomic operation when used with \fB\-\-find\fP, and ++.B losetup ++does not protect this operation by any lock. The number of attempts is ++internally restricted to a maximum of 16. It is recommended to use for example ++.BR flock (1) ++to avoid a collision in heavily parallel use cases. + + .SH OPTIONS + The \fIsize\fR and \fIoffset\fR +@@ -170,6 +177,11 @@ + displays the status of a loop device, it returns 1 if the device + is not configured and 2 if an error occurred which prevented + determining the status of the device. ++.SH NOTES ++Since version 2.37 ++.B losetup ++uses LOOP_CONFIGURE ioctl to setup a new loop device by one ioctl call. The ++old versions use LOOP_SET_FD and LOOP_SET_STATUS64 ioctls to do the same. + + .SH FILES + .TP +diff -Naur a/sys-utils/losetup.c b/sys-utils/losetup.c +--- a/sys-utils/losetup.c 2021-10-20 15:23:28.902136028 -0700 ++++ b/sys-utils/losetup.c 2021-10-20 15:23:54.315264437 -0700 +@@ -463,7 +463,7 @@ + const char *file, uint64_t offset, uint64_t sizelimit) + { + int hasdev = loopcxt_has_device(lc); +- int rc = 0; ++ int rc = 0, ntries = 0; + + /* losetup --find --noverlap file.img */ + if (!hasdev && nooverlap) { +@@ -556,8 +556,12 @@ + rc = loopcxt_setup_device(lc); + if (rc == 0) + break; /* success */ +- if (errno == EBUSY && !hasdev) ++ ++ if (errno == EBUSY && !hasdev && ntries < 16) { ++ xusleep(200000); ++ ntries++; + continue; ++ } + + /* errors */ + errpre = hasdev && loopcxt_get_fd(lc) < 0 ? diff --git a/SOURCES/1002-losetup-increase-limit-of-setup-attempts.patch b/SOURCES/1002-losetup-increase-limit-of-setup-attempts.patch new file mode 100644 index 0000000..9f3b02a --- /dev/null +++ b/SOURCES/1002-losetup-increase-limit-of-setup-attempts.patch @@ -0,0 +1,12 @@ +diff -Naur a/sys-utils/losetup.c b/sys-utils/losetup.c +--- a/sys-utils/losetup.c 2021-10-20 15:24:27.694433107 -0700 ++++ b/sys-utils/losetup.c 2021-10-20 15:28:27.101642814 -0700 +@@ -557,7 +557,7 @@ + if (rc == 0) + break; /* success */ + +- if (errno == EBUSY && !hasdev && ntries < 16) { ++ if (errno == EBUSY && !hasdev && ntries < 64) { + xusleep(200000); + ntries++; + continue; diff --git a/SOURCES/1003-lib-loopdev-perform-retry-on-EAGAIN.patch b/SOURCES/1003-lib-loopdev-perform-retry-on-EAGAIN.patch new file mode 100644 index 0000000..810d1de --- /dev/null +++ b/SOURCES/1003-lib-loopdev-perform-retry-on-EAGAIN.patch @@ -0,0 +1,12 @@ +diff -Naur a/sys-utils/losetup.c b/sys-utils/losetup.c +--- a/sys-utils/losetup.c 2021-10-20 15:28:49.072753825 -0700 ++++ b/sys-utils/losetup.c 2021-10-20 15:29:07.938849143 -0700 +@@ -557,7 +557,7 @@ + if (rc == 0) + break; /* success */ + +- if (errno == EBUSY && !hasdev && ntries < 64) { ++ if ((errno == EBUSY || errno == EAGAIN) && !hasdev && ntries < 64) { + xusleep(200000); + ntries++; + continue; diff --git a/SPECS/util-linux.spec b/SPECS/util-linux.spec index 9de160e..239e628 100644 --- a/SPECS/util-linux.spec +++ b/SPECS/util-linux.spec @@ -2,7 +2,7 @@ Summary: A collection of basic system utilities Name: util-linux Version: 2.32.1 -Release: 27.3%{?dist} +Release: 27.4%{?dist} License: GPLv2 and GPLv2+ and LGPLv2+ and BSD with advertising and Public Domain Group: System Environment/Base URL: http://en.wikipedia.org/wiki/Util-linux @@ -208,6 +208,9 @@ Patch56: 0056-tests-update-sfdisk-resize.patch ### Hyperscale (1000-9999) ### Patch1000: 1000-setpriv-add-reset-env.patch +Patch1001: 1001-losetup-avoid-infinite-busy-loop.patch +Patch1002: 1002-losetup-increase-limit-of-setup-attempts.patch +Patch1003: 1003-lib-loopdev-perform-retry-on-EAGAIN.patch %description @@ -1080,6 +1083,12 @@ fi %{_libdir}/python*/site-packages/libmount/ %changelog +* Wed Oct 20 2021 Davide Cavalca 2.32.1-27.4 +- Backport three losetup upstream fixes: + https://github.com/karelzak/util-linux/commit/3ff6fb802de1efafbd90af228f91461691ac190c + https://github.com/karelzak/util-linux/commit/75cd5e2f281cec16c7da49b65c0f3cadd51749b8 + https://github.com/karelzak/util-linux/commit/3e03cb680668e4d47286bc7e6ab43e47bb84c989 + * Thu Jul 08 2021 Davide Cavalca 2.32.1-27.3 - Rebuild against stock libuser and openldap packages