libsepol: fix validation of user declarations in modules
PATCH 1/1 libsepol: fix validation of user declarations in modules
Users are allowed to be declared in modules. Modules do not get expanded leaving the struct user_datum members exp_range and exp_dfltlevel empty.
Do no validate the expanded range and level for modular polices.
--- libsepol/src/policydb_validate.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
libsepol/src/policydb_validate.c +6 -6
@@ -18,7 +18,7 @@ typedef struct validate {typedef struct map_arg {validate_t *flavors;sepol_handle_t *handle; -int mls; +policydb_t *policy; }map_arg_t ;static int create_gap_ebitmap (char **val_to_name,uint32_t nprim,ebitmap_t *gaps)
@@ -571,7 +571,7 @@ static int validate_mls_range(mls_range_t *range, validate_t *sens, validate_t *return -1 ; } -static int validate_user_datum (sepol_handle_t *handle,user_datum_t *user,validate_t flavors[],int mls) +static int validate_user_datum (sepol_handle_t *handle,user_datum_t *user,validate_t flavors[],policydb_t *p) {if (validate_value (user->s.value, &flavors[SYM_USERS ])) goto bad;
@@ -581,9 +581,9 @@ static int validate_user_datum(sepol_handle_t *handle, user_datum_t *user, valid goto bad;if (validate_mls_semantic_level (&user->dfltlevel, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) goto bad; -if (mls &&validate_mls_range (&user->exp_range, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) +if (p->mls && p->policy_type !=POLICY_MOD &&validate_mls_range (&user->exp_range, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) goto bad; -if (mls &&validate_mls_level (&user->exp_dfltlevel, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) +if (p->mls && p->policy_type !=POLICY_MOD &&validate_mls_level (&user->exp_dfltlevel, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) goto bad;if (user->bounds &&validate_value (user->bounds, &flavors[SYM_USERS ])) goto bad;
@@ -599,7 +599,7 @@ static int validate_user_datum_wrapper(__attribute__((unused)) hashtab_key_t k, {map_arg_t *margs = args; -return validate_user_datum (margs->handle, d, margs->flavors, margs->mls); +return validate_user_datum (margs->handle, d, margs->flavors, margs->policy); }static int validate_bool_datum (sepol_handle_t *handle,cond_bool_datum_t *boolean,validate_t flavors[])
@@ -689,7 +689,7 @@ static int validate_datum(__attribute__ ((unused))hashtab_key_t k, hashtab_datumstatic int validate_datum_array_entries (sepol_handle_t *handle,policydb_t *p,validate_t flavors[]) { -map_arg_t margs = { flavors, handle, p->mls }; +map_arg_t margs = { flavors, handle, p };if (hashtab_map (p->p_commons.table, validate_common_datum_wrapper, &margs)) goto bad;
Signature · 1 line
2.36.1
Quoted 8 lines · Christian Göttsche
Users are allowed to be declared in modules. Modules do not get expanded leaving the
struct user_datummembersexp_rangeandexp_dfltlevelempty.
Do no validate the expanded range and level for modular polices.Reported-by bauen1 <[email protected]>Signed-off-by Christian Göttsche <[email protected]>
Quoted 59 lines
--- libsepol/src/policydb_validate.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)libsepol/src/policydb_validate.c +6
-7@@ -18,7 +18,7 @@ typedef struct validate {typedef struct map_arg {validate_t *flavors;sepol_handle_t *handle; -int mls; +policydb_t *policy; }map_arg_t ;static int create_gap_ebitmap (char **val_to_name,uint32_t nprim,ebitmap_t *gaps)@@ -571,7 +571,7 @@ static int validate_mls_range(mls_range_t *range, validate_t *sens, validate_t *return -1 ; } -static int validate_user_datum (sepol_handle_t *handle,user_datum_t *user,validate_t flavors[],int mls) +static int validate_user_datum (sepol_handle_t *handle,user_datum_t *user,validate_t flavors[],policydb_t *p) {if (validate_value (user->s.value, &flavors[SYM_USERS ])) goto bad;@@ -581,9 +581,9 @@ static int validate_user_datum(sepol_handle_t *handle, user_datum_t *user, valid goto bad;if (validate_mls_semantic_level (&user->dfltlevel, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) goto bad; -if (mls &&validate_mls_range (&user->exp_range, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) +if (p->mls && p->policy_type !=POLICY_MOD &&validate_mls_range (&user->exp_range, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) goto bad; -if (mls &&validate_mls_level (&user->exp_dfltlevel, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) +if (p->mls && p->policy_type !=POLICY_MOD &&validate_mls_level (&user->exp_dfltlevel, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) goto bad;if (user->bounds &&validate_value (user->bounds, &flavors[SYM_USERS ])) goto bad;@@ -599,7 +599,7 @@ static int validate_user_datum_wrapper(__attribute__((unused)) hashtab_key_t k, {map_arg_t *margs = args; -return validate_user_datum (margs->handle, d, margs->flavors, margs->mls); +return validate_user_datum (margs->handle, d, margs->flavors, margs->policy); }static int validate_bool_datum (sepol_handle_t *handle,cond_bool_datum_t *boolean,validate_t flavors[])@@ -689,7 +689,7 @@ static int validate_datum(__attribute__ ((unused))hashtab_key_t k, hashtab_datumstatic int validate_datum_array_entries (sepol_handle_t *handle,policydb_t *p,validate_t flavors[]) { -map_arg_t margs = { flavors, handle, p->mls }; +map_arg_t margs = { flavors, handle, p };if (hashtab_map (p->p_commons.table, validate_common_datum_wrapper, &margs)) goto bad; --2.36.1
Quoted 9 lines · James Carter
Quoted 6 lines · Christian Göttsche
Users are allowed to be declared in modules. Modules do not get expanded leaving the
struct user_datummembersexp_rangeandexp_dfltlevelempty.
Do no validate the expanded range and level for modular polices.
Quoted 5 lines
Quoted 2 lines
Reported-by bauen1 <[email protected]>Signed-off-by Christian Göttsche <[email protected]>Acked-by James Carter <[email protected]>
Merged.
Thanks,
Jim
Quoted 59 lines
Quoted 59 lines
--- libsepol/src/policydb_validate.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)libsepol/src/policydb_validate.c +6
-7@@ -18,7 +18,7 @@ typedef struct validate {typedef struct map_arg {validate_t *flavors;sepol_handle_t *handle; -int mls; +policydb_t *policy; }map_arg_t ;static int create_gap_ebitmap (char **val_to_name,uint32_t nprim,ebitmap_t *gaps)@@ -571,7 +571,7 @@ static int validate_mls_range(mls_range_t *range, validate_t *sens, validate_t *return -1 ; } -static int validate_user_datum (sepol_handle_t *handle,user_datum_t *user,validate_t flavors[],int mls) +static int validate_user_datum (sepol_handle_t *handle,user_datum_t *user,validate_t flavors[],policydb_t *p) {if (validate_value (user->s.value, &flavors[SYM_USERS ])) goto bad;@@ -581,9 +581,9 @@ static int validate_user_datum(sepol_handle_t *handle, user_datum_t *user, valid goto bad;if (validate_mls_semantic_level (&user->dfltlevel, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) goto bad; -if (mls &&validate_mls_range (&user->exp_range, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) +if (p->mls && p->policy_type !=POLICY_MOD &&validate_mls_range (&user->exp_range, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) goto bad; -if (mls &&validate_mls_level (&user->exp_dfltlevel, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) +if (p->mls && p->policy_type !=POLICY_MOD &&validate_mls_level (&user->exp_dfltlevel, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) goto bad;if (user->bounds &&validate_value (user->bounds, &flavors[SYM_USERS ])) goto bad;@@ -599,7 +599,7 @@ static int validate_user_datum_wrapper(__attribute__((unused)) hashtab_key_t k, {map_arg_t *margs = args; -return validate_user_datum (margs->handle, d, margs->flavors, margs->mls); +return validate_user_datum (margs->handle, d, margs->flavors, margs->policy); }static int validate_bool_datum (sepol_handle_t *handle,cond_bool_datum_t *boolean,validate_t flavors[])@@ -689,7 +689,7 @@ static int validate_datum(__attribute__ ((unused))hashtab_key_t k, hashtab_datumstatic int validate_datum_array_entries (sepol_handle_t *handle,policydb_t *p,validate_t flavors[]) { -map_arg_t margs = { flavors, handle, p->mls }; +map_arg_t margs = { flavors, handle, p };if (hashtab_map (p->p_commons.table, validate_common_datum_wrapper, &margs)) goto bad; --2.36.1
Quoted 17 lines · Christian Göttsche
Users are allowed to be declared in modules. Modules do not get expanded leaving the
struct user_datummembersexp_rangeandexp_dfltlevelempty.
Do no validate the expanded range and level for modular polices.Reported-by bauen1 <[email protected]>Signed-off-by Christian Göttsche <[email protected]>--- libsepol/src/policydb_validate.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)libsepol/src/policydb_validate.c +0
-0
libsepol/src/policydb_validate.c typedef struct validate { · line 22
Quoted 6 lines
libsepol/src/policydb_validate.c +1
-1@@ -18,7 +18,7 @@ typedef struct validate {typedef struct map_arg {validate_t *flavors;sepol_handle_t *handle; -int mls; +policydb_t *policy; }map_arg_t ;
Hello,
As the policy is not modified, could this pointer be "const policydb_t *policy;"? (And the last parameter of validate_user_datum be "const policydb_t *p"). On the other hand, as policydb_validate.c does not use any const pointer, feel free to disregard my comment.
This patch nevertheless looks good to me too.
Thanks!
Nicolas
Quoted 24 lines · Nicolas Iooss
Quoted 21 lines · Christian Göttsche
Users are allowed to be declared in modules. Modules do not get expanded leaving the
struct user_datummembersexp_rangeandexp_dfltlevelempty.
Do no validate the expanded range and level for modular polices.Reported-by bauen1 <[email protected]>Signed-off-by Christian Göttsche <[email protected]>--- libsepol/src/policydb_validate.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)libsepol/src/policydb_validate.c +0
-1@@ -18,7 +18,7 @@ typedef struct validate { typedef struct map_arg { validate_t *flavors; sepol_handle_t *handle; - int mls;
Quoted 9 lines
libsepol/src/policydb_validate.c typedef struct validate { · line 22
Quoted 2 lines
libsepol/src/policydb_validate.c +1
-0+policydb_t *policy; } map_arg_t;Hello,
As the policy is not modified, could this pointer be "constpolicydb_t*policy;"? (And the last parameter ofvalidate_user_datumbe "constpolicydb_t*p"). On the other hand, aspolicydb_validate.cdoes not use any const pointer, feel free to disregard my comment.
Since policydb_validate.c does not use const pointer at all yet I followed that style.
I might prepare a patch to constify all pointers and refactor the logging mechanism,
since I like to add validation into the kernel to avoid crashes like [1], especially
if SELinux gets namespace support [2].
[1]: https://github.com/SELinuxProject/selinux-testsuite/issues/76
[2]: https://patchwork.kernel.org/project/selinux/list/?series=632975
Quoted 4 lines
This patch nevertheless looks good to me too.
Thanks!
Nicolas
PATCH v2 1/1 libsepol: fix validation of user declarations in non-base modules
In reply to Christian GöttscheUsers may be declared in non-base modules, which do not get expanded, leaving the struct user_datum members exp_range and exp_dfltlevel empty.
Skip validation of the expanded range and level for non-base module polices.
---
v2:
- update commit description and fix typos
--- libsepol/src/policydb_validate.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
libsepol/src/policydb_validate.c +6 -6
@@ -18,7 +18,7 @@ typedef struct validate {typedef struct map_arg {validate_t *flavors;sepol_handle_t *handle; -int mls; +policydb_t *policy; }map_arg_t ;static int create_gap_ebitmap (char **val_to_name,uint32_t nprim,ebitmap_t *gaps)
@@ -571,7 +571,7 @@ static int validate_mls_range(mls_range_t *range, validate_t *sens, validate_t *return -1 ; } -static int validate_user_datum (sepol_handle_t *handle,user_datum_t *user,validate_t flavors[],int mls) +static int validate_user_datum (sepol_handle_t *handle,user_datum_t *user,validate_t flavors[],policydb_t *p) {if (validate_value (user->s.value, &flavors[SYM_USERS ])) goto bad;
@@ -581,9 +581,9 @@ static int validate_user_datum(sepol_handle_t *handle, user_datum_t *user, valid goto bad;if (validate_mls_semantic_level (&user->dfltlevel, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) goto bad; -if (mls &&validate_mls_range (&user->exp_range, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) +if (p->mls && p->policy_type !=POLICY_MOD &&validate_mls_range (&user->exp_range, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) goto bad; -if (mls &&validate_mls_level (&user->exp_dfltlevel, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) +if (p->mls && p->policy_type !=POLICY_MOD &&validate_mls_level (&user->exp_dfltlevel, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) goto bad;if (user->bounds &&validate_value (user->bounds, &flavors[SYM_USERS ])) goto bad;
@@ -599,7 +599,7 @@ static int validate_user_datum_wrapper(__attribute__((unused)) hashtab_key_t k, {map_arg_t *margs = args; -return validate_user_datum (margs->handle, d, margs->flavors, margs->mls); +return validate_user_datum (margs->handle, d, margs->flavors, margs->policy); }static int validate_bool_datum (sepol_handle_t *handle,cond_bool_datum_t *boolean,validate_t flavors[])
@@ -689,7 +689,7 @@ static int validate_datum(__attribute__ ((unused))hashtab_key_t k, hashtab_datumstatic int validate_datum_array_entries (sepol_handle_t *handle,policydb_t *p,validate_t flavors[]) { -map_arg_t margs = { flavors, handle, p->mls }; +map_arg_t margs = { flavors, handle, p };if (hashtab_map (p->p_commons.table, validate_common_datum_wrapper, &margs)) goto bad;
Signature · 1 line
2.36.1
Re: [PATCH v2] libsepol: fix validation of user declarations in non-base modules
Quoted 7 lines · Christian Göttsche
Users may be declared in non-base modules, which do not get expanded, leaving the
struct user_datummembersexp_rangeandexp_dfltlevelempty.
Skip validation of the expanded range and level for non-base module polices.
Quoted 5 lines
Reported-by bauen1 <[email protected]>Signed-off-by Christian Göttsche <[email protected]>---
v2:
- update commit description and fix typos
Sorry, I didn't see this patch before I applied the first one. Jim
Quoted 59 lines
--- libsepol/src/policydb_validate.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)libsepol/src/policydb_validate.c +6
-7@@ -18,7 +18,7 @@ typedef struct validate {typedef struct map_arg {validate_t *flavors;sepol_handle_t *handle; -int mls; +policydb_t *policy; }map_arg_t ;static int create_gap_ebitmap (char **val_to_name,uint32_t nprim,ebitmap_t *gaps)@@ -571,7 +571,7 @@ static int validate_mls_range(mls_range_t *range, validate_t *sens, validate_t *return -1 ; } -static int validate_user_datum (sepol_handle_t *handle,user_datum_t *user,validate_t flavors[],int mls) +static int validate_user_datum (sepol_handle_t *handle,user_datum_t *user,validate_t flavors[],policydb_t *p) {if (validate_value (user->s.value, &flavors[SYM_USERS ])) goto bad;@@ -581,9 +581,9 @@ static int validate_user_datum(sepol_handle_t *handle, user_datum_t *user, valid goto bad;if (validate_mls_semantic_level (&user->dfltlevel, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) goto bad; -if (mls &&validate_mls_range (&user->exp_range, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) +if (p->mls && p->policy_type !=POLICY_MOD &&validate_mls_range (&user->exp_range, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) goto bad; -if (mls &&validate_mls_level (&user->exp_dfltlevel, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) +if (p->mls && p->policy_type !=POLICY_MOD &&validate_mls_level (&user->exp_dfltlevel, &flavors[SYM_LEVELS ], &flavors[SYM_CATS ])) goto bad;if (user->bounds &&validate_value (user->bounds, &flavors[SYM_USERS ])) goto bad;@@ -599,7 +599,7 @@ static int validate_user_datum_wrapper(__attribute__((unused)) hashtab_key_t k, {map_arg_t *margs = args; -return validate_user_datum (margs->handle, d, margs->flavors, margs->mls); +return validate_user_datum (margs->handle, d, margs->flavors, margs->policy); }static int validate_bool_datum (sepol_handle_t *handle,cond_bool_datum_t *boolean,validate_t flavors[])@@ -689,7 +689,7 @@ static int validate_datum(__attribute__ ((unused))hashtab_key_t k, hashtab_datumstatic int validate_datum_array_entries (sepol_handle_t *handle,policydb_t *p,validate_t flavors[]) { -map_arg_t margs = { flavors, handle, p->mls }; +map_arg_t margs = { flavors, handle, p };if (hashtab_map (p->p_commons.table, validate_common_datum_wrapper, &margs)) goto bad; --2.36.1