From 2543548b8c4ce40d64d15ca8d7b473c3e104502a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 17 Nov 2024 19:04:49 +0100 Subject: [PATCH] mkswap: set selinux label also when creating file 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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c index 9c80b070c7..ca1f07b86d 100644 --- a/disk-utils/mkswap.c +++ b/disk-utils/mkswap.c @@ -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; -- 2.47.2