aboutsummaryrefslogtreecommitdiffstats
path: root/libselinux/src/audit2why.c
Commit message (Collapse)AuthorAgeFilesLines
* libselinux: add a const to suppress a build warning with Python 3.7Nicolas Iooss2018-08-191-1/+1
| | | | | | | | | | | | | | | On systems using Python 3.7, when compiling libselinux Python wrappers (with "make install-pywrap"), the following warning is reported by gcc: audit2why.c: In function ‘analyze’: audit2why.c:364:11: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] permstr = _PyUnicode_AsString( strObj ); ^ Make permstr "const char *" in order to suppress this warning. Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
* libselinux: audit2why: fix build warningsStephen Smalley2018-05-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix the following build warnings. audit2why.c: In function ‘__policy_init’: audit2why.c:207:22: warning: ‘%s’ directive output may be truncated writing up to 4095 bytes into a region of size 4081 [-Wformat-truncation=] "unable to open %s: %s\n", ^~ path, strerror(errno)); ~~~~ audit2why.c:206:4: note: ‘snprintf’ output 20 or more bytes (assuming 4115) into a destination of size 4096 snprintf(errormsg, sizeof(errormsg), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "unable to open %s: %s\n", ~~~~~~~~~~~~~~~~~~~~~~~~~~~ path, strerror(errno)); ~~~~~~~~~~~~~~~~~~~~~~ audit2why.c:253:28: warning: ‘%s’ directive output may be truncated writing up to 4095 bytes into a region of size 4074 [-Wformat-truncation=] "invalid binary policy %s\n", path); ^~ ~~~~ audit2why.c:252:3: note: ‘snprintf’ output between 24 and 4119 bytes into a destination of size 4096 snprintf(errormsg, sizeof(errormsg), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "invalid binary policy %s\n", path); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
* libselinux: add O_CLOEXECNick Kralevich2017-04-121-2/+2
| | | | | | | Makes libselinux safer and less likely to leak file descriptors when used as part of a multithreaded program. Signed-off-by: Nick Kralevich <nnk@google.com>
* libsepol,libselinux,audit2allow: teach audit2why about type bounds failuresStephen Smalley2016-11-291-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Teach audit2why to recognize type bounds failures. This required updating libsepol sepol_compute_av_reason() to identify bounds failures, and updating libsepol context_struct_compute_av() to include the type bounds logic from the kernel. This could potentially be further augmented to provide more detailed reporting via the reason buffer to include information similar to what security_dump_masked_av() reports in the kernel. However, it is unclear if this is needed. It is already possible to get type bounds checking at policy build time by enabling expand-check=1 in /etc/selinux/semanage.conf (or by default when compiling monolithic policy). Before: type=AVC msg=audit(1480451925.038:3225): avc: denied { getattr } for pid=7118 comm="chmod" path="/home/sds/selinux-testsuite/tests/bounds/bounds_file_blue" dev="dm-2" ino=23337697 scontext=unconfined_u:unconfined_r:test_bounds_child_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:test_bounds_file_blue_t:s0 tclass=file permissive=0 Was caused by: Unknown - would be allowed by active policy Possible mismatch between this policy and the one under which the audit message was generated. Possible mismatch between current in-memory boolean settings vs. permanent ones. After: type=AVC msg=audit(1480451925.038:3225): avc: denied { getattr } for pid=7118 comm="chmod" path="/home/sds/selinux-testsuite/tests/bounds/bounds_file_blue" dev="dm-2" ino=23337697 scontext=unconfined_u:unconfined_r:test_bounds_child_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:test_bounds_file_blue_t:s0 tclass=file permissive=0 Was caused by: Typebounds violation. Add an allow rule for the parent type. Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
* libselinux: audit2why: remove unused module_state structureNicolas Iooss2016-11-181-4/+1
| | | | | | | | | | | | | | This structure has been empty since its introduction and makes clang complain when $(filter-out -Werror, $(CFLAGS)) is removed in the Makefile target for audit2why.lo: audit2why.c:443:1: error: empty struct has size 0 in C, size 1 in C++ [-Werror,-Wc++-compat] struct module_state { ^ 1 error generated. Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
* Modify audit2why analyze function to use loaded policyJoshua Brindle2016-06-201-4/+4
| | | | | | | | Class and perms should come from the policy being used for analysis, not the system policy so use sepol_ interfaces Change-Id: Ia0590ed2514249fd98810a8d4fe87f8bf5280561 Signed-off-by: Joshua Brindle <brindle@quarksecurity.com>
* libselinux: fix audit2why error handling if SELinux is disabled.Stephen Smalley2015-02-131-2/+10
| | | | | | | | | | | | | | | If SELinux is disabled, then selinux_current_policy_path() returns NULL. At present, if you run audit2allow on a SELinux-disabled host without the -p option, you get: unable to open (null): Bad address We haven't seen this because most people running audit2allow are doing it on SELinux-enabled hosts and using the host policy. But for Android, the build host OS often has SELinux disabled and we need to pass audit2allow the path to the Android policy. Handle this case and provide a hint to the user. Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
* Get rid of security_context_t and fix const declarations.Stephen Smalley2014-02-191-2/+2
| | | | | | | | | | | | | | | | | | | | In attempting to enable building various part of Android with -Wall -Werror, we found that the const security_context_t declarations in libselinux are incorrect; const char * was intended, but const security_context_t translates to char * const and triggers warnings on passing const char * from the caller. Easiest fix is to replace them all with const char *. And while we are at it, just get rid of all usage of security_context_t itself as it adds no value - there is no true encapsulation of the security context strings and callers already directly use string functions on them. typedef left to permit building legacy users until such a time as all are updated. This is a port of Change-Id I2f9df7bb9f575f76024c3e5f5b660345da2931a7 from Android, augmented to deal with all of the other code in upstream libselinux and updating the man pages too. Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov> Acked-by: Eric Paris <eparis@redhat.com>
* Change audit2why to return constraint information on denial.Dan Walsh2013-10-291-1/+8
| | | | | | This patch uses Richard Haines fixes in libsepol to help identify which constraint is blocking access. The end goal is helping policy writers and administrators to diagnose issues with their policy.
* Revert "Richard Haines patch that allows us discover constraint violation ↵Stephen Smalley2013-10-251-8/+1
| | | | | | | | | information" This reverts commit 56b49ab7114f367f46b70e41d84dc7e6d52d5209. Conflicts: libselinux/src/audit2why.c
* Add selinux_current_policy_path, which returns the a pointer to the loaded ↵Dan Walsh2013-10-241-20/+4
| | | | | | | policy Also change audit2why to look at the loaded policy rather then searching on disk for the policy file. It is more likely that you are examining the running policy.
* This patch fixes python parsing.Dan Walsh2013-10-241-27/+22
| | | | Eliminates a potential memory leaks.
* Richard Haines patch that allows us discover constraint violation informationDan Walsh2013-10-241-1/+8
| | | | | Basically we need this information to allow audit2allow/audit2why to better describe which constraint is being broken.
* libselinux: Fix errors found by coverityEric Paris2013-02-051-1/+1
| | | | | Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Dan Walsh <dwalsh@redhat.com>
* libselinux: audit2why: Cleanup audit2why analysys functionDan Walsh2013-02-051-2/+2
| | | | | | | Tee-tiny cleanup to remove needless {} Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Dan Walsh <dwalsh@redhat.com>
* libselinux: audit2why: do not leak on multiple init() callsEric Paris2013-02-051-0/+4
| | | | | | | | If init() was already called then avc will be set. If avc is set just return. Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Dan Walsh <dwalsh@redhat.com>
* libselinux: audit2why: Fix segfault if finish() called twicerhatdan2013-02-051-1/+4
| | | | | | | | | If audit2why.finish is called more than once the global avc variable will be NULL, and thus dereferencing it will obviously cause problems. Thus just bail if avc is NULL and we know cleanup is done. Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Dan Walsh <dwalsh@redhat.com>
* libselinux: audit2why: make sure path is nul terminatedEric Paris2013-02-011-1/+2
| | | | | | | | We use strncpy which could leave a non-nul terminated string if the source is longer than PATH_MAX. Add that nul. Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Dan Walsh <dwalsh@redhat.com>
* libselinux: audit2why: silence -Wmissing-prototypes warningEric Paris2012-06-281-4/+4
| | | | | | | | | The init functions are non-static but did not have a prototype declaration. They are called magically from python, so just declare the prototype to silence the warning. Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Dan Walsh <dwalsh@redhat.com>
* libselinux: audit2why: close fd on enomemDan Walsh2011-11-021-0/+1
| | | | | | | | Potential file descriptor leak on this code path, need to close file descriptor if out of memory. Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Dan Walsh <dwalsh@redhat.com>
* libselinux: audit2why: work around python bug not defining SIZEOF_SOCKET_TEric Paris2011-08-111-0/+5
| | | | | | | | A at least one broken python headers didn't define SIZEOF_SOCKET_T. Define it if we happen upon one of those. Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Dan Walsh <dwalsh@redhat.com>
* audit2allow: do not print statisticsEric Paris2011-08-031-0/+2
| | | | | | | | I believe this is just to stop flooding the screen with libsepol statistics every time you run audit2allow or any other libsepol command. Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Dan Walsh <dwalsh@redhat.com>
* libselinux: fix python audit2why binding errorEric Paris2011-08-031-2/+3
| | | | | | | | There is a missing error check in audit2why.c. Check for error and return NULL if we can't initialize instead of just pretending it worked. Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Dan Walsh <dwalsh@redhat.com>
* Patch for python3 for libselinuxDaniel J Walsh2011-08-031-1/+38
| | | | | | | | | | | | | | | | | | Allow the specification of python3 in the swig creation This patch adds the new option PYPREFIX which causes the swig created libraries to have a prefix. This allows one to build both the python2 and python3 libraries in the same source tree. The install will then later strip this prefix back off when it drops the files into the python approriate site package directory. This patch also needs to update the PYINC definition as newer python patckages on fedora exist in /usr/include/python3.2mu instead of /usr/include/python3.2 as the other method of detemrining PYINC would have found. Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Dan Walsh <dwalsh@redhat.com>
* initial import from svn trunk revision 2950Joshua Brindle2008-08-191-0/+443