Skip to content

Commit fde46f6

Browse files
stephensmalleypcmoore
authored andcommitted
selinux: change security_compute_sid to return the ssid or tsid on match
If the end result of a security_compute_sid() computation matches the ssid or tsid, return that SID rather than looking it up again. This avoids the problem of multiple initial SIDs that map to the same context. Cc: [email protected] Reported-by: Guido Trentalancia <[email protected]> Fixes: ae25485 ("selinux: introduce an initial SID for early boot processes") Signed-off-by: Stephen Smalley <[email protected]> Tested-by: Guido Trentalancia <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 86c8db8 commit fde46f6

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

security/selinux/ss/services.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,11 +1909,17 @@ static int security_compute_sid(u32 ssid,
19091909
goto out_unlock;
19101910
}
19111911
/* Obtain the sid for the context. */
1912-
rc = sidtab_context_to_sid(sidtab, &newcontext, out_sid);
1913-
if (rc == -ESTALE) {
1914-
rcu_read_unlock();
1915-
context_destroy(&newcontext);
1916-
goto retry;
1912+
if (context_equal(scontext, &newcontext))
1913+
*out_sid = ssid;
1914+
else if (context_equal(tcontext, &newcontext))
1915+
*out_sid = tsid;
1916+
else {
1917+
rc = sidtab_context_to_sid(sidtab, &newcontext, out_sid);
1918+
if (rc == -ESTALE) {
1919+
rcu_read_unlock();
1920+
context_destroy(&newcontext);
1921+
goto retry;
1922+
}
19171923
}
19181924
out_unlock:
19191925
rcu_read_unlock();

0 commit comments

Comments
 (0)