Skip to contentSkip to conversation

old SE Linux patch for procps 3.1.12

PATCH Russell Coker 2 participants 4 messages Oct 19, 2003 – Oct 21, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Procps includes SE Linux support upstream, but it's a bit outdated.

I have attached a patch to remove support for displaying SIDs. It is a bit rough and has a memory leak (allocates textual representations of contexts but never frees them - may be a problem for "top").

I wrote this because I couldn't figure out how to get a straight patch for the new SE Linux, so I updated the old SE Linux code to be more like the new SE Linux code as an intermediate step.

Signature · 4 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page
Makefile renamed from procps-3.1.12/Makefile +3 -3
diff -ruN orig/procps-3.1.12/Makefile procps-3.1.12/Makefile
@@ -166,13 +166,13 @@
 ############ prog.o --> prog
 
 pmap w uptime tload free sysctl vmstat utmp pgrep skill: % : %.o $(LIBPROC)
-	$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) -o $@ $^
+	$(CC) $(ALL_CFLAGS) $^ $(ALL_LDFLAGS) -o $@
 
 top:   % : %.o $(LIBPROC)
-	$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) -o $@ $^ $(CURSES)
+	$(CC) $(ALL_CFLAGS) $^ $(ALL_LDFLAGS) -o $@ $(CURSES)
 
 watch: % : %.o
-	$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) -o $@ $^ $(CURSES)
+	$(CC) $(ALL_CFLAGS) $^ $(ALL_LDFLAGS) -o $@ $(CURSES)
 
 ############ progX --> progY
 
debian/changelog renamed from procps-3.1.12/debian/changelog +8 -0
diff -ruN orig/procps-3.1.12/debian/changelog procps-3.1.12/debian/changelog
@@ -1,3 +1,11 @@
+procps (1:3.1.12-1.se2) unstable; urgency=low
+
+  * Build with SE Linux support.
+
+  * Remove SID support.
+
+ -- Russell Coker <[email protected]>  Sun, 19 Oct 2003 13:47:00 +1000
+
 procps (1:3.1.12-1) unstable; urgency=low
 
   * New upstream release
debian/control renamed from procps-3.1.12/debian/control +1 -1
diff -ruN orig/procps-3.1.12/debian/control procps-3.1.12/debian/control
@@ -2,7 +2,7 @@
 Section: base
 Priority: required
 Maintainer: Craig Small <[email protected]>
-Build-Depends: debhelper (>> 4.1.1), libncurses5-dev, make (>= 3.78.1-8)
+Build-Depends: debhelper (>> 4.1.1), libncurses5-dev, make (>= 3.78.1-8), libselinux-dev
 Standards-Version: 3.5.9
 
 Package: procps
debian/rules renamed from procps-3.1.12/debian/rules +1 -1
diff -ruN orig/procps-3.1.12/debian/rules procps-3.1.12/debian/rules
@@ -21,7 +21,7 @@
 	SHARED=0 $(MAKE) proc/libproc.a
 	mv proc/libproc.a static
 	$(MAKE) clean
-	$(MAKE) W_SHOWFROM=\-DW_SHOWFROM
+	$(MAKE) W_SHOWFROM=\-DW_SHOWFROM LDFLAGS=-lsecure CFLAGS="-O2 -g3 -I/usr/include/selinux -DFLASK_LINUX"
 
 	touch build-stamp
 
proc/module.mk renamed from procps-3.1.12/proc/module.mk +1 -1
diff -ruN orig/procps-3.1.12/proc/module.mk procps-3.1.12/proc/module.mk
@@ -45,7 +45,7 @@
 
 #proc/$(SONAME): proc/library.map
 proc/$(SONAME): $(LIBOBJ)
-	$(CC) -shared -Wl,-soname,$(SONAME) -Wl,--version-script=proc/library.map -o $@ $^ -lc
+	$(CC) -shared -Wl,-soname,$(SONAME) -Wl,--version-script=proc/library.map -o $@ $^ -lc -lsecure
 	cd proc && $(ln_sf) $(SONAME) lib$(NAME).so
 
 
