Allow reacquiring capabilities if not explicitly cleared

- Old behavior: Switching to a non-zero UID was implicitly interpreted as a request to drop capabilities, thereby preventing subsequent reacquisition  via `su`.
- New behavior: Switching to a non-zero UID now requires the `--drop-cap` argument to explicitly prevent the reacquisition of capabilities.
This commit is contained in:
vvb2060
2026-02-04 00:01:55 +08:00
committed by John Wu
parent be5246aef5
commit 628b4d4715

View File

@@ -448,7 +448,7 @@ void exec_root_shell(int client, int pid, SuRequest &req, MntNsMode mode) {
auto f = xopen_file("/proc/self/attr/exec", "we");
if (f) fprintf(f.get(), "%s", req.context.c_str());
}
if (req.target_uid != AID_ROOT || req.drop_cap || proc_is_restricted(pid))
if (req.drop_cap || proc_is_restricted(pid))
drop_caps();
if (req.target_uid != AID_ROOT || req.gids.size() > 0)
set_identity(req.target_uid, req.gids);