libsepol users in non-mls policy bugfix
PATCH 1/1 libsepol users in non-mls policy bugfix
This patch fixes a bug where adding a user in a non-mls module would cause a segfault at link time.
libsepol/src/link.c +8 -4
@@ -994,11 +994,15 @@ static int user_fix_callback(hashtab_key goto cleanup; } -if (mls_range_convert (&user->range, &new_user->range, mod)) - goto cleanup; +if (mod->policy->mls) { -if (mls_level_convert (&user->dfltlevel, &new_user->dfltlevel, mod)) - goto cleanup; +if (mls_range_convert (&user->range, &new_user->range, mod)) + goto cleanup; + +if (mls_level_convert (&user->dfltlevel, &new_user->dfltlevel, mod)) + goto cleanup; + + }return 0 ;
--
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.
Quoted 18 lines · Joshua Brindle
This patch fixes a bug where adding a user in a non-mls module would cause a segfault at link time.
diff -pruN
trunk/libsepol/src/link.cuser_mls_fix/libsepol/src/link.clibsepol/src/link.c +1
-4@@ -994,11 +994,15 @@ static int user_fix_callback(hashtab_key goto cleanup; } -if (mls_range_convert (&user->range, &new_user->range, mod)) - goto cleanup; +if (mod->policy->mls) { -if (mls_level_convert (&user->dfltlevel, &new_user->dfltlevel, mod)) - goto cleanup;
libsepol/src/link.c static int user_fix_callback(hashtab_key · line 1008
Quoted 10 lines
libsepol/src/link.c +7
-0+if (mls_range_convert (&user->range, &new_user->range, mod)) + goto cleanup; + +if (mls_level_convert (&user->dfltlevel, &new_user->dfltlevel, mod)) + goto cleanup; + + }return 0 ;
This patch looks ok, but shouldn't we also stop the segfault in mls_level_convert? The use of assert there looks like it is catching what should be a runtime error that should cause an error message rather than bailing.
Otherwise:
Acked by: Karl MacMillan <[email protected]>
Quoted 6 lines
--
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.
--
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.
Quoted 44 lines
From: Karl MacMillan [mailto:[email protected]]
Quoted 1 line · Joshua Brindle
This patch fixes a bug where adding a user in a non-mls
module would
Quoted 4 lines
cause a segfault at link time.
diff -pruN
trunk/libsepol/src/link.c
user_mls_fix/libsepol/src/link.cQuoted 1 line
---
trunk/libsepol/src/link.c2006-10-2815:35:26.000000000 -0400
Quoted 1 line
+++
user_mls_fix/libsepol/src/link.c2006-10-2815:26:44.000000000 -0400
libsepol/src/link.c static int user_fix_callback(hashtab_key · line 1000
Quoted 9 lines
libsepol/src/link.c +1
-3@@ -994,11 +994,15 @@ static int user_fix_callback(hashtab_key goto cleanup; } -if (mls_range_convert (&user->range, &new_user->range, mod)) - goto cleanup; +if (mod->policy->mls) { - if (mls_level_convert(&user->dfltlevel,
&new_user->dfltlevel, mod))Review static int user_fix_callback(hashtab_key · line 999
Quoted 2 lines
(quoted diff) +1
-1- goto cleanup; + if (mls_range_convert(&user->range,
&new_user->range, mod))libsepol/src/link.c static int user_fix_callback(hashtab_key
Quoted 3 lines
libsepol/src/link.c +3
-0+ goto cleanup; + + if (mls_level_convert(&user->dfltlevel,
&new_user->dfltlevel, mod))libsepol/src/link.c static int user_fix_callback(hashtab_key · line 1008
Quoted 7 lines
libsepol/src/link.c +3
-0+ goto cleanup; + + }return 0 ;This patch looks ok, but shouldn't we also stop the segfault in
mls_level_convert? The use of assert there looks like it is catching what should be a runtime error that should cause an error message rather than bailing.
Quoted 1 line
Otherwise:
Yea, I tried thinking of a more elegant way to do it and couldn't come up with anything, any suggestions?
Clearly those assertions only apply to the MLS case, and we caught a plain bug because of them, I think they are not user errors.
Quoted 5 lines
Acked by: Karl MacMillan <[email protected]>
Quoted 2 lines
Quoted 8 lines
Quoted 2 lines
--
This message was distributed to subscribers of the selinuxmailing list.
Quoted 2 lines
If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe
selinux" without quotes as the message.
--
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.
Quoted 56 lines · Joshua Brindle
Quoted 56 lines
From: Karl MacMillan [mailto:[email protected]]
Quoted 1 line · Joshua Brindle
This patch fixes a bug where adding a user in a non-mls
module would
Quoted 4 lines
cause a segfault at link time.
diff -pruN
trunk/libsepol/src/link.c
user_mls_fix/libsepol/src/link.cQuoted 1 line
---
trunk/libsepol/src/link.c2006-10-2815:35:26.000000000 -0400
Quoted 1 line
+++
user_mls_fix/libsepol/src/link.c2006-10-2815:26:44.000000000 -0400
Review static int user_fix_callback(hashtab_key · line 1000
Quoted 9 lines
(quoted diff) +1
-3@@ -994,11 +994,15 @@ static int user_fix_callback(hashtab_key goto cleanup; } - if (mls_range_convert(&user->range, &new_user->range, mod)) - goto cleanup; + if (mod->policy->mls) { - if (mls_level_convert(&user->dfltlevel,
&new_user->dfltlevel, mod))Review static int user_fix_callback(hashtab_key · line 999
Quoted 2 lines
(quoted diff) +1
-1- goto cleanup; + if (mls_range_convert(&user->range,
&new_user->range, mod))Review static int user_fix_callback(hashtab_key · line 1002
Quoted 3 lines
(quoted diff) +3
-0+ goto cleanup; + + if (mls_level_convert(&user->dfltlevel,
&new_user->dfltlevel, mod))Review static int user_fix_callback(hashtab_key · line 1008
Quoted 7 lines
(quoted diff) +3
-0+ goto cleanup; + + } return 0;This patch looks ok, but shouldn't we also stop the segfault in
mls_level_convert? The use of assert there looks like it is catching what should be a runtime error that should cause an error message rather than bailing.
Quoted 8 lines
Quoted 1 line
Otherwise:
Yea, I tried thinking of a more elegant way to do it and couldn't come up with anything, any suggestions?
Clearly those assertions only apply to the MLS case, and we caught a plain bug because of them, I think they are not user errors.
How about just putting the mls check in mls_level_convert (as it is in mls_semantic_level_expand())?
libsepol/src/link.c +0 -0
@@ -832,6 +832,9 @@ static int mls_level_convert(mls_semanti
{
mls_semantic_cat_t *src_cat, *new_cat;+ if (!mod->policy->mls)
+ return 0;
+
assert(mod->map[SYM_LEVELS][src->sens - 1]); dst->sens = mod->map[SYM_LEVELS][src->sens - 1];
That will catch all callers of the mls conversion functions in the linker. The asserts will then only apply in the MLS case as they should be.
Signature · 6 lines
Darrel -- 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.
Quoted 7 lines · Joshua Brindle
Quoted 7 lines
From: Karl MacMillan [mailto:[email protected]]
This patch looks ok, but shouldn't we also stop the segfault in
mls_level_convert? The use of assert there looks like it is catching what should be a runtime error that should cause an error message rather than bailing.
Quoted 5 lines
Quoted 1 line
Otherwise:
Yea, I tried thinking of a more elegant way to do it and couldn't come up with anything, any suggestions?
You can put the check in mls_level_convert.
Quoted 3 lines
Clearly those assertions only apply to the MLS case, and we caught a plain bug because of them, I think they are not user errors.
Yea - I forgot how all of those assertions are used in the link code. The alternative is below (with some cleanup up error handling that makes it look larger). Honestly, I don't care which patch.
Karl
src/link.c +20 -12
@@ -827,19 +827,24 @@return -1 ; } -static int mls_level_convert (mls_semantic_level_t * src, -mls_semantic_level_t * dst,policy_module_t * mod) +static int mls_level_convert (mls_semantic_level_t * src,mls_semantic_level_t * dst, +policy_module_t * mod,link_state_t * state) {mls_semantic_cat_t *src_cat, *new_cat; +if (!mod->policy->mls) +return 0 ; +assert (mod->map[SYM_LEVELS ][src->sens -1 ]); dst->sens = mod->map[SYM_LEVELS ][src->sens -1 ];for (src_cat = src->cat; src_cat; src_cat = src_cat->next) { new_cat = (mls_semantic_cat_t *)malloc (sizeof (mls_semantic_cat_t)); -if (!new_cat) +if (!new_cat) { +ERR (state->handle,"Out of memory" );return -1 ; + }mls_semantic_cat_init (new_cat); new_cat->next = dst->cat;
@@ -854,13 +859,16 @@return 0 ; } -static int mls_range_convert (mls_semantic_range_t * src, -mls_semantic_range_t * dst,policy_module_t * mod) +static int mls_range_convert (mls_semantic_range_t * src,mls_semantic_range_t * dst, +policy_module_t * mod,link_state_t * state) { -if (mls_level_convert (&src->level[0 ], &dst->level[0 ], mod)) -return -1 ; -if (mls_level_convert (&src->level[1 ], &dst->level[1 ], mod)) -return -1 ; +int ret; + ret =mls_level_convert (&src->level[0 ], &dst->level[0 ], mod, state); +if (ret) +return ret; + ret =mls_level_convert (&src->level[1 ], &dst->level[1 ], mod, state); +if (ret) +return ret;return 0 ; }
@@ -994,10 +1002,10 @@ goto cleanup; } -if (mls_range_convert (&user->range, &new_user->range, mod)) +if (mls_range_convert (&user->range, &new_user->range, mod, state)) goto cleanup; -if (mls_level_convert (&user->dfltlevel, &new_user->dfltlevel, mod)) +if (mls_level_convert (&user->dfltlevel, &new_user->dfltlevel, mod, state)) goto cleanup;return 0 ;
@@ -1224,7 +1232,7 @@ } } -if (mls_range_convert (&rule->trange, &new_rule->trange, mod)) +if (mls_range_convert (&rule->trange, &new_rule->trange, mod, state)) goto cleanup; }return 0 ;
--
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.
Joshua Brindle
Acked-byQuoted 20 lines
From: Karl MacMillan [mailto:[email protected]]
Quoted 4 lines · Joshua Brindle
Quoted 4 lines
From: Karl MacMillan [mailto:[email protected]]
This patch looks ok, but shouldn't we also stop the segfault in
mls_level_convert? The use of assert there looks like itis catching
Quoted 6 lines
Quoted 4 lines
what should be a runtime error that should cause an error message rather than bailing.
Otherwise:
Yea, I tried thinking of a more elegant way to do it and
couldn't come
Quoted 2 lines
up with anything, any suggestions?
You can put the check in
mls_level_convert.
Quoted 9 lines
Quoted 1 line
Clearly those assertions only apply to the MLS case, and we
caught a
Quoted 2 lines
plain bug because of them, I think they are not user errors.
Yea - I forgot how all of those assertions are used in the link code. The alternative is below (with some cleanup up error handling that makes it look larger). Honestly, I don't care which patch.
Looks fine aside from the unrelated parts which should have been split out :)
Quoted 96 lines
Karl
Index:
libsepol/src/link.c
===================================================================src/link.c +12
-9@@ -827,19 +827,24 @@return -1 ; } -static int mls_level_convert(mls_semantic_level_t * src, - mls_semantic_level_t * dst, policy_module_t * mod) +static int mls_level_convert (mls_semantic_level_t * src,mls_semantic_level_t * dst, +policy_module_t * mod,link_state_t * state) {mls_semantic_cat_t *src_cat, *new_cat; +if (!mod->policy->mls) +return 0 ; +assert (mod->map[SYM_LEVELS ][src->sens -1 ]); dst->sens = mod->map[SYM_LEVELS ][src->sens -1 ];for (src_cat = src->cat; src_cat; src_cat = src_cat->next) { new_cat = (mls_semantic_cat_t *)malloc (sizeof (mls_semantic_cat_t)); -if (!new_cat) +if (!new_cat) { +ERR (state->handle,"Out of memory" );return -1 ; + }mls_semantic_cat_init (new_cat); new_cat->next = dst->cat;@@ -854,13 +859,16 @@return 0 ; } -static int mls_range_convert(mls_semantic_range_t * src, - mls_semantic_range_t * dst, policy_module_t * mod) +static int mls_range_convert (mls_semantic_range_t * src,mls_semantic_range_t * dst, +policy_module_t * mod,link_state_t * state) { -if (mls_level_convert (&src->level[0 ], &dst->level[0 ], mod)) -return -1 ; -if (mls_level_convert (&src->level[1 ], &dst->level[1 ], mod)) -return -1 ; +int ret; + ret = mls_level_convert(&src->level[0], &dst->level[0],mod, state);
src/link.c +3
-0+if (ret) +return ret; + ret = mls_level_convert(&src->level[1], &dst->level[1],mod, state);
src/link.c +6
-3+if (ret) +return ret;return 0 ; }@@ -994,10 +1002,10 @@ goto cleanup; } -if (mls_range_convert (&user->range, &new_user->range, mod)) +if (mls_range_convert (&user->range, &new_user->range, mod, state)) goto cleanup; -if (mls_level_convert (&user->dfltlevel, &new_user->dfltlevel, mod)) +if (mls_level_convert (&user->dfltlevel, &new_user->dfltlevel, mod, +state)) goto cleanup;return 0 ;@@ -1224,7 +1232,7 @@ } } -if (mls_range_convert (&rule->trange, &new_rule->trange, mod)) +if (mls_range_convert (&rule->trange, &new_rule->trange, mod, state)) goto cleanup;
src/link.c
Quoted 2 lines
src/link.c +0
-0}return 0 ;
--
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.
Stephen Smalley
Acked-byQuoted 121 lines · Joshua Brindle
Quoted 20 lines
From: Karl MacMillan [mailto:[email protected]]
Quoted 4 lines · Joshua Brindle
Quoted 4 lines
From: Karl MacMillan [mailto:[email protected]]
This patch looks ok, but shouldn't we also stop the segfault in
mls_level_convert? The use of assert there looks like itis catching
Quoted 6 lines
Quoted 4 lines
what should be a runtime error that should cause an error message rather than bailing.
Otherwise:
Yea, I tried thinking of a more elegant way to do it and
couldn't come
Quoted 2 lines
up with anything, any suggestions?
You can put the check in
mls_level_convert.Quoted 9 lines
Quoted 1 line
Clearly those assertions only apply to the MLS case, and we
caught a
Quoted 2 lines
plain bug because of them, I think they are not user errors.
Yea - I forgot how all of those assertions are used in the link code. The alternative is below (with some cleanup up error handling that makes it look larger). Honestly, I don't care which patch.
Looks fine aside from the unrelated parts which should have been split out :)
Quoted 88 lines
Karl
Index:
libsepol/src/link.c
===================================================================src/link.c +12
-9@@ -827,19 +827,24 @@return -1 ; } -static int mls_level_convert(mls_semantic_level_t * src, - mls_semantic_level_t * dst, policy_module_t * mod) +static int mls_level_convert (mls_semantic_level_t * src,mls_semantic_level_t * dst, +policy_module_t * mod,link_state_t * state) {mls_semantic_cat_t *src_cat, *new_cat; +if (!mod->policy->mls) +return 0 ; +assert (mod->map[SYM_LEVELS ][src->sens -1 ]); dst->sens = mod->map[SYM_LEVELS ][src->sens -1 ];for (src_cat = src->cat; src_cat; src_cat = src_cat->next) { new_cat = (mls_semantic_cat_t *)malloc (sizeof (mls_semantic_cat_t)); -if (!new_cat) +if (!new_cat) { +ERR (state->handle,"Out of memory" );return -1 ; + }mls_semantic_cat_init (new_cat); new_cat->next = dst->cat;@@ -854,13 +859,16 @@return 0 ; } -static int mls_range_convert(mls_semantic_range_t * src, - mls_semantic_range_t * dst, policy_module_t * mod) +static int mls_range_convert (mls_semantic_range_t * src,mls_semantic_range_t * dst, +policy_module_t * mod,link_state_t * state) { -if (mls_level_convert (&src->level[0 ], &dst->level[0 ], mod)) -return -1 ; -if (mls_level_convert (&src->level[1 ], &dst->level[1 ], mod)) -return -1 ; +int ret; + ret = mls_level_convert(&src->level[0], &dst->level[0],mod, state);
src/link.c +3
-0+if (ret) +return ret; + ret = mls_level_convert(&src->level[1], &dst->level[1],mod, state);
src/link.c +5
-2+if (ret) +return ret;return 0 ; }@@ -994,10 +1002,10 @@ goto cleanup; } -if (mls_range_convert (&user->range, &new_user->range, mod)) +if (mls_range_convert (&user->range, &new_user->range, mod, state)) goto cleanup; -if (mls_level_convert (&user->dfltlevel, &new_user->dfltlevel, mod)) +if (mls_level_convert (&user->dfltlevel, &new_user->dfltlevel, mod, +state)) goto cleanup;return 0 ;@@ -1224,7 +1232,7 @@ } }
Quoted 12 lines
src/link.c
Quoted 10 lines
src/link.c +1
-1-if (mls_range_convert (&rule->trange, &new_rule->trange, mod)) +if (mls_range_convert (&rule->trange, &new_rule->trange, mod, state)) goto cleanup;src/link.c +0
-0}return 0 ;Acked-by Joshua Brindle <[email protected]>
Signature · 8 lines
Stephen Smalley National Security Agency -- 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.
Quoted 142 lines
From: Stephen Smalley [mailto:[email protected]]
Quoted 6 lines · Joshua Brindle
Quoted 6 lines
From: Karl MacMillan [mailto:[email protected]]
Quoted 3 lines · Joshua Brindle
Quoted 3 lines
From: Karl MacMillan [mailto:[email protected]]
This patch looks ok, but shouldn't we also stop the
segfault in
Quoted 12 lines
Quoted 12 lines
Quoted 1 line
Quoted 1 line
mls_level_convert? The use of assert there looks like itis catching
Quoted 6 lines
Quoted 4 lines
what should be a runtime error that should cause an error message rather than bailing.
Otherwise:
Yea, I tried thinking of a more elegant way to do it and
couldn't come
Quoted 2 lines
up with anything, any suggestions?
Quoted 8 lines
Quoted 8 lines
You can put the check in
mls_level_convert.Quoted 1 line
Clearly those assertions only apply to the MLS case, and we
caught a
Quoted 2 lines
plain bug because of them, I think they are not user errors.
Yea - I forgot how all of those assertions are used in
the link code.
Quoted 1 line
Quoted 1 line
The alternative is below (with some cleanup up error
handling that
Quoted 4 lines
Quoted 2 lines
makes it look larger). Honestly, I don't care which patch.
Looks fine aside from the unrelated parts which should have
been split
Quoted 7 lines
out :)
Quoted 5 lines
Karl
Index:
libsepol/src/link.c===================================================================
Quoted 83 lines
Quoted 83 lines
src/link.c +12
-9@@ -827,19 +827,24 @@return -1 ; } -static int mls_level_convert(mls_semantic_level_t * src, - mls_semantic_level_t * dst, policy_module_t * mod) +static int mls_level_convert (mls_semantic_level_t * src,mls_semantic_level_t * dst, +policy_module_t * mod,link_state_t * state) {mls_semantic_cat_t *src_cat, *new_cat; +if (!mod->policy->mls) +return 0 ; +assert (mod->map[SYM_LEVELS ][src->sens -1 ]); dst->sens = mod->map[SYM_LEVELS ][src->sens -1 ];for (src_cat = src->cat; src_cat; src_cat = src_cat->next) { new_cat = (mls_semantic_cat_t *)malloc (sizeof (mls_semantic_cat_t)); -if (!new_cat) +if (!new_cat) { +ERR (state->handle,"Out of memory" );return -1 ; + }mls_semantic_cat_init (new_cat); new_cat->next = dst->cat;@@ -854,13 +859,16 @@return 0 ; } -static int mls_range_convert(mls_semantic_range_t * src, - mls_semantic_range_t * dst, policy_module_t * mod) +static int mls_range_convert (mls_semantic_range_t * src,mls_semantic_range_t * dst, +policy_module_t * mod,link_state_t * state) { -if (mls_level_convert (&src->level[0 ], &dst->level[0 ], mod)) -return -1 ; -if (mls_level_convert (&src->level[1 ], &dst->level[1 ], mod)) -return -1 ; +int ret; + ret = mls_level_convert(&src->level[0], &dst->level[0],mod, state);
src/link.c +3
-0+if (ret) +return ret; + ret = mls_level_convert(&src->level[1], &dst->level[1],mod, state);
src/link.c +5
-2+if (ret) +return ret;return 0 ; }@@ -994,10 +1002,10 @@ goto cleanup; } -if (mls_range_convert (&user->range, &new_user->range, mod)) +if (mls_range_convert (&user->range, &new_user->range, mod, state)) goto cleanup; -if (mls_level_convert (&user->dfltlevel, &new_user->dfltlevel, mod)) +if (mls_level_convert (&user->dfltlevel, &new_user->dfltlevel, mod, +state)) goto cleanup;return 0 ;@@ -1224,7 +1232,7 @@ } }Quoted 12 lines
src/link.c
Quoted 10 lines
src/link.c +1
-1-if (mls_range_convert (&rule->trange, &new_rule->trange, mod)) +if (mls_range_convert (&rule->trange, &new_rule->trange, mod, state)) goto cleanup;src/link.c +0
-0}return 0 ;Acked-by Joshua Brindle <[email protected]>
Quoted 2 lines
Acked-by Stephen Smalley <[email protected]>
Merged as of libsepol 1.15.2
--
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.