Commit 28b557c
initramfs: Inherit SELinux label on transient root tmpfs
When root.transient is enabled, the tmpfs used as the overlay upper layer
has no SELinux context set, so its root directory gets the default tmpfs_t
label. This propagates to the overlay mountpoint at /, causing services
like systemd-networkd to refuse to start because they expect root_t.
Fix this by reading the SELinux label from the composefs lower layer via
fgetxattr(security.selinux) and setting it as rootcontext on the tmpfs
before creating the overlay. This ensures the overlay root inherits the
correct label from the base filesystem.
The rootcontext mount option sets only the root inode's label, preserving
per-file labeling from SELinux policy via type_transition rules. This is
preferable to context= which would force a uniform label on all inodes.
When SELinux is not enabled, fgetxattr returns an error and no context is
set, preserving the existing behavior.
Note: the ostree backend (otcore-prepare-root.c in ostreedev/ostree) has
the same issue but uses /run as the tmpfs backing store rather than
creating its own tmpfs. That fix would need to go through libcomposefs
mount options or the ostree repo directly.
Closes: #1992
AI-Assisted: yes
AI-Tools: GitLab Duo, OpenCode
Signed-off-by: Andrew Dunn <andrew@dunn.dev>1 parent 841298f commit 28b557c
2 files changed
Lines changed: 25 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
| |||
202 | 205 | | |
203 | 206 | | |
204 | 207 | | |
205 | | - | |
206 | | - | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
207 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
208 | 223 | | |
209 | 224 | | |
210 | 225 | | |
| |||
239 | 254 | | |
240 | 255 | | |
241 | 256 | | |
242 | | - | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
243 | 261 | | |
244 | 262 | | |
245 | 263 | | |
246 | 264 | | |
247 | 265 | | |
248 | 266 | | |
| 267 | + | |
249 | 268 | | |
250 | 269 | | |
251 | | - | |
| 270 | + | |
252 | 271 | | |
253 | 272 | | |
254 | 273 | | |
| |||
0 commit comments