]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mkswap: set selinux label also when creating file
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 17 Nov 2024 18:04:49 +0000 (19:04 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 10 Dec 2024 09:45:10 +0000 (10:45 +0100)
With --file, shen the file is created by mkswap, stat() fails with -ENOENT
and the st_mode field is not populated, so the IS_REG() check fails. But if
we created by mkswap, we know it's just a regular file and we should apply
the selinux label.

Reported in https://bugzilla.redhat.com/show_bug.cgi?id=2324811#c56.

(cherry picked from commit 1dd27d1fa733f97b3a94822ccfd406e1a572867d)

disk-utils/mkswap.c

index 9c80b070c754c7d416f34d53e1892d90b6afe860..ca1f07b86d54f0f42b60073794c6407fdf638d08 100644 (file)
@@ -754,7 +754,8 @@ int main(int argc, char **argv)
        deinit_signature_page(&ctl);
 
 #ifdef HAVE_LIBSELINUX
-       if (S_ISREG(ctl.devstat.st_mode) && is_selinux_enabled() > 0) {
+       if ((ctl.file || S_ISREG(ctl.devstat.st_mode)) &&
+            is_selinux_enabled() > 0) {
                const char *context_string;
                char *oldcontext;
                context_t newcontext;