libsepol: Move context_copy() after switch block in ocontext_copy_*().
PATCH 1/2 libsepol: Move context_copy() after switch block in ocontext_copy_*().
If an initial SID is missing a labeling statement, the compiler will segfault on the context_copy(). Move the context copy after the switch block so that the existance of the initial SID label can be checked before trying to copy the context.
This fixes both ocontext_copy_selinux() and ocontext_copy_xen().
Signed-off-by Chris PeBenito <[email protected]>
--- libsepol/src/expand.c | 18 +++++++++--------- 1 files changed, 9 insertions(+), 9 deletions(-)
libsepol/src/expand.c +9 -9
@@ -2062,11 +2062,6 @@ static int ocontext_copy_xen(expand_state_t *state)else state->out->ocontexts[i] = n; l = n; -if (context_copy (&n->context[0 ], &c->context[0 ], - state)) { -ERR (state->handle,"Out of memory!" ); -return -1 ; - }switch (i) {case OCON_XEN_ISID : n->sid[0 ] = c->sid[0 ];
@@ -2091,6 +2086,11 @@ static int ocontext_copy_xen(expand_state_t *state)ERR (state->handle,"Unknown ocontext" );return -1 ; } +if (context_copy (&n->context[0 ], &c->context[0 ], + state)) { +ERR (state->handle,"Out of memory!" ); +return -1 ; + } } }return 0 ;
@@ -2115,10 +2115,6 @@ static int ocontext_copy_selinux(expand_state_t *state)else state->out->ocontexts[i] = n; l = n; -if (context_copy (&n->context[0 ], &c->context[0 ], state)) { -ERR (state->handle,"Out of memory!" ); -return -1 ; - }switch (i) {case OCON_ISID : n->sid[0 ] = c->sid[0 ];
@@ -2164,6 +2160,10 @@ static int ocontext_copy_selinux(expand_state_t *state)ERR (state->handle,"Unknown ocontext" );return -1 ; } +if (context_copy (&n->context[0 ], &c->context[0 ], state)) { +ERR (state->handle,"Out of memory!" ); +return -1 ; + } } }return 0 ;
Signature · 7 lines
1.7.8.6 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 2/2 libsepol: check for missing initial SID labeling statement.
If an initial SID is missing a labeling statement, the compiler will segfault when trying to copy the context during expand. Check for this situation to handle it gracefully.
This fixes ocontext_copy_selinux() and ocontext_copy_xen().
Signed-off-by Chris PeBenito <[email protected]>
--- libsepol/src/expand.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)
libsepol/src/expand.c +12 -0
@@ -2064,6 +2064,12 @@ static int ocontext_copy_xen(expand_state_t *state) l = n;switch (i) {case OCON_XEN_ISID : +if (c->context[0 ].user ==0 ) { +ERR (state->handle, +"Missing context for %s initial sid" , + c->u.name); +return -1 ; + } n->sid[0 ] = c->sid[0 ];break ;case OCON_XEN_PIRQ :
@@ -2117,6 +2123,12 @@ static int ocontext_copy_selinux(expand_state_t *state) l = n;switch (i) {case OCON_ISID : +if (c->context[0 ].user ==0 ) { +ERR (state->handle, +"Missing context for %s initial sid" , + c->u.name); +return -1 ; + } n->sid[0 ] = c->sid[0 ];break ;case OCON_FS :/* FALLTHROUGH */
Signature · 7 lines
1.7.8.6 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.