Seuser mls validation
Hi, the following patch adds seuser mls validation. It makes the validate function dependent on policydb, but that's fine, because validation will occur in the direct handle only, server-side, against a policydb. We won't be doing validation client side in the pserver case.
It also pulls the seuser validate() call out of merge_components, and puts it in direct_api.c, which is more correct (because seusers aren't really a policy component), and may allow future optimizations (see FIXMEs).
Also, this patch folds the seusers.h header in seuser_internal.h, like it was done elsewhere.
libsemanage/src/direct_api.c +17 -3
@@ -346,8 +346,11 @@ static int semanage_direct_commit(semana modified |= pports->dtable->is_modified (pports->dbase); modified |= pbools->dtable->is_modified (pbools->dbase); modified |= pifaces->dtable->is_modified (pifaces->dbase); -/* FIXME: should not be necessary, just for validation */ - modified |= seusers->dtable->is_modified (seusers->dbase); +int seusers_modified = seusers->dtable->is_modified (seusers->dbase); + +/* FIXME: get rid of this, once we support loading the existing policy, +* instead of rebuilding it for seusers */ + modified |= seusers_modified;/* If there were policy changes, or explicitly requested, rebuild the policy */ if (sh->do_rebuild || modified) {
@@ -383,7 +386,7 @@ static int semanage_direct_commit(semanaif (semanage_apply_local_changes (sh, out) <0 ) goto cleanup; - +if (semanage_write_policydb (sh, out) <0 ) goto cleanup;
@@ -392,6 +395,17 @@ static int semanage_direct_commit(semana goto cleanup; } +/* FIXME: else if !modified, but seusers_modified, +* load the existing policy instead of rebuilding */ + +/* Validate seusers against policy +* if either policy changed, or seusers changed, +* or we forced a rebuild */ +if (sh->do_rebuild || modified || seusers_modified) { +if (semanage_seuser_validate (sh, out) <0 ) + goto cleanup; + } +/* Commit changes to components */ if (semanage_commit_components (sh) <0 ) goto cleanup;
libsemanage/src/policy_components.c +0 -5
@@ -5,7 +5,6 @@#include "handle.h" #include "database.h" #include "modules.h" -#include "seusers.h" #include "debug.h" #define MODE_SET 1
@@ -167,10 +166,6 @@ int semanage_base_merge_components( goto err; } -/* Validate seusers against policy */ -if (semanage_seuser_validate (handle) <0 ) - goto err; -return STATUS_SUCCESS ; err:
libsemanage/src/seuser_internal.h +5 -0
@@ -3,6 +3,7 @@#include <semanage/seuser_record.h> #include <semanage/seusers.h> +#include <sepol/policydb.h> #include "database.h" #include "handle.h" #include "dso.h"
@@ -32,4 +33,8 @@ extern int seuser_file_dbase_init(extern void seuser_file_dbase_release (dbase_config_t * dconfig); +extern int hidden semanage_seuser_validate( +semanage_handle_t * handle, +sepol_policydb_t * policydb); +#endif
libsemanage/src/seusers.c +46 -13
110 lines not on this page · raw message
libsemanage/src/seusers.h +0 -11
@@ -1,11 +0,0 @@ -/* Copyright (C) 2005 Red Hat, Inc. */ - -#ifndef _SEUSERS_INTERNAL_H_ -#define _SEUSERS_INTERNAL_H_ - -#include "seuser_internal.h" - -extern int hidden semanage_seuser_validate( -semanage_handle_t * handle); - -#endif
policycoreutils/semanage/semanage +12 -7
@@ -109,8 +109,6 @@ class seluserRecords: semanage_user_add_local(self.sh, k, u) if semanage_commit(self.sh) != 0: raise ValueError("Failed to add SELinux user") - - self.dict[name]=seluser(name, roles, selevel, serange) def modify(self, name, roles=[], selevel="", serange=""): (rc,k)=semanage_user_key_create(self.sh, name)
@@ -164,7 +162,6 @@ class seluserRecords: class portRecords: def __init__(self): - self.dict={} self.sh=semanage_handle_create() self.semanaged=semanage_is_managed(self.sh) if self.semanaged:
@@ -209,11 +206,19 @@ class portRecords: def list(self): (status, self.plist, self.psize) = semanage_port_list(self.sh) - print "%-25s %s\n" % ("SELinux Port Name", "Port Number") + print "%-15s %-25s\n" % ("Port Range", "Context") for idx in range(self.psize): - u=semanage_port_by_idx(self.plist, idx) - name=semanage_port_get_name(u) - print "%20s %d" % ( name, semanage_port_get_number(u)) + p=semanage_port_by_idx(self.plist, idx) + low = semanage_port_get_low(p) + high = semanage_port_get_high(p) + proto_str = semanage_port_get_proto_str(p) + if low == high: + range_str = str(low) + else: + range_str = str(low) + ":" + str(high) + con = semanage_port_get_con(p) + (rc,con_str) = semanage_context_to_string(self.sh, con) + print "%-10s%-5s %-25s" % (range_str, proto_str, con_str) if __name__ == '__main__':
Quoted 36 lines
diff -Naurp --exclude-from excludes old/policycoreutils/semanage/semanage new/policycoreutils/semanage/semanage
policycoreutils/semanage/semanage +5
-7@@ -109,8 +109,6 @@ class seluserRecords: semanage_user_add_local(self.sh, k, u) if semanage_commit(self.sh) != 0: raise ValueError("Failed to add SELinux user") - - self.dict[name]=seluser(name, roles, selevel, serange) def modify(self, name, roles=[], selevel="", serange=""): (rc,k)=semanage_user_key_create(self.sh, name)@@ -164,7 +162,6 @@ class seluserRecords: class portRecords: def __init__(self): - self.dict={} self.sh=semanage_handle_create() self.semanaged=semanage_is_managed(self.sh) if self.semanaged:@@ -209,11 +206,19 @@ class portRecords: def list(self): (status, self.plist, self.psize) = semanage_port_list(self.sh) - print "%-25s %s\n" % ("SELinux Port Name", "Port Number") + print "%-15s %-25s\n" % ("Port Range", "Context") for idx in range(self.psize): - u=semanage_port_by_idx(self.plist, idx) - name=semanage_port_get_name(u) - print "%20s %d" % ( name, semanage_port_get_number(u)) + p=semanage_port_by_idx(self.plist, idx) + low = semanage_port_get_low(p) + high = semanage_port_get_high(p) + proto_str = semanage_port_get_proto_str(p)
policycoreutils/semanage/semanage class portRecords: · line 224
Quoted 10 lines
policycoreutils/semanage/semanage +7
-0+ if low == high: + range_str = str(low) + else: + range_str = str(low) + ":" + str(high) + con = semanage_port_get_con(p) + (rc,con_str) = semanage_context_to_string(self.sh, con) + print "%-10s%-5s %-25s" % (range_str, proto_str, con_str) if __name__ == '__main__':
Okay, that last part snuck in by accident, I had been deleting it from the patch for a while, and I finally missed it. Let me know if you want a new patch - this shouldn't do any harm with the ports merged, I think it's correct. Does not check the rc values, but neither does the rest of that tool. At least it doesn't run user code for ports, like the current implementation does.
...or just delete it if you want, Dan might have an alternative implementation.
--
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 52 lines · Ivan Gyurdiev
Quoted 35 lines
diff -Naurp --exclude-from excludes old/policycoreutils/semanage/semanage new/policycoreutils/semanage/semanage
policycoreutils/semanage/semanage +5
-7@@ -109,8 +109,6 @@ class seluserRecords: semanage_user_add_local(self.sh, k, u) if semanage_commit(self.sh) != 0: raise ValueError("Failed to add SELinux user") - - self.dict[name]=seluser(name, roles, selevel, serange) def modify(self, name, roles=[], selevel="", serange=""): (rc,k)=semanage_user_key_create(self.sh, name)@@ -164,7 +162,6 @@ class seluserRecords: class portRecords: def __init__(self): - self.dict={} self.sh=semanage_handle_create() self.semanaged=semanage_is_managed(self.sh) if self.semanaged:@@ -209,11 +206,19 @@ class portRecords: def list(self): (status, self.plist, self.psize) = semanage_port_list(self.sh) - print "%-25s %s\n" % ("SELinux Port Name", "Port Number") + print "%-15s %-25s\n" % ("Port Range", "Context") for idx in range(self.psize): - u=semanage_port_by_idx(self.plist, idx) - name=semanage_port_get_name(u) - print "%20s %d" % ( name, semanage_port_get_number(u)) + p=semanage_port_by_idx(self.plist, idx) + low = semanage_port_get_low(p) + high = semanage_port_get_high(p) + proto_str = semanage_port_get_proto_str(p)policycoreutils/semanage/semanage class portRecords: · line 224
Quoted 10 lines
policycoreutils/semanage/semanage +7
-0+ if low == high: + range_str = str(low) + else: + range_str = str(low) + ":" + str(high) + con = semanage_port_get_con(p) + (rc,con_str) = semanage_context_to_string(self.sh, con) + print "%-10s%-5s %-25s" % (range_str, proto_str, con_str) if __name__ == '__main__':Okay, that last part snuck in by accident, I had been deleting it from the patch for a while, and I finally missed it. Let me know if you want a new patch - this shouldn't do any harm with the ports merged, I think it's correct. Does not check the rc values, but neither does the rest of that tool. At least it doesn't run user code for ports, like the current implementation does.
Quoted 2 lines
...or just delete it if you want, Dan might have an alternative implementation.
Is the semanage diff here obsoleted by Dan's latest policycoreutils patch? Also, the first hunk looks odd to me - what is it doing?
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 3 lines
Is the semanage diff here obsoleted by Dan's latest policycoreutils patch?
Yes, just use Dan's copy...
Quoted 2 lines
Also, the first hunk looks odd to me - what is it doing?
No clue - that's why I was deleting it :)
It just caused python interpreter errors.
--
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 9 lines · Ivan Gyurdiev
Quoted 3 lines
Is the semanage diff here obsoleted by Dan's latest policycoreutils patch?
Yes, just use Dan's copy...
Quoted 2 lines
Also, the first hunk looks odd to me - what is it doing?
No clue - that's why I was deleting it :)
It just caused python interpreter errors.
Yes use mine. The self.dict stuff was an original implementation that didn't get fully removed.
Dan
--
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.