proc/readproc.c renamed from procps-3.1.12/proc/readproc.c +23 -4
diff -ruN orig/procps-3.1.12/proc/readproc.c procps-3.1.12/proc/readproc.c
@@ -29,6 +29,8 @@
 
 #ifdef FLASK_LINUX
 #include <fs_secure.h>
+#include <ss.h>
+#include <selinux.h>
 #endif
 
 #ifdef PROF
@@ -485,6 +487,17 @@
     return n;
 }
 
+#ifdef FLASK_LINUX
+security_context_t sid_to_con(security_id_t sid)
+{
+  char buf[4096];
+  int len = sizeof(buf);
+  if(security_sid_to_context(sid, buf, &len))
+    return NULL;
+  return strdup(buf);
+}
+#endif
+
 /* These are some nice GNU C expression subscope "inline" functions.
  * The can be used with arbitrary types and evaluate their arguments
  * exactly once.
@@ -521,6 +534,7 @@
     static char path[32], sbuf[1024];	/* bufs for stat,statm */
 #ifdef FLASK_LINUX
     security_id_t secsid;
+    int selinux_enabled=is_selinux_enabled();
 #endif
     pid_t pid;  // saved until we have a proc_t allocated for sure
 
@@ -547,7 +561,8 @@
 //	snprintf(path, sizeof path, "/proc/%s", ent->d_name);
     }
 #ifdef FLASK_LINUX
-    if ( stat_secure(path, &sb, &secsid) == -1 ) /* no such dirent (anymore) */
+    if ( (selinux_enabled && unlikely(stat_secure(path, &sb, &secsid) == -1))
+       || unlikely(stat(path, &sb) == -1) ) /* no such dirent (anymore) */
 #else
     if (unlikely(stat(path, &sb) == -1))	/* no such dirent (anymore) */
 #endif
@@ -562,7 +577,8 @@
     p->euid = sb.st_uid;			/* need a way to get real uid */
     p->egid = sb.st_gid;			/* need a way to get real gid */
 #ifdef FLASK_LINUX
-    p->secsid = secsid;
+    if(selinux_enabled)
+      p->scontext = sid_to_con(secsid);
 #endif
     p->pid  = pid;
 
@@ -633,6 +649,7 @@
     static char path[32], sbuf[1024];	/* bufs for stat,statm */
 #ifdef FLASK_LINUX
     security_id_t secsid;
+    int selinux_enabled=is_selinux_enabled();
 #endif
     pid_t pid;  // saved until we have a proc_t allocated for sure
 
@@ -654,7 +671,8 @@
 //  snprintf(path, sizeof path, "/proc/%s", ent->d_name);
 
 #ifdef FLASK_LINUX
-    if (stat_secure(path, &sb, &secsid) == -1) /* no such dirent (anymore) */
+    if ( (selinux_enabled && stat_secure(path, &sb, &secsid) == -1)
+        || stat(path, &sb) == -1) /* no such dirent (anymore) */
 #else
     if (stat(path, &sb) == -1)		/* no such dirent (anymore) */
 #endif
@@ -666,7 +684,8 @@
     p->euid = sb.st_uid;			/* need a way to get real uid */
     p->egid = sb.st_gid;			/* need a way to get real gid */
 #ifdef FLASK_LINUX
-    p->secsid = secsid;
+    if(selinux_enabled)
+      p->scontext = sid_to_con(secsid);
 #endif
     p->pid  = pid;
 
proc/readproc.h renamed from procps-3.1.12/proc/readproc.h +2 -2
diff -ruN orig/procps-3.1.12/proc/readproc.h procps-3.1.12/proc/readproc.h
@@ -137,7 +137,7 @@
 	exit_signal,	/* might not be SIGCHLD */
 	processor;      /* current (or most recent?) CPU */
 #ifdef FLASK_LINUX
-	security_id_t secsid;
+	security_context_t scontext;
 #endif
 } proc_t;
 
@@ -155,7 +155,7 @@
     uid_t*	uids;	/* uids of procs */
     int		nuid;	/* cannot really sentinel-terminate unsigned short[] */
 #ifdef FLASK_LINUX
-    security_id_t* sids; /* SIDs of the procs */
+    security_context_t* scontexts; /* security contexts of the procs */
 #endif
 } PROCTAB;
 
ps/common.h renamed from procps-3.1.12/ps/common.h +0 -1
diff -ruN orig/procps-3.1.12/ps/common.h procps-3.1.12/ps/common.h
@@ -103,7 +103,6 @@
 #define FF_LX 0x0100 /* X */
 #define FF_Lm 0x0200 /* m */  /* overloaded: threads, sort, format */
 #define FF_Fc 0x0400 /* --context */  /* Flask security context format */
-#define FF_Fs 0x0800 /* --SID */      /* Flask SID format */
 
 /* predefined format modifier flags such as:  -l -f l u s -j */
 #define FM_c 0x0001 /* -c */
ps/module.mk renamed from procps-3.1.12/ps/module.mk +2 -2
diff -ruN orig/procps-3.1.12/ps/module.mk procps-3.1.12/ps/module.mk
@@ -20,11 +20,11 @@
 TARFILES += $(PSSRC) $(addprefix ps/,$(PS_X))
 
 ps/ps: $(PSOBJ) $(LIBPROC)
-	$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) -o $@ $^
+	$(CC) $(ALL_CFLAGS) $^ $(ALL_LDFLAGS) -o $@
 
 # This just adds the stacktrace code
 ps/debug: $(PSOBJ) stacktrace.o $(LIBPROC)
-	$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) -o $@ $^ -lefence
+	$(CC) $(ALL_CFLAGS) $^ $(ALL_LDFLAGS) -o $@ -lefence
 
 $(PSOBJ): %.o: %.c ps/common.h $(LIBPROC)
 	$(CC) -c $(ALL_CPPFLAGS) $(ALL_CFLAGS) $< -o $@
ps/output.c renamed from procps-3.1.12/ps/output.c +9 -119

161 lines not on this page · raw message

ps/parser.c renamed from procps-3.1.12/ps/parser.c +10 -15
diff -ruN orig/procps-3.1.12/ps/parser.c procps-3.1.12/ps/parser.c
@@ -314,8 +314,18 @@
       display_version();
       exit(0);
     case 'Z':     /* full Mandatory Access Control level info */
+#ifdef WITH_SELINUX
+      if (is_selinux_enabled()) {
+	trace("-Z shows full MAC info\n");
+	format_flags |= FF_Fc;
+      } else {
+	fprintf(stderr,
+		"Warning: -Z ignored. Requires a SELinux enabled kernel\n");
+      }
+#else
       trace("-Z shows full MAC info\n");
       return "Don't understand MAC on Linux.";
+#endif
       break;
     case 'a':
       trace("-a select all with a tty, but omit session leaders.\n");
@@ -727,7 +737,6 @@
   gnu_table_struct *found;
   static const gnu_table_struct gnu_table[] = {
   {"Group",         &&case_Group},       /* rgid */
-  {"SID",           &&case_secsid},
   {"User",          &&case_User},        /* ruid */
   {"cols",          &&case_cols},
   {"columns",       &&case_columns},
@@ -755,8 +764,6 @@
   {"pid",           &&case_pid},
   {"ppid",          &&case_ppid},
   {"rows",          &&case_rows},
-  {"secsid",        &&case_secsid},
-  {"sid",           &&case_sid},
   {"sort",          &&case_sort},
   {"tty",           &&case_tty},
   {"user",          &&case_user},        /* euid */
@@ -904,14 +911,6 @@
       }
     }
     return "Number of rows must follow --rows or --lines.";
-  case_sid:
-    trace("--sid\n");
-    arg = grab_gnu_arg();
-    if(!arg) return "Some sid thing(s) must follow --sid.";
-    err=parse_list(arg, parse_pid);
-    if(err) return err;
-    selection_list->typecode = SEL_SESS;
-    return NULL;
   case_sort:
     trace("--sort\n");
     arg=grab_gnu_arg();
@@ -944,10 +943,6 @@
     trace("--context\n");
     format_flags |= FF_Fc;
     return NULL;
-  case_secsid:
-     trace("--secsid\n");
-     format_flags |= FF_Fs;
-     return NULL;
 }
 
 /*************** process trailing PIDs  **********************/
ps/ps.1 renamed from procps-3.1.12/ps/ps.1 +1 -4
diff -ruN orig/procps-3.1.12/ps/ps.1 procps-3.1.12/ps/ps.1
@@ -106,8 +106,7 @@
 u            display user-oriented format
 v            display virtual memory format
 --format     user-defined format
---context    (SELinux only) Display security context format; implies --secsid
---secsid     (SELinux only) Display Security ID
+--context    (SELinux only) Display security context format;
 .TE
 .SH "OUTPUT MODIFIERS"
 .TS
@@ -432,14 +431,12 @@
 ruid         RUID    
 ruser        RUSER   
 s            S       
-secsid       SECSID
 sess         SESS    
 session      SESS    
 sgi_p        P       
 sgi_rss      RSS     
 sgid         SGID    
 sgroup       SGROUP  
-sid          SID     
 sig          PENDING 
 sig_block    BLOCKED 
 sig_catch    CATCHED 
ps/sortformat.c renamed from procps-3.1.12/ps/sortformat.c +0 -1
diff -ruN orig/procps-3.1.12/ps/sortformat.c procps-3.1.12/ps/sortformat.c
@@ -832,7 +832,6 @@
 
     /* These are FLASK security options. */
     case FF_Fc:          spec="FLASK_context"; break;
-    case FF_Fs:          spec="FLASK_sid";     break;
 
     }  /* end switch(format_flags) */
 
#1 lore raw
Quoted 9 lines · Russell Coker

Procps includes SE Linux support upstream, but it's a bit outdated.

I have attached a patch to remove support for displaying SIDs. It is a bit rough and has a memory leak (allocates textual representations of contexts but never frees them - may be a problem for "top").

I wrote this because I couldn't figure out how to get a straight patch for the new SE Linux, so I updated the old SE Linux code to be more like the new SE Linux code as an intermediate step.

My impression was that Albert Cahalan was going to directly implement support for displaying the /proc/pid/attr/* values since /proc/pid/attr is now part of the mainline kernel API. At which point you don't really need a SELinux-specific patch at all.

Signature · 8 lines
Stephen Smalley <[email protected]>
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.
#2 lore raw
Quoted 7 lines · Stephen Smalley
Quoted 6 lines · Russell Coker

Procps includes SE Linux support upstream, but it's a bit outdated.

I have attached a patch to remove support for displaying SIDs. It is a bit rough and has a memory leak (allocates textual representations of contexts but never frees them - may be a problem for "top").

Quoted 8 lines
Quoted 3 lines

I wrote this because I couldn't figure out how to get a straight patch for the new SE Linux, so I updated the old SE Linux code to be more like the new SE Linux code as an intermediate step.

My impression was that Albert Cahalan was going to directly implement support for displaying the /proc/pid/attr/* values since /proc/pid/attr is now part of the mainline kernel API. At which point you don't really need a SELinux-specific patch at all.

Yes. However I don't think that Albert was planning to write it himself...

procps currently has support upstream for the old SE Linux, and I don't expect things to change until/unless we submit appropriate patches.

In my tree I have implemented quite a bit of the new SE Linux API for old SE Linux. For example I have the runcon and chcon programs from the new SE Linux running on the old SE Linux. It won't be much extra work to get it to the stage of having a procps patch for the new SE Linux which compiles for old SE Linux too.

Signature · 10 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page


--
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.
#3 lore raw
Quoted 1 line · Russell Coker

Yes. However I don't think that Albert was planning to write it himself...

You might want to check with him, as that was my impression. He seemed to favor the idea of directly implementing support for /proc/pid/attr and avoiding any SELinux-specific patch or any dependency on libselinux. In any event, it doesn't matter to us, as that isn't the upstream procps for RH last I checked.

Quoted 2 lines

procps currently has support upstream for the old SE Linux, and I don't expect things to change until/unless we submit appropriate patches.

procps 3.x ChangeLog says that support for SELinux has been dropped due to the new kernel interface.

Quoted 5 lines

In my tree I have implemented quite a bit of the new SE Linux API for old SE Linux. For example I have the runcon and chcon programs from the new SE Linux running on the old SE Linux. It won't be much extra work to get it to the stage of having a procps patch for the new SE Linux which compiles for old SE Linux too.

This isn't a priority to us; supporting old SELinux is not our concern.

Signature · 8 lines
Stephen Smalley <[email protected]>
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.