port of procps patch to acahalan procps
Subsystems (2)
Hi,
I've ported the SELinux 2.5 procps patch to the acahalan procps; this may be useful for other systems like Debian which also use acalahan's procps (I think Gentoo does).
It's been lightly tested.
Albert: this is an update to the new SELinux API for Linux 2.5; the old API is deprecated now, and will likely be obsoleted once the new API is backported to Linux 2.4.
Makefile +3 -3
@@ -63,9 +63,9 @@ CURSES := -I/usr/include/ncurses -lncurses -LDFLAGS := -Wl,-warn-common +LDFLAGS := -Wl,-warn-common -lselinux -lattr -CFLAGS := -D_GNU_SOURCE -O2 -g3 -fno-common -ffast-math -I proc \ +CFLAGS := -D_GNU_SOURCE -DWITH_SELINUX -g -fno-common -ffast-math -I proc \ -W -Wall -Wshadow -Wcast-align -Wredundant-decls \ -Wbad-function-cast -Wcast-qual -Wwrite-strings -Waggregate-return \ # -Wpadded -Wunreachable-code -Wdisabled-optimization \
@@ -128,7 +128,7 @@ ###### install $(BINFILES) : all - $(install) --mode a=rx --strip $(notdir $@) $@ + $(install) --mode a=rx $(notdir $@) $@ $(MANFILES) : all $(install) --mode a=r $(notdir $@) $@
proc/readproc.c +56 -23
154 lines not on this page · raw message
proc/readproc.h +9 -6
@@ -14,8 +14,8 @@#define SIGNAL_STRING -#ifdef FLASK_LINUX -#include <fs_secure.h> +#ifdef WITH_SELINUX +#include <selinux/selinux.h> #endif EXTERN_C_BEGIN
@@ -136,8 +136,8 @@ tgid,/* thread group ID */ exit_signal,/* might not be SIGCHLD */ processor;/* current (or most recent?) CPU */ -#ifdef FLASK_LINUX -security_id_t secsid; +#ifdef WITH_SELINUX +security_context_t scontext;#endif } proc_t;
@@ -154,8 +154,8 @@pid_t * pids;/* pids of the procs */ 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 */ +#ifdef WITH_SELINUX +security_context_t * scontexts;/* security contexts of the procs */ #endif }PROCTAB ;
@@ -218,6 +218,9 @@/* Obsolete, consider only processes with one of the passed: */ #define PROC_PID 0x1000/* process id numbers ( 0 terminated) */ #define PROC_UID 0x4000/* user id numbers ( length needed ) */ +#ifdef WITH_SELINUX +#define PROC_CONTEXT 0x8000 +#endif // it helps to give app code a few spare bits #define PROC_SPARE_1 0x01000000
ps/display.c +1 -1
@@ -246,7 +246,7 @@fprintf (stderr,"Error: can not access /proc.\n" );exit (1 ); } -memset (&buf,'#' ,sizeof (proc_t)); +memset (&buf,0 ,sizeof (proc_t));while (ps_readproc (ptp,&buf)){if (want_this_proc (&buf))show_one_proc (&buf);if (buf.cmdline)free ((void *)*buf.cmdline);// ought to reuse
ps/help.c +2 -2
@@ -35,8 +35,8 @@ "-O,O preloaded -o v virtual memory --cumulative --format --deselect\n" "-l,l long u user-oriented --sort --tty --forest --version\n" "-F extra full X registers --heading --no-heading\n" -#ifdef FLASK_LINUX -" --context --SID (Flask only)\n" +#ifdef WITH_SELINUX +" --context (SELinux only)\n" #endif" ********* misc options *********\n" "-V,V show version L list format codes f ASCII art forest\n"
ps/output.c +18 -119
192 lines not on this page · raw message
ps/parser.c +7 -8
@@ -727,7 +727,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,7 +754,6 @@ {"pid", &&case_pid}, {"ppid", &&case_ppid}, {"rows", &&case_rows}, - {"secsid", &&case_secsid}, {"sid", &&case_sid}, {"sort", &&case_sort}, {"tty", &&case_tty},
@@ -941,13 +939,14 @@exit (0 );return NULL ; case_context: -trace ("--context\n" ); - format_flags |= FF_Fc; +if (is_selinux_enabled ()) { +trace ("--context\n" ); + format_flags |= FF_Fc; + }else { +fprintf (stderr, +"Warning: --context ignored. Requires a SELinux enabled kernel\n" ); + }return NULL ; - case_secsid: -trace ("--secsid\n" ); - format_flags |= FF_Fs; -return NULL ; }/*************** process trailing PIDs **********************/
ps/sortformat.c +2 -3
@@ -803,9 +803,8 @@case FF_LX : spec="OL_X" ;break ;case FF_Lm: spec="OL_m" ;break ; -/* These are FLASK security options. */ -case FF_Fc: spec="FLASK_context" ;break ; -case FF_Fs: spec="FLASK_sid" ;break ; +/* These are SELinux security options. */ +case FF_Fc: spec="SELINUX_context" ;break ; }/* end switch(format_flags) */
ps/common.h +0 -1
@@ -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 */
A message that is not in the archive (sent off-list or not yet received): 1057805552.751.1243.camel@cube
Quoted 1 line · Albert Cahalan
OK. I'll get most of that into the 3.1.10 release.
Cool. Note however that it won't currently run on 2.4 SELinux, so you should probably warn your users about this.
Quoted 6 lines
I need to know more about a security context. I need to know how big it is today (variable?) and how, if at all, you intend to keep the size from ever changing. I'm working toward a stable ABI for procps, meaning that compile-time choices can't make the library incompatible with the apps.
It's basically just a char *, and I don't think that will ever change.
Quoted 6 lines
proc/readproc.c +3
-0+#ifdef WITH_SELINUX +int selinux_enabled =is_selinux_enabled (); +#endif Is that going to be slow? You're making this call for every process.
It shouldn't be too slow, no; basically it is implemented by reading /proc/self/attr/current and seeing if it works. But it would be a good idea to factor the code out into an initialization section.
Quoted 9 lines
proc/readproc.c +3
-1-if (!p) +if (!p) { p =xcalloc (p,sizeof *p);/* passed buf or alloced mem */ +memset (p,0 ,sizeof (p)); + }Why? I notice elsewhere that you seem to expect
readproc()to get called with a security context already allocated. Hmmm...
The reason I did this was because the patch for the other procps does:
if (p->scontext) {
freecon(p->scontext);
p->scontext=NULL;
}But this might be something that was only needed for the other procps. It does look like when readproc is called, the proc_t * is always freshly allocated, and is later freed with freeproc, which will correctly free the context. So you could probably just delete both the freecon code and the memset code in readproc.
Quoted 5 lines
proc/readproc.h +3
-0+#ifdef WITH_SELINUX +#define PROC_CONTEXT 0x8000 +#endif no need to #ifdef that
Ok.
Quoted 6 lines
ps/display.c +1
-1-memset (&buf,'#' ,sizeof (proc_t)); +memset (&buf,0 ,sizeof (proc_t));This is debug code. It's used to help catch uninitialized memory. (did it catch you?)
Yes, because of the above code that checked whether p->scontext was nonzero, and freed it if not.
This is unrelated to the SELinux patch, but: I personally find valgrind to be a far more effective way to debug memory allocation errors. Also, I think it would be better to memset it to 0 in released code, but have a debugging mode which uses '#'. This is a kind of defensive programming; if a bug could be avoided by memsetting a buffer to 0, then it's not really even a bug in the first place in my opinion. You don't want procps to segfault on the user's computer just because they hit a strange codepath.
--
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.