New patch for libselinux
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]
Patch to libselinux to fix handling of MATCHPATHCON_NOTRANS.
Also added two new functions to handle looking at files on disk and comparing to the default file_contexts, These functions are intended to be used by rpm -V.
include/selinux/selinux.h +9 -0
@@ -429,8 +429,17 @@Caller must free the returned strings via free. */ extern int getseuserbyname (const char *linuxuser,char **seuser,char **level); +/* This function allows you to compare two security context and ignore the +user component */ +int selinux_compare_context_without_user (const security_context_t a,const security_context_t b); + +/* This function looks at the file context on disk and compares it to the +system defaults, it returns 1 on match non 0 on failure */ +int selinux_verify_file_context (const char *path,mode_t mode); +#ifdef __cplusplus }#endif #endif +
man/man8/matchpathcon.8 +15 -3
@@ -3,13 +3,25 @@ matchpathcon \- get the default security context for the specified path from the file contexts configuration. .SH "SYNOPSIS" -.B matchpathcon [-n] filepath... - +.B matchpathcon [-V] [-N] [-n] [-f file_contexts_file ] [-p prefix ] filepath... .SH "DESCRIPTION" .B matchpathcon Prints the file path and the default security context associated with it. +.SH OPTIONS +.B \-n +Do not display path. +.br +.B \-N +Do not use translations. +.br +.B \-f file_context_file +Use alternate file_context file +.br +.B \-p prefix +Use prefix to speed translations .br -If the -n option is given, do not display path. +.B \-V +Verify file context on disk matches defaults .SH AUTHOR This manual page was written by Dan Walsh <[email protected]>.
src/matchpathcon.c +52 -5
90 lines not on this page · raw message
utils/matchpathcon.c +49 -13
85 lines not on this page · raw message
Quoted 5 lines · Daniel J Walsh
Patch to libselinux to fix handling of
MATCHPATHCON_NOTRANS.Also added two new functions to handle looking at files on disk and comparing to the default
file_contexts, These functions are intended to be used by rpm -V.
I don't think we want to directly export selinux_compare_context_without_user(), or if we do, we want it abstracted in some manner that covers the general case.
Also, I think selinux_verify_file_context needs to be generalized, because if/when rpm begins to use contexts from the rpm headers again, then rpm will need to pass in the context against which to compare rather than having selinux_verify_file_context always use matchpathcon.
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.
Quoted 4 lines · Stephen Smalley
Quoted 2 lines · Daniel J Walsh
Patch to libselinux to fix handling of
MATCHPATHCON_NOTRANS.
Quoted 9 lines
Quoted 3 lines
Also added two new functions to handle looking at files on disk and comparing to the default
file_contexts, These functions are intended to be used by rpm -V.I don't think we want to directly export
selinux_compare_context_without_user(), or if we do, we want it abstracted in some manner that covers the general case.
We are using similar functions in restorecon and I think somewhere else, so I thought it would be good to move it into libselinux.
Quoted 6 lines
Also, I think
selinux_verify_file_contextneeds to be generalized, because if/when rpm begins to use contexts from the rpm headers again, then rpm will need to pass in the context against which to compare rather than havingselinux_verify_file_contextalways use matchpathcon.
Not sure what you mean, You still have the other functions to use. The idea with this
function is to compare a files on disk context with the system defaults. You could also use matchpathcon_init before calling this function to change the default file context file?
I also want to define a function
selinux_setdefault_filecon(file)
Which would do matchpathcon/setfilecon under the covers, and do the appropriate turn off translations stuff. Since this code is propulgating into a series of programs. (install, MAKEDEV, kadmin?, and Nautilus, restorecon and probably others.)
--
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.
Quoted 9 lines · Daniel J Walsh
Quoted 5 lines · Stephen Smalley
I don't think we want to directly export
selinux_compare_context_without_user(), or if we do, we want it abstracted in some manner that covers the general case.We are using similar functions in restorecon and I think somewhere else, so I thought
it would be good to move it into libselinux.
Possibly, but _without_user is too much detail for the caller. Caller just wants some function that indicates equivalence (for some definition of equivalence).
Quoted 6 lines
Not sure what you mean, You still have the other functions to use. The
idea with this
function is to compare a files on disk context with the system defaults. You could also usematchpathcon_initbefore calling this function to change the default file context file?
Actually, I suppose at the point of verification, you already have the module policy installed and integrated into the system file_contexts file, so matchpathcon() should work. I was thinking that rpm would have to pass in the context originally obtained from the package header (and saved in the rpm database?) instead. But that should always match the result yielded from matchpathcon once the module's .fc has been merged.
Quoted 8 lines
I also want to define a function
selinux_setdefault_filecon(file)Which would do matchpathcon/setfilecon under the covers, and do the appropriate turn off translations stuff.
Since this code is propulgating into a series of programs. (install, MAKEDEV, kadmin?, and Nautilus, restorecon and probably others.)
selinux_lsetfilecon_default(const char *path)?
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.
Quoted 22 lines · Stephen Smalley
Quoted 9 lines · Daniel J Walsh
Quoted 5 lines · Stephen Smalley
I don't think we want to directly export
selinux_compare_context_without_user(), or if we do, we want it abstracted in some manner that covers the general case.We are using similar functions in restorecon and I think somewhere else, so I thought
it would be good to move it into libselinux.Possibly, but
_without_useris too much detail for the caller. Caller just wants some function that indicates equivalence (for some definition of equivalence).Quoted 6 lines
Not sure what you mean, You still have the other functions to use. The
idea with this
function is to compare a files on disk context with the system defaults. You could also usematchpathcon_initbefore calling this function to change the default file context file?
Quoted 6 lines
Actually, I suppose at the point of verification, you already have the module policy installed and integrated into the system
file_contextsfile, somatchpathcon()should work. I was thinking that rpm would have to pass in the context originally obtained from the package header (and saved in the rpm database?) instead. But that should always match the result yielded from matchpathcon once the module's .fc has been merged.
This btw raises the question of whether rpm -V should check contexts at all, or whether that support should drop out of rpm altogether, and context verification handled entirely via setfiles/restorecon and friends. If rpm isn't using any internal data there and we are always checking filesystem state vs. policy state, then why have rpm handle it?
Quoted 12 lines
Quoted 9 lines
I also want to define a function
selinux_setdefault_filecon(file)Which would do matchpathcon/setfilecon under the covers, and do the appropriate turn off translations stuff.
Since this code is propulgating into a series of programs. (install, MAKEDEV, kadmin?, and Nautilus, restorecon and probably others.)
selinux_lsetfilecon_default(const char *path)?
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.
I have redone the original patch for libselinux
Now have a function called selinux_context_cmp which will compare two context ignoring the user componant for equivalency.
Fixed selinux_verify_file_context to work properly, default_canoncon now checks myflags for MATCHPATHCON_NOTRANS
Added selinux_lsetfilecon_default(const char* path)
to set a file context to match the entry in file_contexts file. Changing install command to use this function improved perfomance
# time install resolv.conf /etc/
real 0m0.251s user 0m0.176s sys 0m0.040s # ls -lZ /etc/resolv.conf -rwxr-xr-x root root system_u:object_r:net_conf_t /etc/resolv.conf # time ./ginstall resolv.conf /etc/
real 0m0.007s user 0m0.000s sys 0m0.008s # ls -lZ /etc/resolv.conf -rwxr-xr-x root root system_u:object_r:net_conf_t /etc/resolv.conf
include/selinux/selinux.h +12 -0
@@ -429,8 +429,20 @@Caller must free the returned strings via free. */ extern int getseuserbyname (const char *linuxuser,char **seuser,char **level); +/* This function allows you to compare two security context, it will ignore the +user component */ +int selinux_context_cmp (const security_context_t a,const security_context_t b); + +/* This function looks at the file context on disk and compares it to the +system defaults, it returns 1 on match non 0 on failure */ +int selinux_verify_file_context (const char *path,mode_t mode); + +/* This function sets the file context on to the system defaults returns 0 on success */ +int selinux_lsetfilecon_default (const char *path); +#ifdef __cplusplus }#endif #endif +
man/man8/matchpathcon.8 +15 -3
@@ -3,13 +3,25 @@ matchpathcon \- get the default security context for the specified path from the file contexts configuration. .SH "SYNOPSIS" -.B matchpathcon [-n] filepath... - +.B matchpathcon [-V] [-N] [-n] [-f file_contexts_file ] [-p prefix ] filepath... .SH "DESCRIPTION" .B matchpathcon Prints the file path and the default security context associated with it. +.SH OPTIONS +.B \-n +Do not display path. +.br +.B \-N +Do not use translations. +.br +.B \-f file_context_file +Use alternate file_context file +.br +.B \-p prefix +Use prefix to speed translations .br -If the -n option is given, do not display path. +.B \-V +Verify file context on disk matches defaults .SH AUTHOR This manual page was written by Dan Walsh <[email protected]>.
src/matchpathcon.c +78 -5
116 lines not on this page · raw message
utils/matchpathcon.c +49 -13
85 lines not on this page · raw message
Re: I have redone the original patch for libselinux
include/selinux/selinux.h line 434
Quoted 10 lines · Daniel J Walsh
diff --exclude-from=exclude -N -u -r
nsalibselinux/include/selinux/selinux.hlibselinux-1.30.15/include/selinux/selinux.hinclude/selinux/selinux.h +3
-0@@ -429,8 +429,20 @@Caller must free the returned strings via free. */ extern int getseuserbyname (const char *linuxuser,char **seuser,char **level); +/* This function allows you to compare two security context, it will ignore the +user component */ +int selinux_context_cmp (const security_context_t a,const security_context_t b);
I think I'd make this:
/* Compare two file security contexts. Return 0 if equivalent. */ int selinux_file_context_cmp(const char *s1, const char *s2);
Rationale: User identity does matter in process security contexts, so we don't want people to use such a function on arbitrary contexts. We also don't want the user-specific aspect in the interface at all, even in the comment; the caller just wants to know if the two file contexts should be treated as equivalent.
include/selinux/selinux.h line 438
Quoted 3 lines
include/selinux/selinux.h +3
-0+/* This function looks at the file context on disk and compares it to the +system defaults, it returns 1 on match non 0 on failure */ +int selinux_verify_file_context (const char *path,mode_t mode);
Should that be return 0 on match?
include/selinux/selinux.h line 447
Quoted 10 lines
include/selinux/selinux.h +10
-0+int selinux_verify_file_context (const char *path,mode_t mode) +{ +security_context_t con =NULL ; +security_context_t fcontext =NULL ; +int rc=0 ; + +if (myflags &MATCHPATHCON_NOTRANS ) + rc =lgetfilecon_raw (path, &con); +else + rc =lgetfilecon (path, &con);
Why not just set MATCHPATHCON_NOTRANS as you do in selinux_lsetfilecon_default, and then always use lgetfilecon_raw here? Then the caller doesn't need to set it himself, and you always avoid extraneous translations in this function.
include/selinux/selinux.h
Quoted 6 lines
include/selinux/selinux.h +6
-0+if (matchpathcon (path,mode,&fcontext) !=0 ) { +if (fcontext ==NULL && errno !=ENOENT ) + rc =1 ; +else + rc =0 ; + }
fcontext == NULL test seems unnecessary; matchpathcon failed, so there should be no result.
Quoted 5 lines
include/selinux/selinux.h +5
-0+int selinux_lsetfilecon_default (const char *path) { +struct stat st; +int rc =-1 ; +security_context_t scontext=NULL ; +unsigned int localflags=myflags;
include/selinux/selinux.h
Quoted 10 lines
include/selinux/selinux.h +10
-0+if (lstat (path, &st) !=0 ) +return rc; + +set_matchpathcon_flags (myflags |MATCHPATHCON_NOTRANS ); + +/* If there's an error determining the context, or it has none, +return to allow default context */ +if (matchpathcon (path, st.st_mode, &scontext)) { +if (scontext ==NULL && errno !=ENOENT ) + rc =0 ;
scontext == NULL test seems unnecessary. Shouldn't that be errno == ENOENT (i.e. if there was no matching entry in file_contexts, return success).
include/selinux/selinux.h
Quoted 7 lines
include/selinux/selinux.h +7
-0+ }else { + rc =lsetfilecon_raw (path, scontext); +freecon (scontext); + } +set_matchpathcon_flags (localflags); +return rc; +}
Likely should make myflags per-thread for safety in case we have any threaded callers.
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.