lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 1 | SELinux FAQ |
| 2 | |
| 3 | ---------------------------------------------------------------------------- |
| 4 | |
| 5 | This file contains answers to frequently-asked questions about the SELinux |
| 6 | feature for Poky. |
| 7 | |
| 8 | Copyright (C) 2012 Wind River Systems, Inc. |
| 9 | |
| 10 | ============================================================================ |
| 11 | |
| 12 | Table of Contents |
| 13 | |
| 14 | 1. About SELinux |
| 15 | * 1.1 What is SELinux? |
| 16 | * 1.2 How does this layer do to enable SELinux features? |
| 17 | |
| 18 | 2. Building with SELinux |
| 19 | |
| 20 | * 2.1 How can I build a SELinux image? |
| 21 | * 2.2 How can I add SELinux to my custom images? |
| 22 | |
| 23 | 3. Using SELinux |
| 24 | |
| 25 | * 3.1 How do I turn SELinux off at boot? |
| 26 | * 3.2 How do I turn enforcing mode on/off at boot? |
| 27 | |
| 28 | 4. Resolving Problems |
| 29 | |
| 30 | * 4.1 Why I can not login in via ssh in enforcing mode? |
| 31 | |
| 32 | ============================================================================== |
| 33 | |
| 34 | 1 - About SELinux |
| 35 | |
| 36 | ------------------------------------------------------------------------------ |
| 37 | |
| 38 | 1.1 - What is SELinux? |
| 39 | |
| 40 | Security-enhanced Linux (SELinux) is a reference implementation of the Flask |
| 41 | security architecture for flexible mandatory access control. It was created to |
| 42 | demonstrate the value of flexible mandatory access controls and how such |
| 43 | controls could be added to an operating system. |
| 44 | |
| 45 | 1.2 - How does this layer do to enable SELinux features? |
| 46 | |
| 47 | To enable SELinux features, this layers has done these works: |
| 48 | |
| 49 | * new DISTRO_FEATURES "selinux" defined |
| 50 | * new DISTRO "poky-selinux" defined, with DISTRO_FEATURES += "pam selinux" |
| 51 | * config file for Linux kernel to enable SELinux |
| 52 | * recipes for SELinux userland libraries and tools |
| 53 | * package group (packagegroup-core-selinux) for SELinux userland packages |
| 54 | * bbappends for SELinux related recipes to build with SELinux enabled |
| 55 | * recipes for SELinux policy modified from refpolicy |
| 56 | |
| 57 | |
| 58 | ============================================================================== |
| 59 | |
| 60 | 2 - Building with SELinux |
| 61 | |
| 62 | ------------------------------------------------------------------------------ |
| 63 | |
| 64 | 2.1 - How can I build a SELinux image? |
| 65 | |
| 66 | After init Poky build environment, please follow these steps: |
| 67 | |
| 68 | 1. Add meta-selinux path to BUILDDIR/conf/bblayers.conf file. |
| 69 | |
| 70 | 2. Set DISTRO="poky-selinux" or add DISTRO_FEATURES_append=" pam selinux" |
| 71 | in BUILDDIR/conf/local.conf file. |
| 72 | |
| 73 | 3. Build the default selinux image. |
| 74 | |
| 75 | $ bitbake core-image-selinux |
| 76 | |
| 77 | 2.2 - How can I add SELinux to my custom images? |
| 78 | |
| 79 | If you only want to add SELinux to your custom image, then you should perform |
| 80 | the following steps: |
| 81 | |
| 82 | 1. Add meta-selinux path to BUILDDIR/conf/bblayers.conf file |
| 83 | |
| 84 | 2. Add DISTRO_FEATURES_append=" pam selinux" in BUILDDIR/conf/local.conf |
| 85 | file. |
| 86 | |
| 87 | 3. Add packagegroup-core-selinux to your custom image. |
| 88 | For example, if core-image-custom.bb is your building image file, then |
| 89 | you should add packagegroup-core-selinux to IMAGE_INSTALL in |
| 90 | core-image-custom.bb. |
| 91 | |
| 92 | 4. Build your custom image in build directory |
| 93 | |
| 94 | $ bitbake core-image-custom |
| 95 | |
| 96 | |
| 97 | |
| 98 | ============================================================================== |
| 99 | |
| 100 | 3 - Using SELinux |
| 101 | |
| 102 | ------------------------------------------------------------------------------ |
| 103 | |
| 104 | 3.1 - How do I turn SELinux off at boot? |
| 105 | |
| 106 | Set SELINUX=disabled in /etc/selinux/config. |
| 107 | |
| 108 | Alternatively, you can add "selinux=0" to your kernel boot parameters. It is |
| 109 | not recommended but useful on some testing situations. |
| 110 | For example, when you are using qemu targets, |
| 111 | |
| 112 | $ runqemu qemumips core-image-selinux ext3 nographic bootparams="selinux=0" |
| 113 | |
| 114 | The initial filesystem relabel step requires considerable memory and can result |
| 115 | in unexpected, sometimes impossible to reproduce, failures if an OOM condition |
| 116 | occurs while it is in progress. Therefore you should consider allocating at a |
| 117 | minimum 512MB of RAM to your qemu image. 1GB or more is recommended. This is |
| 118 | accomplished by adding qemuparams="-m 1024" to your runqemu options. |
| 119 | |
| 120 | The defaults for various platforms vary, though it is usually around 256MB. |
| 121 | |
| 122 | 3.2 - How do I turn enforcing mode on/off? |
| 123 | |
| 124 | You can specify the SELinux mode in /etc/selinux/config. |
| 125 | |
| 126 | # SELINUX= can take one of these three values: |
| 127 | # enforcing - SELinux security policy is enforced. |
| 128 | # permissive - SELinux prints warnings instead of enforcing. |
| 129 | # disabled - No SELinux policy is loaded. |
| 130 | SELINUX=enforcing |
| 131 | |
| 132 | Setting "SELINUX" to "enforcing" is the same as adding "enforcing=1" to the |
| 133 | kernel boot parameters. While to "permissive" is the same as adding |
| 134 | "enforcing=0" to the kernel boot parameters. |
| 135 | However, to "disabled" is not the same as the "selinux=0" kernel boot |
| 136 | parameter. Rather than fully disabling SELinux in the kernel, the "disabled" |
| 137 | setting instead turns enforcing off and skips loading a policy. |
| 138 | |
| 139 | ============================================================================== |
| 140 | |
| 141 | 4 - Resolving Problems |
| 142 | |
| 143 | ------------------------------------------------------------------------------ |
| 144 | |
| 145 | 4.1 - Why I can not login in via ssh in enforcing mode? |
| 146 | |
| 147 | Please check "PermitEmptyPasswords" in /etc/ssh/sshd_config. If it is set to |
| 148 | "yes", set to "no" then restart sshd. That's because pam_selinux module does |
| 149 | not allow sshd to set PermitEmptyPasswords to "yes". |
| 150 | |
| 151 | Note: If both IMAGE_FEATURES debug-tweaks ssh-server-openssh are enabled, this |
| 152 | "PermitEmptyPasswords" will be set to "yes" by default for Poky images. |
| 153 | |
| 154 | |