Commit Graph

8 Commits

Author SHA1 Message Date
Sasi Kumar Maddineni
9a913243ff selinux-image: Preserve SELinux contexts in tarballs
Tarball images were created without SELinux context information,
causing loss of security labels during extraction while working with
features like:ostree. This breaks SELinux policy enforcement and requires
relabeling after deployment, adding runtime overhead.

Append "--selinux" to IMAGE_CMD_TAR to include SELinux file contexts
when generating tarball images. This ensures security labels are
preserved across image creation and deployment.

Signed-off-by: Sasi Kumar Maddineni <quic_sasikuma@quicinc.com>
Signed-off-by: Yi Zhao <yi.zhao@windriver.com>
2025-11-28 11:47:08 +08:00
Yi Zhao
46ec0414b4 selinux-image.bbclass: refactor bbclass
The selinux_set_labels function should run as late as possible. To
guarantee that, we append it to IMAGE_PREPROCESS_COMMAND in
RecipePreFinalise event handler, this ensures it is the last function in
IMAGE_PREPROCESS_COMMAND.

After refactoring, system using systemd can also label selinux contexts
during build.

Signed-off-by: Yi Zhao <yi.zhao@windriver.com>
Signed-off-by: Joe MacDonald <joe@deserted.net>
2023-10-12 10:14:19 -04:00
Yi Zhao
654201e25d meta-selinux: convert to new override syntax
This is the result of automated script conversion:
poky/scripts/contrib/convert-overrides.py meta-selinux

Converting the metadata to use ":" as the override character instead of "_".

Signed-off-by: Yi Zhao <yi.zhao@windriver.com>
Signed-off-by: Joe MacDonald <joe@deserted.net>
2021-08-04 16:18:39 -04:00
Yi Zhao
3f850b745c selinux-image.bbclass: using append instead of += for IMAGE_PREPROCESS_COMMAND
Fix AVC denied error when booting:

type=AVC msg=audit(1548055920.478:86): avc:  denied  { execute } for
pid=366 comm="audispd" path="/lib/ld-2.28.so" dev="vda" ino=7545
scontext=system_u:system_r:audisp_t:s15:c0.c1023
tcontext=system_u:object_r:unlabeled_t:s0 tclass=file permissive=1

type=AVC msg=audit(1548055920.478:87): avc:  denied  { open } for
pid=366 comm="audispd" path="/lib/libc-2.28.so" dev="vda" ino=7558
scontext=system_u:system_r:audisp_t:s15:c0.c1023
tcontext=system_u:object_r:unlabeled_t:s0 tclass=file permissive=1

When using "+=" for IMAGE_PREPROCESS_COMMAND, the selinux_set_labels
process would run before prelink process to set the security labels for
the files. But the label for /lib/libc-2.28.so and /lib/ld-2.28.so would
be changed after run prelink process. Use "_append" to make sure the
selinux_set_labels process run after prelink process.

Signed-off-by: Yi Zhao <yi.zhao@windriver.com>
Signed-off-by: Joe MacDonald <joe@deserted.net>
2019-04-14 17:08:54 -04:00
George McCollister
8ecad12b2c selinux-image: fix labeling on non-seclabel mounts
Use -m to prevent non-seclabel mounts from being excluded from labeling.
After the following commit setfiles will no longer label files on a
mount other than / if it doesn't have seclabel listed in /proc/mounts:
f2e77865e1 (diff-2de9aefdd8fc5bc6a8740533e5d1cc2e)

Signed-off-by: George McCollister <george.mccollister@gmail.com>
Signed-off-by: Joe MacDonald <joe_macdonald@mentor.com>
2018-08-13 11:20:32 -04:00
Joe MacDonald
849cd74b5f selinux-image: enable image labelling
selinux images attempt to label the filesystem image at creation time.
This depends on a native setfiles, though, which isn't guaranteed to be
present without the DEPEND addition.

If the 'setfiles' call fails, that shouldn't be fatal, though, it can
always be run at first boot time, as is commonly done with desktop and
server distros.

Signed-off-by: Joe MacDonald <joe_macdonald@mentor.com>
2017-05-02 21:21:44 -04:00
George McCollister
d3efe54085 selinux-image: Fix RE error getting POL_TYPE
Change [:space:] to [[:space:]]. [:space:] is incorrect and is treated
as a list of characters. Prior to this change having a policy of
'standard' resulted in POL_TYPE being set to 'tandard'.

Change the regular expression to match from the beginning of the line
since correcting the [:space:] error causes the '# SELINUXTYPE= can
take one of these values:' line to match.

Signed-off-by: George McCollister <george.mccollister@gmail.com>
Signed-off-by: Joe MacDonald <joe_macdonald@mentor.com>
2015-11-27 09:18:14 -05:00
Philip Tricca
56e952f43a selinux-image: Add new image class to label the rootfs, use it for selinux images.
Signed-off-by: Philip Tricca <flihp@twobit.us>
Signed-off-by: Joe MacDonald <joe_macdonald@mentor.com>
2015-08-08 16:43:23 -04:00