Skip to content

Commit bfed41c

Browse files
ynezzhauke
authored andcommitted
busybox: fix login applet on selinux
Currently the system boots up, but is unusable because pressing enter does not provide login with error: login: can't get SID for root This is happenning, because login.c passes the Linux username directly to get_default_context(), while libselinux expects an SELinux user identity, causing the call to fail for users without a matching SELinux name (e.g., root) and aborting login on SELinux-enabled systems. Fixes: #19075 Upstream-Status: Submitted [https://lists.busybox.net/pipermail/busybox/2025-April/091407.html] Signed-off-by: Petr Štetiar <[email protected]> Link: openwrt/openwrt#19080 (cherry picked from commit 5809bfa) Link: openwrt/openwrt#19542 Signed-off-by: Hauke Mehrtens <[email protected]>
1 parent 254f6b2 commit bfed41c

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
From 850a6d031039237b0b13d8fab9f10a7cd4752907 Mon Sep 17 00:00:00 2001
2+
From: Dominick Grift <[email protected]>
3+
Date: Sat, 5 Apr 2025 13:40:26 +0200
4+
Subject: [PATCH] loginutils/login.c: libselinux get_default_context() expects
5+
seuser
6+
7+
Use getseuserbyname() to get the seuser associated with username and use that
8+
instead with get_default_context()
9+
10+
>From get_default_context.3:
11+
"These functions takes a SELinux user identity that must be defined in the SELinux policy as their input, not a Linux username."
12+
13+
Fixes: #19075
14+
Upstream-Status: Submitted [https://lists.busybox.net/pipermail/busybox/2025-April/091407.html]
15+
Signed-off-by: Dominick Grift <[email protected]>
16+
---
17+
loginutils/login.c | 11 ++++++++++-
18+
1 file changed, 10 insertions(+), 1 deletion(-)
19+
20+
--- a/loginutils/login.c
21+
+++ b/loginutils/login.c
22+
@@ -183,12 +183,16 @@ static void die_if_nologin(void)
23+
static void initselinux(char *username, char *full_tty,
24+
security_context_t *user_sid)
25+
{
26+
+ char *seuser = NULL, *level = NULL;
27+
security_context_t old_tty_sid, new_tty_sid;
28+
29+
if (!is_selinux_enabled())
30+
return;
31+
32+
- if (get_default_context(username, NULL, user_sid)) {
33+
+ if (getseuserbyname(username, &seuser, &level)) {
34+
+ bb_error_msg_and_die("can't get seuser for %s", username);
35+
+ }
36+
+ if (get_default_context(seuser, NULL, user_sid)) {
37+
bb_error_msg_and_die("can't get SID for %s", username);
38+
}
39+
if (getfilecon(full_tty, &old_tty_sid) < 0) {
40+
@@ -201,6 +205,11 @@ static void initselinux(char *username,
41+
if (setfilecon(full_tty, new_tty_sid) != 0) {
42+
bb_perror_msg_and_die("chsid(%s, %s) failed", full_tty, new_tty_sid);
43+
}
44+
+
45+
+ if (ENABLE_FEATURE_CLEAN_UP) {
46+
+ free(seuser);
47+
+ free(level);
48+
+ }
49+
}
50+
#endif
51+

0 commit comments

Comments
 (0)