From: <mad...@us...> - 2007-01-08 20:30:33
|
Revision: 2154 http://svn.sourceforge.net/selinux/?rev=2154&view=rev Author: madmethod Date: 2007-01-08 12:30:28 -0800 (Mon, 08 Jan 2007) Log Message: ----------- The function semanage_direct_commit in libsemanage:direct_api.c does not correctly propagate error codes. This patch fixes that. Signed-off-by: Karl MacMillan <kma...@me...> Acked-By: Joshua Brindle <jbr...@tr...> Modified Paths: -------------- trunk/libsemanage/src/direct_api.c Modified: trunk/libsemanage/src/direct_api.c =================================================================== --- trunk/libsemanage/src/direct_api.c 2007-01-05 19:15:46 UTC (rev 2153) +++ trunk/libsemanage/src/direct_api.c 2007-01-08 20:30:28 UTC (rev 2154) @@ -467,9 +467,11 @@ /* Before we do anything else, flush the join to its component parts. * This *does not* flush to disk automatically */ - if (users->dtable->is_modified(users->dbase) && - users->dtable->flush(sh, users->dbase) < 0) - goto cleanup; + if (users->dtable->is_modified(users->dbase)) { + retval = users->dtable->flush(sh, users->dbase); + if (retval < 0) + goto cleanup; + } /* Decide if anything was modified */ fcontexts_modified = fcontexts->dtable->is_modified(fcontexts->dbase); @@ -497,85 +499,97 @@ /* =================== Module expansion =============== */ /* link all modules in the sandbox to the base module */ - if (semanage_get_modules_names - (sh, &mod_filenames, &num_modfiles) != 0 - || semanage_verify_modules(sh, mod_filenames, - num_modfiles) == -1 - || semanage_link_sandbox(sh, &base) < 0) { + retval = semanage_get_modules_names(sh, &mod_filenames, &num_modfiles); + if (retval < 0) goto cleanup; - } + retval = semanage_verify_modules(sh, mod_filenames, num_modfiles); + if (retval < 0) + goto cleanup; + retval = semanage_link_sandbox(sh, &base); + if (retval < 0) + goto cleanup; /* write the linked base */ - if ((linked_filename = - semanage_path(SEMANAGE_TMP, SEMANAGE_LINKED)) == NULL - || semanage_write_module(sh, linked_filename, base) == -1 - || semanage_verify_linked(sh) != 0) { + linked_filename = semanage_path(SEMANAGE_TMP, SEMANAGE_LINKED); + if (linked_filename == NULL) { + retval = -1; goto cleanup; } + retval = semanage_write_module(sh, linked_filename, base); + if (retval < 0) + goto cleanup; + retval = semanage_verify_linked(sh); + if (retval < 0) + goto cleanup; /* ==================== File-backed ================== */ /* File Contexts */ /* Sort the file contexts. */ - if (semanage_fc_sort - (sh, sepol_module_package_get_file_contexts(base), - sepol_module_package_get_file_contexts_len(base), - &sorted_fc_buffer, &sorted_fc_buffer_len) == -1) { + retval = semanage_fc_sort(sh, sepol_module_package_get_file_contexts(base), + sepol_module_package_get_file_contexts_len(base), + &sorted_fc_buffer, &sorted_fc_buffer_len); + if (retval < 0) goto cleanup; - } /* Write the contexts (including template contexts) to a single file. * The buffer returned by the sort function has a trailing \0 character, * which we do NOT want to write out to disk, so we pass sorted_fc_buffer_len-1. */ - if ((ofilename = - semanage_path(SEMANAGE_TMP, SEMANAGE_FC_TMPL)) == NULL - || write_file(sh, ofilename, sorted_fc_buffer, - sorted_fc_buffer_len - 1) == -1) { + ofilename = semanage_path(SEMANAGE_TMP, SEMANAGE_FC_TMPL); + if (ofilename == NULL) { + retval = -1; goto cleanup; } + retval = write_file(sh, ofilename, sorted_fc_buffer, + sorted_fc_buffer_len - 1); + if (retval < 0) + goto cleanup; /* Split complete and template file contexts into their separate files. */ - if (semanage_split_fc(sh)) + retval = semanage_split_fc(sh); + if (retval < 0) goto cleanup; pfcontexts->dtable->drop_cache(pfcontexts->dbase); /* Seusers */ if (sepol_module_package_get_seusers_len(base)) { - if ((ofilename = - semanage_path(SEMANAGE_TMP, - SEMANAGE_SEUSERS)) == NULL - || write_file(sh, ofilename, - sepol_module_package_get_seusers - (base), - sepol_module_package_get_seusers_len - (base)) == -1) { + ofilename = semanage_path(SEMANAGE_TMP, SEMANAGE_SEUSERS); + if (ofilename == NULL) { + retval = -1; goto cleanup; } + retval = write_file(sh, ofilename, + sepol_module_package_get_seusers(base), + sepol_module_package_get_seusers_len(base)); + if (retval < 0) + goto cleanup; + pseusers->dtable->drop_cache(pseusers->dbase); } else { - if (pseusers->dtable->clear(sh, pseusers->dbase) < 0) + retval = pseusers->dtable->clear(sh, pseusers->dbase); + if (retval < 0) goto cleanup; } /* Users_extra */ if (sepol_module_package_get_user_extra_len(base)) { - if ((ofilename = - semanage_path(SEMANAGE_TMP, - SEMANAGE_USERS_EXTRA)) == NULL - || write_file(sh, ofilename, - sepol_module_package_get_user_extra - (base), - sepol_module_package_get_user_extra_len - (base)) == -1) { + ofilename = semanage_path(SEMANAGE_TMP, SEMANAGE_USERS_EXTRA); + if (ofilename == NULL) { + retval = -1; goto cleanup; } + retval = write_file(sh, ofilename, + sepol_module_package_get_user_extra(base), + sepol_module_package_get_user_extra_len(base)); + if (retval < 0) + goto cleanup; pusers_extra->dtable->drop_cache(pusers_extra->dbase); } else { - if (pusers_extra->dtable-> - clear(sh, pusers_extra->dbase) < 0) + retval = pusers_extra->dtable->clear(sh, pusers_extra->dbase); + if (retval < 0) goto cleanup; } @@ -603,7 +617,8 @@ /* Create new policy object, then attach to policy databases * that work with a policydb */ - if (semanage_expand_sandbox(sh, base, &out) < 0) + retval = semanage_expand_sandbox(sh, base, &out); + if (retval < 0) goto cleanup; dbase_policydb_attach((dbase_policydb_t *) pusers_base->dbase, @@ -615,13 +630,16 @@ /* ============= Apply changes, and verify =============== */ - if (semanage_base_merge_components(sh) < 0) + retval = semanage_base_merge_components(sh); + if (retval < 0) goto cleanup; - if (semanage_write_policydb(sh, out) < 0) + retval = semanage_write_policydb(sh, out); + if (retval < 0) goto cleanup; - if (semanage_verify_kernel(sh) != 0) + retval = semanage_verify_kernel(sh); + if (retval < 0) goto cleanup; } @@ -635,26 +653,30 @@ * merged into the main file_contexts. We won't check the * large file_contexts - checked at compile time */ if (sh->do_rebuild || modified || fcontexts_modified) { - if (semanage_fcontext_validate_local(sh, out) < 0) + retval = semanage_fcontext_validate_local(sh, out); + if (retval < 0) goto cleanup; } /* Validate local seusers against policy */ if (sh->do_rebuild || modified || seusers_modified) { - if (semanage_seuser_validate_local(sh, out) < 0) + retval = semanage_seuser_validate_local(sh, out); + if (retval < 0) goto cleanup; } /* Validate local ports for overlap */ if (sh->do_rebuild || ports_modified) { - if (semanage_port_validate_local(sh) < 0) + retval = semanage_port_validate_local(sh); + if (retval < 0) goto cleanup; } /* ================== Write non-policydb components ========= */ /* Commit changes to components */ - if (semanage_commit_components(sh) < 0) + retval = semanage_commit_components(sh); + if (retval < 0) goto cleanup; retval = semanage_install_sandbox(sh); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ssm...@us...> - 2008-02-04 15:41:25
|
Revision: 2780 http://selinux.svn.sourceforge.net/selinux/?rev=2780&view=rev Author: ssmalley Date: 2008-02-04 07:41:21 -0800 (Mon, 04 Feb 2008) Log Message: ----------- Author: Stephen Smalley Email: sd...@ty... Subject: libsemanage: free base immediately after expand Date: Fri, 01 Feb 2008 09:11:06 -0500 Drop the base module immediately after expanding, so that the memory can be reused for the remainder of the transaction. Signed-off-by: Stephen Smalley <sd...@ty...> Acked-By: Joshua Brindle <me...@ma...> Acked-By: Todd C. Miller <tm...@tr...> Modified Paths: -------------- trunk/libsemanage/src/direct_api.c Modified: trunk/libsemanage/src/direct_api.c =================================================================== --- trunk/libsemanage/src/direct_api.c 2008-02-04 15:26:35 UTC (rev 2779) +++ trunk/libsemanage/src/direct_api.c 2008-02-04 15:41:21 UTC (rev 2780) @@ -642,6 +642,9 @@ retval = semanage_expand_sandbox(sh, base, &out); if (retval < 0) goto cleanup; + + sepol_module_package_free(base); + base = NULL; dbase_policydb_attach((dbase_policydb_t *) pusers_base->dbase, out); @@ -718,7 +721,6 @@ dbase_policydb_detach((dbase_policydb_t *) pbools->dbase); free(mod_filenames); - sepol_module_package_free(base); sepol_policydb_free(out); semanage_release_trans_lock(sh); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ssm...@us...> - 2008-04-21 17:58:41
|
Revision: 2871 http://selinux.svn.sourceforge.net/selinux/?rev=2871&view=rev Author: ssmalley Date: 2008-04-21 09:55:37 -0700 (Mon, 21 Apr 2008) Log Message: ----------- Author: Stephen Smalley Email: sd...@ty... Subject: libsemanage: don't call genhomedircon if policy was not rebuilt Date: Mon, 21 Apr 2008 09:41:15 -0400 See: https://bugzilla.redhat.com/show_bug.cgi?id=441379 It appears to me that what is happening here is we have a case where nothing is being rebuilt (semanage boolean -D is being applied but there are no local boolean definitions and thus no change), and thus semanage_direct_commit() does not rebuild the policy (conditional on sh->do_rebuild || modified), leaving the out policydb == NULL. Then when it calls semanage_genhomedircon(sh, out, 1) the NULL policydb pointer ultimately gets passed down to libsepol and that then triggers a seg fault upon the attempted dereference. This patch ensures that we do not call genhomedircon if the policy was not rebuilt, as there is no need to regenerate home directory contexts in that situation. This avoids the bug for semanage boolean -D while still properly handling semodule -Bn aka genhomedircon or other operations. Signed-off-by: Stephen Smalley <sd...@ty...> Acked-by: Joshua Brindle <me...@ma...> Modified Paths: -------------- trunk/libsemanage/src/direct_api.c Modified: trunk/libsemanage/src/direct_api.c =================================================================== --- trunk/libsemanage/src/direct_api.c 2008-04-18 14:23:06 UTC (rev 2870) +++ trunk/libsemanage/src/direct_api.c 2008-04-21 16:55:37 UTC (rev 2871) @@ -708,7 +708,7 @@ /* run genhomedircon if its enabled, this should be the last operation * which requires the out policydb */ if (!sh->conf->disable_genhomedircon) { - if ((retval = + if (out && (retval = semanage_genhomedircon(sh, out, 1)) != 0) { ERR(sh, "semanage_genhomedircon returned error code %d.", retval); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |