Skip to contentSkip to conversation

Semanage/libsemanage seems to be broken.

DISCUSSION Ivan Gyurdiev 2 participants 2 messages Feb 10, 2006 – Feb 13, 2006 2 messages not in the archive SELinux security module

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 22 lines · Ivan Gyurdiev
Quoted 3 lines
# semanage user -a -rSystemLow-SystemHigh -R user_r -R sysadm_r walsh_u
# semaage user -d walsh_u

I assume this was misspelled in the email only.

Quoted 13 lines
# semanage user -l
               MLS/       MLS/
SELinux User    MCS Level  MCS Range                      SELinux Roles
lwalsh          None       None
root            s0         SystemLow-SystemHigh           system_r sysadm_r user_r
rwalsh          s0         s0                             system_r sysadm_r user_r
system_u        s0         SystemLow-SystemHigh           system_r
twalsh          s0         s0                             user_r
user_u          s0         SystemLow-SystemHigh           system_r sysadm_r user_r
walsh_u         None       None
Quoted 5 lines

#semanage user -d walsh_u
/usr/sbin/semanage: SELinux user walsh_u is defined in policy, cannot be deleted

#semanage user -a -rSystemLow-SystemHigh -R user_r -R sysadm_r walsh_u /usr/sbin/semanage: SELinux user walsh_u is already defined

Quoted 8 lines

Hmm.... are you shipping the prefix file for genhomedircon yet?

This appears to be caused by the users_extra file not getting cleared on policy rebuild.
I used to always clear this file. However, after Joshua's patch to support the users extra file in the package format, this was changed to not clear the file. The idea was that on commit(), that file would get overwritten by the users_extra settings from the policy package.

However, I expected this to be a required file. Is this not the case?
If the users_extra is not a required section of the module package, then perhaps we should explicitly clear that file on rebuild. The same argument applies to the seusers file, and the file contexts file. Are those sections optional?

The attached patch should fix the problem - it treats seusers and users_extra as optional sections. If they are not present, the corresponding dbase is cleared. File contexts appear to be requred (no len == 0 check).

libsemanage/src/direct_api.c +16 -9
diff -Naurp --exclude-from excludes old/libsemanage/src/direct_api.c new/libsemanage/src/direct_api.c
@@ -475,7 +475,7 @@ static int semanage_direct_commit(semana
 
 		/* ==================== File-backed ================== */
 
-		/* write the linked file contexts template */
+		/* File Contexts */
 		if ((ofilename = semanage_path(SEMANAGE_TMP, SEMANAGE_FC_TMPL)) == NULL ||
 		    write_file(sh, ofilename, sepol_module_package_get_file_contexts(base), 
 				sepol_module_package_get_file_contexts_len(base)) == -1) {
@@ -484,29 +484,36 @@ static int semanage_direct_commit(semana
 
 		if (semanage_split_fc(sh)) 
 			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) {
 				goto cleanup;
 			}
+			pseusers->dtable->drop_cache(pseusers->dbase);
+
+		} else {
+			if (pseusers->dtable->clear(sh, pseusers->dbase) < 0)
+				goto cleanup;
 		}
 
+		/* Users_extra */
 		if (sepol_module_package_get_user_extra_len(base)) {
 			if ((ofilename = semanage_path(SEMANAGE_TMP, SEMANAGE_USER_EXTRA)) == NULL ||
 			    write_file(sh, ofilename, sepol_module_package_get_user_extra(base), 
 					sepol_module_package_get_user_extra_len(base)) == -1) {
 				goto cleanup;
 			}
-		}
+			pusers_extra->dtable->drop_cache(pusers_extra->dbase);
 
-		/* Drop any cached content for file_contexts, seusers, or users_extra,
-	 	 * since it is now superceded by the files just written, and needs to be
-		 * re-cached */
-		pfcontexts->dtable->drop_cache(pfcontexts->dbase);
-		pseusers->dtable->drop_cache(pseusers->dbase);
-		pusers_extra->dtable->drop_cache(pusers_extra->dbase);
+		} else {
+			if (pusers_extra->dtable->clear(sh, pusers_extra->dbase) < 0)
+				goto cleanup;
+		}
 
 		/* ==================== Policydb-backed ================ */
 
#3 lore raw
Quoted 4 lines · Ivan Gyurdiev

The attached patch should fix the problem - it treats seusers and users_extra as optional sections. If they are not present, the corresponding dbase is cleared. File contexts appear to be requred (no len == 0 check).

Merged as of libsemanage 1.5.22.

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.