diff --git a/depmod-Prevent-module-dependency-files-corruption.patch b/depmod-Prevent-module-dependency-files-corruption.patch new file mode 100644 index 0000000..33484dd --- /dev/null +++ b/depmod-Prevent-module-dependency-files-corruption.patch @@ -0,0 +1,80 @@ +From c1858f5d0a88a39f37a9b3efdd83245740fcb87d Mon Sep 17 00:00:00 2001 +From: Michal Suchanek +Date: Fri, 7 Dec 2018 15:45:41 +0100 +Subject: [PATCH] depmod: Prevent module dependency files corruption due to + parallel invocation. + +Depmod does not use unique filename for temporary files. There is no +guarantee the user does not attempt to run mutiple depmod processes in +parallel. If that happens a temporary file might be created by +depmod(1st), truncated by depmod(2nd), and renamed to final name by +depmod(1st) resulting in corrupted file seen by user. + +Due to missing mkstempat() this is more complex than it should be. +Adding PID and random number to the filename should be reasonably +reliable. Adding O_EXCL as mkstemp does fails creating the file rather +than corrupting existing file. + +Also prevent dependency files missing. This happens because target files +are removed before renaming the temporary file. + +Signed-off-by: Michal Suchanek +--- + tools/depmod.c | 14 ++++++++++---- + 1 file changed, 10 insertions(+), 4 deletions(-) + +diff --git a/tools/depmod.c b/tools/depmod.c +index 989d9077926c..5526ac892cf8 100644 +--- a/tools/depmod.c ++++ b/tools/depmod.c +@@ -29,6 +29,7 @@ + #include + #include + #include ++#include + #include + + #include +@@ -2398,6 +2399,10 @@ static int depmod_output(struct depmod *depmod, FILE *out) + }; + const char *dname = depmod->cfg->dirname; + int dfd, err = 0; ++ struct timeval tv; ++ ++ gettimeofday(&tv, NULL); ++ srand(tv.tv_sec); + + if (out != NULL) + dfd = -1; +@@ -2412,15 +2417,17 @@ static int depmod_output(struct depmod *depmod, FILE *out) + + for (itr = depfiles; itr->name != NULL; itr++) { + FILE *fp = out; +- char tmp[NAME_MAX] = ""; ++ char tmp[NAME_MAX + 1] = ""; + int r, ferr; + + if (fp == NULL) { +- int flags = O_CREAT | O_TRUNC | O_WRONLY; ++ int flags = O_CREAT | O_TRUNC | O_WRONLY | O_EXCL; + int mode = 0644; + int fd; + +- snprintf(tmp, sizeof(tmp), "%s.tmp", itr->name); ++ snprintf(tmp, sizeof(tmp), "%s.%i.%i", itr->name, getpid(), ++ rand()); ++ tmp[NAME_MAX] = 0; + fd = openat(dfd, tmp, flags, mode); + if (fd < 0) { + ERR("openat(%s, %s, %o, %o): %m\n", +@@ -2451,7 +2458,6 @@ static int depmod_output(struct depmod *depmod, FILE *out) + break; + } + +- unlinkat(dfd, itr->name, 0); + if (renameat(dfd, tmp, dfd, itr->name) != 0) { + err = -errno; + CRIT("renameat(%s, %s, %s, %s): %m\n", +-- +2.19.2 + diff --git a/kmod-testsuite.changes b/kmod-testsuite.changes index 6a9f1b4..34c1f5b 100644 --- a/kmod-testsuite.changes +++ b/kmod-testsuite.changes @@ -1,3 +1,21 @@ +------------------------------------------------------------------- +Fri Dec 7 14:55:21 UTC 2018 - Michal Suchanek + +- Fix module dependency file corruption on parallel invocation (bsc#1118629). + + depmod-Prevent-module-dependency-files-corruption-due-to-pa.patch + +------------------------------------------------------------------- +Wed Jul 18 08:51:06 UTC 2018 - jengelh@inai.de + +- Remove enum padding constants + + enum.patch. + +------------------------------------------------------------------- +Fri Jun 8 21:37:14 UTC 2018 - vlad.botanic@gmail.com + +- allow 'modprobe -c' print the status of "allow_unsupported_modules" option. + + 0012-modprobe-print-unsupported-status.patch + ------------------------------------------------------------------- Fri Apr 6 10:43:42 UTC 2018 - msuchanek@suse.com diff --git a/kmod-testsuite.spec b/kmod-testsuite.spec index 3dec895..711bd84 100644 --- a/kmod-testsuite.spec +++ b/kmod-testsuite.spec @@ -12,7 +12,7 @@ # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. -# Please submit bugfixes or comments via http://bugs.opensuse.org/ +# Please submit bugfixes or comments via https://bugs.opensuse.org/ # @@ -38,6 +38,9 @@ Patch4: 0010-modprobe-Implement-allow-unsupported-modules.patch Patch5: 0011-Do-not-filter-unsupported-modules-when-running-a-van.patch Patch6: libkmod-signature-Fix-crash-when-module-signature-is.patch Patch7: libkmod-signature-pkcs-7-fix-crash-when-signer-info-.patch +Patch8: 0012-modprobe-print-unsupported-status.patch +Patch9: enum.patch +Patch10: depmod-Prevent-module-dependency-files-corruption.patch BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRequires: asn1c BuildRequires: autoconf @@ -62,7 +65,7 @@ buildloop with the kernel. %prep %setup -q -n kmod-%version -%patch -P 0 -P 1 -P 2 -P 3 -P 4 -P 5 -P 6 -P 7 -p1 +%patch -P 0 -P 1 -P 2 -P 3 -P 4 -P 5 -P 6 -P 7 -P 8 -P 9 -P 10 -p1 %build autoreconf -fi diff --git a/kmod.changes b/kmod.changes index fa6e1cf..3d0cd1a 100644 --- a/kmod.changes +++ b/kmod.changes @@ -1,7 +1,14 @@ +------------------------------------------------------------------- +Fri Dec 7 14:55:21 UTC 2018 - Michal Suchanek + +- Fix module dependency file corruption on parallel invocation (bsc#1118629). + + depmod-Prevent-module-dependency-files-corruption-due-to-pa.patch + ------------------------------------------------------------------- Wed Jul 18 08:51:06 UTC 2018 - jengelh@inai.de -- Add enum.patch. +- Remove enum padding constants + + enum.patch. ------------------------------------------------------------------- Fri Jun 8 21:37:14 UTC 2018 - vlad.botanic@gmail.com diff --git a/kmod.spec b/kmod.spec index a6e376e..ecfd1bb 100644 --- a/kmod.spec +++ b/kmod.spec @@ -12,7 +12,7 @@ # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. -# Please submit bugfixes or comments via http://bugs.opensuse.org/ +# Please submit bugfixes or comments via https://bugs.opensuse.org/ # @@ -39,6 +39,7 @@ Patch6: libkmod-signature-Fix-crash-when-module-signature-is.patch Patch7: libkmod-signature-pkcs-7-fix-crash-when-signer-info-.patch Patch8: 0012-modprobe-print-unsupported-status.patch Patch9: enum.patch +Patch10: depmod-Prevent-module-dependency-files-corruption.patch BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRequires: asn1c BuildRequires: autoconf @@ -111,7 +112,7 @@ in %lname. %prep %setup -q -n kmod-%version -%patch -P 0 -P 1 -P 2 -P 3 -P 4 -P 5 -P 6 -P 7 -P 8 -P 9 -p1 +%patch -P 0 -P 1 -P 2 -P 3 -P 4 -P 5 -P 6 -P 7 -P 8 -P 9 -P 10 -p1 %build autoreconf -fi