SELinux musl support
This series fixes compiling and running on musl libc.
patches 1-2 are fairly trivial.
patches 3-4 are a feature change on that platform since it does not support GLOB_TILDE and GLOB_BRACE. tilde is coming in musl 1.1.21 according to [1]. brace support is not documented anywhere or in the example configs so that is probably not a big problem.
patch 5 fixes a bug and it just happens that glibc returns a value for sysconf and the error handling was wrong but never noticed.
[1]: https://wiki.musl-libc.org/roadmap.html
[PATCH 1/5] sestatus: include limits.h for PATH_MAX [PATCH 2/5] libselinux: enable linking to musl-fts [PATCH 3/5] setfiles: Musl compatibility for GLOB_BRACE and [PATCH 4/5] restorecond: Musl compatibility for GLOB_BRACE and [PATCH 5/5] genhomedircon: sysconf can return -1 without failure
PATCH 1/5 sestatus: include limits.h for PATH_MAX
compile fails on musl libc because it cant find PATH_MAX.
--- policycoreutils/sestatus/sestatus.c | 1 + 1 file changed, 1 insertion(+)
policycoreutils/sestatus/sestatus.c +1 -0
@@ -17,6 +17,7 @@#include <unistd.h> #include <libgen.h> #include <ctype.h> +#include <limits.h> #define PROC_BASE "/proc"#define MAX_CHECK 50
Signature · 1 line
2.16.1
PATCH 2/5 libselinux: enable linking to musl-fts
In reply to Jason ZamanMusl libc does not include the fts(3) functions so need to link to the musl-fts library
https://github.com/pullmoll/musl-fts
--- libselinux/src/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
libselinux/src/Makefile +3 -1
@@ -98,6 +98,8 @@ LD_SONAME_FLAGS=-install_name,$(LIBSO) endif PCRE_LDLIBS ?= -lpcre +# override with -lfts when building on Musl libc to use fts-standalone +FTS_LDLIBS ?= override CFLAGS += -I../include -D_GNU_SOURCE $(DISABLE_FLAGS) $(PCRE_CFLAGS)
@@ -149,7 +151,7 @@ $(LIBA): $(OBJS) $(RANLIB) $@ $(LIBSO): $(LOBJS) - $(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ $(PCRE_LDLIBS) -ldl -Wl,$(LD_SONAME_FLAGS) + $(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ $(PCRE_LDLIBS) $(FTS_LDLIBS) -ldl -Wl,$(LD_SONAME_FLAGS) ln -sf $@ $(TARGET) $(LIBPC): $(LIBPC).in ../VERSION
Signature · 1 line
2.16.1
PATCH 3/5 setfiles: Musl compatibility for GLOB_BRACE and GLOB_TILDE
In reply to Jason ZamanFrom: Luis Ressel <[email protected]>
musl doesn't implement GLOB_BRACE and GLOB_TILDE, so simply don't use them there. This only affects "setfiles -f", which I don't expect many people use, and it's undocumented anyway that it expands globs.
--- policycoreutils/setfiles/restore.c | 8 ++++++++ 1 file changed, 8 insertions(+)
policycoreutils/setfiles/restore.c +8 -0
@@ -6,6 +6,14 @@#include "restore.h" #include <glob.h> +#ifndef GLOB_BRACE +#define GLOB_BRACE 0 +#endif + +#ifndef GLOB_TILDE +#define GLOB_TILDE 0 +#endif +char **exclude_list;int exclude_count;
Signature · 1 line
2.16.1
PATCH 4/5 restorecond: Musl compatibility for GLOB_BRACE and GLOB_TILDE
In reply to Jason Zamanmusl doesn't implement GLOB_BRACE and GLOB_TILDE, so simply don't use them there. This affects restorecond -u but braces are not used in the example configs. GLOB_TILDE is on the roadmap[1] for musl 1.1.21 so restorecond -u should be fine soon.
[1]: https://wiki.musl-libc.org/roadmap.html
--- restorecond/restore.c | 13 ++++++++----- restorecond/watch.c | 8 ++++++++ 2 files changed, 16 insertions(+), 5 deletions(-)
restorecond/restore.c +8 -5
@@ -1,11 +1,14 @@ -/* -* Note that the restorecond(8) service build links with these functions. -* Therefore any changes here should also be tested against that utility. -*/ -#include "restore.h" #include <glob.h> +#ifndef GLOB_TILDE +#define GLOB_TILDE 0 +#endif + +#ifndef GLOB_BRACE +#define GLOB_BRACE 0 +#endif +char **exclude_list;int exclude_count;
restorecond/watch.c +8 -0
@@ -20,6 +20,14 @@#include "stringslist.h" #include "utmpwatcher.h" +#ifndef GLOB_TILDE +#define GLOB_TILDE 0 +#endif + +#ifndef GLOB_BRACE +#define GLOB_BRACE 0 +#endif +/* size of the event structure, not counting name */ #define EVENT_SIZE (sizeof (struct inotify_event))/* reasonable guess as to size of 1024 events */
Signature · 1 line
2.16.1
PATCH 5/5 genhomedircon: sysconf can return -1 without failure
In reply to Jason Zamanfrom getpwnam_r(3): "The call sysconf(_SC_GETPW_R_SIZE_MAX) returns either -1, without changing errno, or an initial suggested size for buf. (If this size is too small, the call fails with ERANGE, in which case the caller can retry with a larger buffer.)"
The same can happen for _SC_GETGR_R_SIZE_MAX. 1024 appears to be a good fallback but may need revisiting in the future.
This triggered an error on musl libc but could happen other places too.
--- libsemanage/src/genhomedircon.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
libsemanage/src/genhomedircon.c +10 -2
@@ -972,9 +972,13 @@ static int add_user(genhomedircon_settings_t * s,char uid[11 ];char gid[11 ]; + errno =0 ;/* Allocate space for the getpwnam_r buffer */ rbuflen =sysconf (_SC_GETPW_R_SIZE_MAX); -if (rbuflen <=0 ) +if (rbuflen ==-1 && errno ==0 ) +/* sysconf returning -1 with no errno means indeterminate size */ + rbuflen =1024 ; +else if (rbuflen <=0 ) goto cleanup; rbuf =malloc (rbuflen);if (rbuf ==NULL )
@@ -1057,8 +1061,12 @@ static int get_group_users(genhomedircon_settings_t * s,struct group grstorage, *group =NULL ;struct passwd *pw =NULL ; + errno =0 ; grbuflen =sysconf (_SC_GETGR_R_SIZE_MAX); -if (grbuflen <=0 ) +if (grbuflen ==-1 && errno ==0 ) +/* sysconf returning -1 with no errno means indeterminate size */ + grbuflen =1024 ; +else if (grbuflen <=0 ) goto cleanup; grbuf =malloc (grbuflen);if (grbuf ==NULL )
Signature · 1 line
2.16.1
Quoted 12 lines · Jason Zaman
This series fixes compiling and running on musl libc.
patches 1-2 are fairly trivial.
patches 3-4 are a feature change on that platform since it does not support
GLOB_TILDEandGLOB_BRACE. tilde is coming in musl 1.1.21 according to [1]. brace support is not documented anywhere or in the example configs so that is probably not a big problem.patch 5 fixes a bug and it just happens that glibc returns a value for sysconf and the error handling was wrong but never noticed.
Quoted 7 lines
[1]: https://wiki.musl-libc.org/roadmap.html
[PATCH 1/5] sestatus: include
limits.hforPATH_MAX[PATCH 2/5] libselinux: enable linking to musl-fts [PATCH 3/5] setfiles: Musl compatibility forGLOB_BRACEand [PATCH 4/5] restorecond: Musl compatibility forGLOB_BRACEand [PATCH 5/5] genhomedircon: sysconf can return -1 without failure
Thanks! These patches look good to me and I would also appreciate if they are merged in 2.8.
Nicolas
Quoted 15 lines · Nicolas Iooss
Quoted 14 lines · Jason Zaman
This series fixes compiling and running on musl libc.
patches 1-2 are fairly trivial.
patches 3-4 are a feature change on that platform since it does not support
GLOB_TILDEandGLOB_BRACE. tilde is coming in musl 1.1.21 according to [1]. brace support is not documented anywhere or in the example configs so that is probably not a big problem.patch 5 fixes a bug and it just happens that glibc returns a value for sysconf and the error handling was wrong but never noticed.
Quoted 8 lines
Quoted 5 lines
[PATCH 1/5] sestatus: include
limits.hforPATH_MAX[PATCH 2/5] libselinux: enable linking to musl-fts [PATCH 3/5] setfiles: Musl compatibility forGLOB_BRACEand [PATCH 4/5] restorecond: Musl compatibility forGLOB_BRACEand [PATCH 5/5] genhomedircon: sysconf can return -1 without failureThanks! These patches look good to me and I would also appreciate if they are merged in 2.8.
Awesome, I'll push them on monday then unless there are any issues before then :)
Quoted 3 lines
Nicolas
Quoted 22 lines · Jason Zaman
Quoted 21 lines · Nicolas Iooss
Quoted 19 lines · Jason Zaman
This series fixes compiling and running on musl libc.
patches 1-2 are fairly trivial.
patches 3-4 are a feature change on that platform since it does not support
GLOB_TILDEandGLOB_BRACE. tilde is coming in musl 1.1.21 according to [1]. brace support is not documented anywhere or in the example configs so that is probably not a big problem.patch 5 fixes a bug and it just happens that glibc returns a value for sysconf and the error handling was wrong but never noticed.
[1]: https://wiki.musl-libc.org/roadmap.html
[PATCH 1/5] sestatus: include
limits.hforPATH_MAX[PATCH 2/5] libselinux: enable linking to musl-fts [PATCH 3/5] setfiles: Musl compatibility forGLOB_BRACEand [PATCH 4/5] restorecond: Musl compatibility forGLOB_BRACEand [PATCH 5/5] genhomedircon: sysconf can return -1 without failure
Quoted 5 lines
Quoted 2 lines
Thanks! These patches look good to me and I would also appreciate if they are merged in 2.8.
Awesome, I'll push them on monday then unless there are any issues before then :)
FWIW, the patches look fine to me as well and I did a test PR to trigger travis CI testing and they passed,
https://github.com/SELinuxProject/selinux/pull/96
One possible area for improvement (but not necessary to merge this) would be to fix the genhomedircon code to also then handle the case where getpwnam_r/getgrnam_r returns ERANGE, in which case we are supposed to realloc a larger buffer and try again per the man page.
Quoted 29 lines · Stephen Smalley
Quoted 22 lines · Jason Zaman
Quoted 21 lines · Nicolas Iooss
Quoted 19 lines · Jason Zaman
This series fixes compiling and running on musl libc.
patches 1-2 are fairly trivial.
patches 3-4 are a feature change on that platform since it does not support
GLOB_TILDEandGLOB_BRACE. tilde is coming in musl 1.1.21 according to [1]. brace support is not documented anywhere or in the example configs so that is probably not a big problem.patch 5 fixes a bug and it just happens that glibc returns a value for sysconf and the error handling was wrong but never noticed.
[1]: https://wiki.musl-libc.org/roadmap.html
[PATCH 1/5] sestatus: include
limits.hforPATH_MAX[PATCH 2/5] libselinux: enable linking to musl-fts [PATCH 3/5] setfiles: Musl compatibility forGLOB_BRACEand [PATCH 4/5] restorecond: Musl compatibility forGLOB_BRACEand [PATCH 5/5] genhomedircon: sysconf can return -1 without failureQuoted 5 lines
Quoted 2 lines
Thanks! These patches look good to me and I would also appreciate if they are merged in 2.8.
Awesome, I'll push them on monday then unless there are any issues before then :)
Quoted 7 lines
FWIW, the patches look fine to me as well and I did a test PR to trigger travis CI testing and they passed,
https://github.com/SELinuxProject/selinux/pull/96One possible area for improvement (but not necessary to merge this) would be to fix the genhomedircon code to also then handle the case where getpwnam_r/getgrnam_r returns ERANGE, in which case we are supposed to realloc a larger buffer and try again per the man page.
Yeah i thought about that, but you're supposed to do that even when sysconf does return a number and we've apparently never hit this before. and the example code in the man pages doesnt really do it either. so as small changes as possible before release is better. after release we could think about it but probably still not really high importance.
-- Jason
Quoted 38 lines · Jason Zaman
Quoted 29 lines · Stephen Smalley
Quoted 22 lines · Jason Zaman
Quoted 21 lines · Nicolas Iooss
Quoted 19 lines · Jason Zaman
This series fixes compiling and running on musl libc.
patches 1-2 are fairly trivial.
patches 3-4 are a feature change on that platform since it does not support
GLOB_TILDEandGLOB_BRACE. tilde is coming in musl 1.1.21 according to [1]. brace support is not documented anywhere or in the example configs so that is probably not a big problem.patch 5 fixes a bug and it just happens that glibc returns a value for sysconf and the error handling was wrong but never noticed.
[1]: https://wiki.musl-libc.org/roadmap.html
[PATCH 1/5] sestatus: include
limits.hforPATH_MAX[PATCH 2/5] libselinux: enable linking to musl-fts [PATCH 3/5] setfiles: Musl compatibility forGLOB_BRACEand [PATCH 4/5] restorecond: Musl compatibility forGLOB_BRACEand [PATCH 5/5] genhomedircon: sysconf can return -1 without failureQuoted 5 lines
Quoted 2 lines
Thanks! These patches look good to me and I would also appreciate if they are merged in 2.8.
Awesome, I'll push them on monday then unless there are any issues before then :)
Quoted 7 lines
FWIW, the patches look fine to me as well and I did a test PR to trigger travis CI testing and they passed,
https://github.com/SELinuxProject/selinux/pull/96One possible area for improvement (but not necessary to merge this) would be to fix the genhomedircon code to also then handle the case where getpwnam_r/getgrnam_r returns ERANGE, in which case we are supposed to realloc a larger buffer and try again per the man page.
Quoted 5 lines
Yeah i thought about that, but you're supposed to do that even when sysconf does return a number and we've apparently never hit this before. and the example code in the man pages doesnt really do it either. so as small changes as possible before release is better. after release we could think about it but probably still not really high importance.
This is all pushed to master now, travis-ci passes on master too.
-- Jason