Re: [PATCH 1/2] security: safesetid: use real GID for GID policy lookup

From: Guicai Ma

Date: Wed Nov 25 2026 - 03:52:07 EST


On Sat, 3 Oct 2026 19:34:15 +0900, Sung Byeongchan wrote:
> SafeSetID policies constrain the ID transitions available to a task for
> each source ID. id_permitted_for_cred() always builds that source key
> from the old real UID, even when it is checking a GID transition. If the
> real UID and real GID differ, the policy attached to the real GID is
> therefore missed and the lookup can return the unconstrained default.

Reproduced the bypass and verified the fix on arm64 under KVM with KASAN
(v7.4-rc3-178-g20eef29b7c84, CONFIG_LSM="safesetid,yama").

On the unpatched kernel, a task with real UID 1000, real GID 2000 and
only CAP_SETGID reached GID 2002 under a 2000:2001 GID policy via
setresgid(), setgroups() and setfsgid(), while a matching 1000:1001 UID
policy still blocked setresuid(1002). With this patch applied, all three
GID transitions are killed with SIGKILL, and the allowed 2000:2001
transition, existing-GID transitions, the existing safesetid selftest
and the new test in 2/2 all pass with no KASAN warnings.

Tested-by: Guicai Ma <maguicai@xxxxxxxxxx>

Thanks,
Guicai