libsemanage: preserve read-only store overrides
Stephen Smalley
maintainerPATCH 1/1 libsemanage: preserve read-only store overrides
Keep per-file store fallback, but stop CIL lookup at an earlier HLL source whose cache is missing. Create writable module directories before compiling vendor-only HLL, refresh the extraction path after compilation, and report enabled state from RO-aware module metadata.
RO HLL can change independently of a writable derived CIL cache. Recompile externally sourced HLL when processing it for a build or CIL extraction; retain normal caching for writable HLL.
Resolve store-backed file databases at cache time rather than pinning the first active path at connect. Permit TMP fallbacks only for local record files and invalidate cached views across transaction-state changes. Existing flush-on-modification provides file-level copy-on-write, including an empty file that shadows vendor records after deleting the last entry. Use the same fallback when publishing local file contexts.
For ACTIVE as well as TMP, stop fallback when checking the writable path fails for a reason other than ENOENT, so errors are not hidden by a read-only copy.
This prevents replacement HLL from silently using vendor CIL, stale vendor-derived policy after rebuild, and loss of RO local overrides during transactions. No public API or policy format change is needed.
--- libsemanage/src/database_file.c | 26 ++++++++++ libsemanage/src/direct_api.c | 85 +++++++++++++++++++++----------- libsemanage/src/modules.c | 29 +++++++---- libsemanage/src/semanage_store.c | 28 +++++++++-- 4 files changed, 125 insertions(+), 43 deletions(-)
libsemanage/src/database_file.c +26 -0
@@ -32,6 +32,9 @@ struct dbase_file {/* Backing path for read-only[0] and transaction[1] */ const char *path[2 ]; +int store_file; +int cache_in_transaction; +/* FILE extension */ const record_file_table_t *rftable; };
@@ -47,6 +50,12 @@ static int dbase_file_cache(semanage_handle_t *handle, dbase_file_t *dbase)parse_info_t *parse_info =NULL ;const char *fname =NULL ; +/* A transaction changes the source even when the serial is unchanged. */ +if (dbase->store_file >=0 && + dbase->cache_in_transaction != handle->is_in_transaction) +dbase_llist_drop_cache (&dbase->llist); + dbase->cache_in_transaction = handle->is_in_transaction; +/* Already cached */ if (!dbase_llist_needs_resync (handle, &dbase->llist))return STATUS_SUCCESS ;
@@ -57,6 +66,11 @@ static int dbase_file_cache(semanage_handle_t *handle, dbase_file_t *dbase) goto err; fname = dbase->path[handle->is_in_transaction]; +if (dbase->store_file >=0 ) + fname =semanage_path_read (handle->is_in_transaction ? +SEMANAGE_TMP : +SEMANAGE_ACTIVE , + dbase->store_file);if (parse_init (handle, fname,NULL , &parse_info) <0 ) goto err;
@@ -168,6 +182,18 @@ int dbase_file_init(semanage_handle_t *handle, const char *path_ro, tmp_dbase->path[0 ] = path_ro; tmp_dbase->path[1 ] = path_rw; + tmp_dbase->store_file =-1 ; + tmp_dbase->cache_in_transaction = handle->is_in_transaction; +if (semanage_ro_root_count () >0 ) { +int i; + +for (i =0 ; i <SEMANAGE_STORE_NUM_PATHS ; i++) { +if (!strcmp (path_rw,semanage_path (SEMANAGE_TMP , i))) { + tmp_dbase->store_file = i; +break ; + } + } + } tmp_dbase->rftable = rftable;dbase_llist_init (&tmp_dbase->llist, rtable, &SEMANAGE_FILE_DTABLE );
libsemanage/src/direct_api.c +55 -30
150 lines not on this page · raw message
libsemanage/src/modules.c +20 -9
@@ -555,6 +555,8 @@ int semanage_module_get_path(semanage_handle_t *sh,* modules root, filling @path with the first location that exists. * When the module exists nowhere, @path is left with the writable root * value so the caller's error message names the write target. +* A missing CIL cache beside an HLL source must be rebuilt, not replaced +* by a lower root's cache for a different source module. */ int semanage_module_find_path(semanage_handle_t *sh, const semanage_module_info_t *modinfo,
@@ -562,19 +564,28 @@ int semanage_module_find_path(semanage_handle_t *sh, size_t len) {unsigned int i, n =semanage_ro_root_count (); +const char *root; +char hll_path[PATH_MAX ];int ret; - ret =semanage_module_build_path (sh,semanage_module_write_root (sh), - modinfo, type, path, len); -if (ret !=0 || n ==0 ||access (path,F_OK ) ==0 ) -return ret; - -for (i =0 ; i < n; i++) { - ret =semanage_module_build_path ( - sh,semanage_ro_active_path (i,SEMANAGE_MODULES ), - modinfo, type, path, len); +for (i =0 ;; i++) { + root = (i ==0 ) ? +semanage_module_write_root (sh) : +semanage_ro_active_path (i -1 ,SEMANAGE_MODULES ); + ret =semanage_module_build_path (sh, root, modinfo, type, path, + len);if (ret !=0 ||access (path,F_OK ) ==0 )return ret; + +if (type ==SEMANAGE_MODULE_PATH_CIL ) { + ret =semanage_module_build_path ( + sh, root, modinfo,SEMANAGE_MODULE_PATH_HLL , + hll_path,sizeof (hll_path)); +if (ret !=0 ||access (hll_path,F_OK ) ==0 ) +return ret; + } +if (i == n) +break ; }/* Not found anywhere; restore the writable-root path */
libsemanage/src/semanage_store.c +24 -4
@@ -502,9 +502,10 @@ const char *semanage_ro_active_path(unsigned int idx,/* * First-existing of the writable ACTIVE path and each RO ACTIVE path, -* for read-side lookups. For TMP/PREVIOUS, or when no fallback root -* has the file, this is semanage_path(store, file) so callers that -* then create the file use the writable store. +* for read-side lookups. TMP also falls back for local record files; +* generated policy files and PREVIOUS never fall back. An existing empty +* writable file shadows the read-only file, including after deleting +* the last local record. */ const char *semanage_path_read (enum semanage_store_defs store,enum semanage_sandbox_defs file)
@@ -512,7 +513,26 @@ const char *semanage_path_read(enum semanage_store_defs store,const char *path =semanage_path (store, file);unsigned int i; -if (store !=SEMANAGE_ACTIVE ||access (path,F_OK ) ==0 ) +if (store ==SEMANAGE_TMP ) { +switch (file) { +case SEMANAGE_IBPKEYS_LOCAL : +case SEMANAGE_IBENDPORTS_LOCAL : +case SEMANAGE_PORTS_LOCAL : +case SEMANAGE_INTERFACES_LOCAL : +case SEMANAGE_NODES_LOCAL : +case SEMANAGE_BOOLEANS_LOCAL : +case SEMANAGE_SEUSERS_LOCAL : +case SEMANAGE_USERS_BASE_LOCAL : +case SEMANAGE_USERS_EXTRA_LOCAL : +case SEMANAGE_STORE_FC_LOCAL : +break ; +default : +return path; + } + }else if (store !=SEMANAGE_ACTIVE ) +return path; + +if (access (path,F_OK ) ==0 || errno !=ENOENT )return path;for (i =0 ; i < semanage_n_ro_roots; i++) {
Signature · 1 line
2.56.0
Stephen Smalley
maintainerQuoted 22 lines · Stephen Smalley
Keep per-file store fallback, but stop CIL lookup at an earlier HLL source whose cache is missing. Create writable module directories before compiling vendor-only HLL, refresh the extraction path after compilation, and report enabled state from RO-aware module metadata.
RO HLL can change independently of a writable derived CIL cache. Recompile externally sourced HLL when processing it for a build or CIL extraction; retain normal caching for writable HLL.
Resolve store-backed file databases at cache time rather than pinning the first active path at connect. Permit TMP fallbacks only for local record files and invalidate cached views across transaction-state changes. Existing flush-on-modification provides file-level copy-on-write, including an empty file that shadows vendor records after deleting the last entry. Use the same fallback when publishing local file contexts.
For ACTIVE as well as TMP, stop fallback when checking the writable path fails for a reason other than ENOENT, so errors are not hidden by a read-only copy.
Quoted 5 lines
This prevents replacement HLL from silently using vendor CIL, stale vendor-derived policy after rebuild, and loss of RO local overrides during transactions. No public API or policy format change is needed.
Signed-off-by Stephen Smalley <[email protected]>
This has been merged.