From: Zbigniew Jędrzejewski-Szmek Date: Sun, 17 Nov 2024 18:04:49 +0000 (+0100) Subject: mkswap: set selinux label also when creating file X-Git-Tag: v2.42-start~156^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1dd27d1fa733f97b3a94822ccfd406e1a572867d;p=thirdparty%2Futil-linux.git 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. --- diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c index 9c80b070c..ca1f07b86 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;