>>For the translation daemon itself, you might want a libselinux function
>>that lets you disable all translations (i.e. set a flag that is checked
>>on entry by selinux_trans_to_raw_context() and
>>selinux_raw_to_trans_context() and handled in the same manner as the !
>>mls_enabled case).  Then the translation daemon could just call any
>>libselinux function without needing to worry about accidentally
>>triggering a communication to itself.
> 
> 
> I threw together a couple of patches.  Is this what you had in mind?

Saw a bug in the mcstransd patch as soon as I mailed it, fixed here.

-- ljk



--- libselinux-1.30.28/src/setrans_client.c     2006-09-13 13:37:04.000000000 
-0400
+++ libselinux-1.30.28.ljk/src/setrans_client.c 2006-10-02 14:57:22.000000000 
-0400
@@ -17,6 +17,7 @@
 #include "setrans_internal.h"
 
 static int mls_enabled = -1;
+static int trans_disabled = 0;
 
 // Simple cache
 static __thread security_context_t prev_t2r_trans = NULL;
@@ -245,7 +246,7 @@ int selinux_trans_to_raw_context(securit
                return 0;
        }
 
-       if (!mls_enabled) {
+       if (!mls_enabled || trans_disabled) {
                *rawp = strdup(trans);
                goto out;
        }
@@ -287,7 +288,7 @@ int selinux_raw_to_trans_context(securit
                return 0;
        }
 
-       if (!mls_enabled) {
+       if (!mls_enabled || trans_disabled) {
                *transp = strdup(raw);
                goto out;
        }
@@ -320,3 +321,9 @@ int selinux_raw_to_trans_context(securit
 }
 
 hidden_def(selinux_raw_to_trans_context)
+
+void selinux_disable_translation (int value)
+{
+       trans_disabled = value;
+       return;
+}
--- libselinux-1.30.28/include/selinux/selinux.h        2006-09-13 
13:37:05.000000000 -0400
+++ libselinux-1.30.28.ljk/include/selinux/selinux.h    2006-10-02 
13:12:17.000000000 -0400
@@ -444,6 +444,9 @@ extern "C" {
        extern int selinux_raw_to_trans_context(security_context_t raw,
                                                security_context_t * transp);
 
+/* Disable the translation of contexts if passed a non-zero value.*/
+       extern void selinux_disable_translation(int value);
+
 /* Get the SELinux username and level to use for a given Linux username. 
    These values may then be passed into the get_ordered_context_list*
    and get_default_context* functions to obtain a context for the user.
--- mcstrans-0.1.8/src/mcstransd.c      2006-06-19 14:38:08.000000000 -0400
+++ mcstrans-0.1.8.ljk/src/mcstransd.c  2006-10-02 14:50:35.000000000 -0400
@@ -17,6 +17,9 @@
 #include <sys/types.h>
 #include <sys/capability.h>
 #include <sys/resource.h>
+#include <selinux/avc.h>
+#include <selinux/flask.h>
+#include <selinux/av_permissions.h>
 
 #ifdef UNUSED
 #elif defined(__GNUC__)
@@ -71,22 +74,47 @@ static  __attribute__((noreturn)) void c
 }
 
 /*
+ * Check to see if the subject requesting the translation
+ * is cleared to see the translation.
+ * Returns: 0 on success (allowed), 1 on failure (denied).
+ */
+static int 
+cleared_to_translate(char *in, char *pcon)
+{
+       
+       security_id_t           ssid,tsid; /* SELinux SIDS                  */
+       int     retval;
+
+       avc_init("mcstransd", NULL, NULL, NULL, NULL); 
+       if (avc_context_to_sid(pcon, &ssid) != 0) 
+               return 1;
+       if (avc_context_to_sid(in, &tsid) != 0) {
+               free(ssid);
+               return 1;
+       }
+       retval = avc_has_perm(ssid, tsid, SECCLASS_FILE, FILE__GETATTR,
+                       NULL, NULL);
+       free(ssid);
+       free(tsid);
+       if (retval == 0)
+               return 0;
+       return 1;
+}
+
+/*
  * Convert raw label portion of a security context to translated label
  * Returns:  0 on success, 1 on failure
  */
 static int
-raw_to_trans_context(char *in, char **out, char *UNUSED(pcon))
+raw_to_trans_context(char *in, char **out, char *pcon)
 {
-
        *out = NULL; 
 
-       /* TODO: Check if MLS clearance (in "pcon") dominates the MLS label
-        * (in "in").
-        */
-
-       trans_context(in, out);
-       
-       return 0;
+       if (cleared_to_translate(in, pcon) == 0) {
+               trans_context(in, out);
+               return 0;
+       } 
+       return 1;
 }
 
 
@@ -95,16 +123,15 @@ raw_to_trans_context(char *in, char **ou
  * Returns:  0 on success, 1 on failure
  */
 static int
-trans_to_raw_context(char *in, char **out, char *UNUSED(pcon))
+trans_to_raw_context(char *in, char **out, char *pcon)
 {
        *out = NULL;
        
-       /* TODO: Check if MLS clearance (in "pcon") dominates the MLS label
-        * (in "in").
-        */
-
        untrans_context(in, out);
-
+       if (cleared_to_translate(*out, pcon) == 1) {
+               *out = NULL;
+               return 1;
+       }       
        return 0;
 }
 
@@ -493,6 +520,8 @@ initialize(void)
                cleanup_exit(1);
        }
 
+       selinux_disable_translation(1);
+
        /* the socket will be unlinked when the daemon terminates */
        act.sa_handler = sigterm_handler;
        sigemptyset(&act.sa_mask);
--
redhat-lspp mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/redhat-lspp

Reply via email to