libsepol/sepol_compute_sid: Do not destroy uninitialized context
PATCH 1/1 libsepol/sepol_compute_sid: Do not destroy uninitialized context
Avoid context_destroy() on "newcontext" before context_init() is called.
Fixes:
libsepol-3.6/src/services.c:1335: var_decl: Declaring variable "newcontext" without initializer. libsepol-3.6/src/services.c:1462: uninit_use_in_call: Using uninitialized value "newcontext.range.level[0].cat.node" when calling "context_destroy".
\# 1460| rc = sepol_sidtab_context_to_sid(sidtab, &newcontext, out_sid); \# 1461| out: \# 1462|-> context_destroy(&newcontext); \# 1463| return rc; \# 1464| }
--- libsepol/src/services.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
libsepol/src/services.c +2 -4
@@ -1362,14 +1362,12 @@ static int sepol_compute_sid(sepol_security_id_t ssid, scontext =sepol_sidtab_search (sidtab, ssid);if (!scontext) {ERR (NULL ,"unrecognized SID %d" , ssid); - rc = -EINVAL ; - goto out; +return -EINVAL ; } tcontext =sepol_sidtab_search (sidtab, tsid);if (!tcontext) {ERR (NULL ,"unrecognized SID %d" , tsid); - rc = -EINVAL ; - goto out; +return -EINVAL ; }if (tclass && tclass <= policydb->p_classes.nprim)
Signature · 1 line
2.43.0
Quoted 6 lines · Vit Mojzis
Avoid
context_destroy()on "newcontext" beforecontext_init()is called.Fixes:
libsepol-3.6/src/services.c:1335:var_decl: Declaring variable "newcontext" without initializer.libsepol-3.6/src/services.c:1462:uninit_use_in_call: Using uninitialized value "newcontext.range.level[0].cat.node" when calling "context_destroy".
Quoted 7 lines
\# 1460| rc = sepol_sidtab_context_to_sid(sidtab, &newcontext, out_sid); \# 1461| out: \# 1462|-> context_destroy(&newcontext); \# 1463| return rc; \# 1464| }Signed-off-by Vit Mojzis <[email protected]>
LGTM.
Quoted 29 lines
--- libsepol/src/services.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)libsepol/src/services.c +2
-5@@ -1362,14 +1362,12 @@ static int sepol_compute_sid(sepol_security_id_t ssid, scontext =sepol_sidtab_search (sidtab, ssid);if (!scontext) {ERR (NULL ,"unrecognized SID %d" , ssid); - rc = -EINVAL ; - goto out; +return -EINVAL ; } tcontext =sepol_sidtab_search (sidtab, tsid);if (!tcontext) {ERR (NULL ,"unrecognized SID %d" , tsid); - rc = -EINVAL ; - goto out; +return -EINVAL ; }if (tclass && tclass <= policydb->p_classes.nprim) --2.43.0
Quoted 6 lines · Vit Mojzis
Avoid
context_destroy()on "newcontext" beforecontext_init()is called.Fixes:
libsepol-3.6/src/services.c:1335:var_decl: Declaring variable "newcontext" without initializer.libsepol-3.6/src/services.c:1462:uninit_use_in_call: Using uninitialized value "newcontext.range.level[0].cat.node" when calling "context_destroy".
Quoted 7 lines
\# 1460| rc = sepol_sidtab_context_to_sid(sidtab, &newcontext, out_sid); \# 1461| out: \# 1462|-> context_destroy(&newcontext); \# 1463| return rc; \# 1464| }Signed-off-by Vit Mojzis <[email protected]>
BTW, this function has long since diverged from the corresponding kernel function security_compute_sid; originally they were identical and even built from the same sources but we forked them long ago to specialize the kernel code. Don't believe anything is using it except for checkpolicy (via the -d option for the transition/member/change_sid commands) but no one should be relying on it matching the kernel's behavior.
Quoted 18 lines · Stephen Smalley
Quoted 6 lines · Vit Mojzis
Avoid
context_destroy()on "newcontext" beforecontext_init()is called.Fixes:
libsepol-3.6/src/services.c:1335:var_decl: Declaring variable "newcontext" without initializer.libsepol-3.6/src/services.c:1462:uninit_use_in_call: Using uninitialized value "newcontext.range.level[0].cat.node" when calling "context_destroy".Quoted 7 lines
\# 1460| rc = sepol_sidtab_context_to_sid(sidtab, &newcontext, out_sid); \# 1461| out: \# 1462|-> context_destroy(&newcontext); \# 1463| return rc; \# 1464| }Signed-off-by Vit Mojzis <[email protected]>Acked-by Stephen Smalley <[email protected]>
Quoted 7 lines
BTW, this function has long since diverged from the corresponding kernel function
security_compute_sid; originally they were identical and even built from the same sources but we forked them long ago to specialize the kernel code. Don't believe anything is using it except for checkpolicy (via the -d option for the transition/member/change_sid commands) but no one should be relying on it matching the kernel's behavior.
Applied.