Commit graph

272 commits

Author SHA1 Message Date
Stephen Smalley
39b5a40295 Fix relabel target.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2013-10-23 12:44:30 -04:00
Joe MacDonald
fceca652c1 libselinux: avoid shadowing 'stat' in load_mmap
label_file.c: In function ‘load_mmap’:
   label_file.c:238:81: error: declaration of ‘stat’ shadows a global declaration [-Werror=shadow]
   cc1: all warnings being treated as errors

Signed-off-by: Joe MacDonald <joe@deserted.net>
2013-10-22 14:22:42 -04:00
Joe MacDonald
2864f757dd libselinux: support building on older PCRE libs
Versions of PCRE prior to 8.20 did not have pcre_free_study().  In its
absence, use pcre_free() instead.

Signed-off-by: Joe MacDonald <joe@deserted.net>
2013-10-22 14:22:22 -04:00
Laurent Bigonville
ead1e1d8e2 libselinux: Fix various minor manpage issues and correct section numbering. 2013-10-16 15:10:34 -04:00
Laurent Bigonville
50b1654c1d libselinux: Do not use LDFLAGS to set -lpcre and -lpthread
This is breaking build if LDFLAGS is redefined.

This is the case on Debian where hardening flags are passed
automatically by the build system.
2013-10-16 15:10:14 -04:00
Laurent Bigonville
c45f797b28 libselinux: Allow overriding LIBBASE in src/Makefile 2013-10-16 15:09:26 -04:00
Sven Vermeulen
32e76a314e Current stable policycoreutils requires selinux_current_policy_path
Without this fix, stolen from Fedora's patchset, recent policycoreutils
just fails.

See http://marc.info/?t=136926404600001&r=1&w=2 and
see http://marc.info/?l=selinux&m=136692033821285&w=2

Signed-off-by: Sven Vermeulen <sven.vermeulen@siphos.be>
2013-10-16 14:57:02 -04:00
Sven Vermeulen
a15451b523 Support udev-197 and higher
The errno value was not set, causing wrong return notifications and
failing to have udev label things correctly.

See https://bugzilla.redhat.com/show_bug.cgi?id=909826#c24 and
see https://bugs.gentoo.org/show_bug.cgi?id=462626

Signed-off-by: Sven Vermeulen <sven.vermeulen@siphos.be>
2013-10-16 14:56:48 -04:00
Sven Vermeulen
e4cee831af Make RANLIB variable overridable
If the RANLIB variable is defined by the user, use that value instead of
the /usr/bin/ranlib binary.

Signed-off-by: Sven Vermeulen <sven.vermeulen@siphos.be>
2013-10-16 14:55:58 -04:00
Sven Vermeulen
1310e36026 Update pkgconfig definition
Signed-off-by: Sven Vermeulen <sven.vermeulen@siphos.be>
2013-10-16 14:55:48 -04:00
Sven Vermeulen
ef3e072f58 Mount sys before trying to mount selinuxfs
If /sys is not present, the attempt to mount selinuxfs will of course
fail. So we try to mount /sys first (and only if that fails fall back to
the /selinux mount point) and then try to mount selinuxfs.

Signed-off-by: Sven Vermeulen <sven.vermeulen@siphos.be>
2013-10-16 14:55:40 -04:00
Eric Paris
e9410c9b06 VERSION BUMP FOR UPSTREAM PUSH 2013-02-05 20:22:02 -05:00
Eric Paris
ce39302fd0 libselinux: sefcontext_compile: do not leak fd on error
We open the file which is to be used to write the binary format of file
contexts.  If we hit an error actually writing things out, we return,
but never close the fd.  Do not leak.

Signed-off-by: Eric Paris <eparis@redhat.com>
2013-02-05 20:21:52 -05:00
Eric Paris
4e5eaacc59 libselinux: matchmediacon: do not leak fd
Every time matchmediacon is called we open the
selinux_media_context_path().  But we never close the file.  Close the
file when we are finished with it.

Signed-off-by: Eric Paris <eparis@redhat.com>
2013-02-05 20:21:52 -05:00
Eric Paris
1e8f102e8c libselinux: src/label_android_property: do not leak fd on error
We were opening the path, but if the fstat failed or it was not a
regular file we would return without closing the fd.  Fix my using the
common error exit path rather than just returning.

Signed-off-by: Eric Paris <eparis@redhat.com>
2013-02-05 20:21:52 -05:00
Eric Paris
0834ff3022 libselinux: do not leak file contexts with mmap'd backend
We use strdup to store the intended context when we have an mmap'd
file backend.  We, however, skipped freeing those contexts.

Signed-off-by: Eric Paris <eparis@redhat.com>
2013-02-05 20:14:48 -05:00
Eric Paris
efb6347dd3 libselinux: unmap file contexts on selabel_close()
We were leaking all of the file context db because we didn't unmap them
on selabel_close()

Signed-off-by: Eric Paris <eparis@redhat.com>
2013-02-05 20:14:48 -05:00
Dan Walsh
9c83b206e1 libselinux: pkg-config do not specifc ruby version
pkg-config do not work if you specifiy the version of ruby in Fedora 19

Signed-off-by: Eric Paris <eparis@redhat.com>
2013-02-05 20:14:48 -05:00
Eric Paris
1d403326ae libselinux: optimize set*con functions
Set*con now caches the security context and only re-sets it if it changes.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2013-02-05 20:14:47 -05:00
Dan Walsh
e9759ea7af libselinux: Change boooleans.subs to booleans.subs_dist.
Currently we ship other subs files with the _dist to indicate they come with
the distribution as opposed to being modified by the user.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2013-02-05 20:14:46 -05:00
Eric Paris
aa62cd60f7 libselinux: Fix errors found by coverity
Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2013-02-05 20:14:45 -05:00
Eric Paris
c89deab09a libselinux: selinux_status_open: do not leak statusfd on exec
Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2013-02-05 20:14:44 -05:00
Eric Paris
761881c947 libselinux: selinux_status_open: handle error from sysconf
We didn't handle sysconf(_SC_PAGESIZE) returning an error.  It should be
very rare, obviously, be we should handle it.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2013-02-05 20:14:44 -05:00
Pádraig Brady
2f624c94c7 libselinux: man: context_new(3): fix the return value description
Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2013-02-05 20:14:44 -05:00
Guillem Jover
be2d728599 libselinux: Use ENOTSUP instead of EOPNOTSUPP for getfilecon functions
EOPNOTSUPP means "operation not supoorted on socket", and ENOTSUP means
"not supported", although per POSIX they can be alised to the same
value and on Linux they do, ENOTSUP seems the more correct error code.
In addition these function are documented as returning ENOTSUP, and
given that they are implemented in means of getxattr(2) which does
return ENOTSUP too, this just consolidates their behaviour.

Signed-off-by: Guillem Jover <guillem@debian.org>
Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2013-02-05 20:14:44 -05:00
Guillem Jover
9acdd37989 libselinux: man: Add references and man page links to _raw function variants
Signed-off-by: Guillem Jover <guillem@debian.org>
Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2013-02-05 20:14:43 -05:00
Guillem Jover
4f289b50ac libselinux: man: Fix typo in man page
Signed-off-by: Guillem Jover <guillem@debian.org>
Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2013-02-05 20:14:43 -05:00
Guillem Jover
6ef13eeda7 libselinux: man: Fix man pages formatting
- Add man page sections '(N)' to external references, and '()' on
  functions described in the same man page.
- Escape minus signs when those are expected to be used on the command
  line or files.
- Mark files and variables in italic; Note headings, function names,
  constants, program options and man page references in bold.
- Do not justify and hyphenate SEE ALSO section, and avoid hyphenation
  on symbol names by prepending them with \%.
- Remove trailing dot from NAME section description.
- Split sections with a no-op command '.', to visually distinguish them
  but to avoid introducing spurious vertical space in the formatted
  output.
- Add explicit .sp commands in the SYNOPSIS section between function
  prototypes, and fix space placement in function protoypes.
- Split header includes with .br (instead of the explicit or implicit
  .sp) so that they are vertically contiguous.
- Add missing {} around SELINUXTYPE and POLICYTYPE variable text in
  paths.
- Remove unneeded formatting commands.
- Remove spurious blank lines.

Signed-off-by: Guillem Jover <guillem@debian.org>
Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2013-02-05 20:14:43 -05:00
Guillem Jover
8cc79bcd98 libselinux: man: Fix program synopsis and function prototypes in man pages
Fix typos, or wrong function prototypes.

Signed-off-by: Guillem Jover <guillem@debian.org>
Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2013-02-05 20:14:43 -05:00
Dan Walsh
7504bbd873 libselinux: audit2why: Cleanup audit2why analysys function
Tee-tiny cleanup to remove needless {}

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2013-02-05 20:14:42 -05:00
rhatdan
13b599d7b8 libselinux: mode_to_security_class: interface to translate a mode_t in to a security class
coreutils needs to be able to take a statbuf and ask permissions
questions.  This gives us the interface to translate that statbuf mode_t
into a security class which can be used.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2013-02-05 20:14:40 -05:00
Eric Paris
d09bcb75f5 libselinux: audit2why: do not leak on multiple init() calls
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>
2013-02-05 20:14:40 -05:00
rhatdan
019e6fd6d4 libselinux: audit2why: Fix segfault if finish() called twice
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>
2013-02-05 20:14:39 -05:00
rhatdan
2677b72191 libselinux: man: make selinux.8 mention service man pages
We were listing a number of service man pages (like httpd_selinux) in
the see also section of selinux.8.  As that number of pages explodes it
does not make sense to try to list them all.  Instead tell people to use
man -k selinux to find them.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2013-02-05 20:14:39 -05:00
rhatdan
44cba24ba6 libselinux: sefcontontext_compile: Add error handling to help debug problems in libsemanage.
Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2013-02-01 12:08:57 -05:00
Eric Paris
a293048a59 libselinux: do not leak mmapfd
On failure, common if .bin is older than the text version, we will leak
the mmapfd.  Don't do that.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2013-02-01 12:08:57 -05:00
Eric Paris
9ebd779353 libselinux: label_file: use precompiled filecontext when possible
When loading the filecontext database, check to see if there is a newer
binary version.  If so, mmap that file, is used to populate the regex db
instead of reading from the text representation and compiling regex's as
needed.  If the text file is newer it will use the text version and
ignore the binary version.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2013-02-01 12:08:57 -05:00
Eric Paris
dac8b32c17 libselinux: utils: new file context regex compiler
This is a new 'compiler' which tranforms the file context database into
a binary format.  This binary format may be mmap'd in later removing the
need to compile the regular expression at run time.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2013-02-01 12:08:56 -05:00
Eric Paris
933840af6c libselinux: audit2why: make sure path is nul terminated
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>
2013-02-01 12:08:56 -05:00
Eric Paris
8638197342 Version bumps for upstream push 2012-09-13 10:33:58 -04:00
Guido Trentalancia
45658fc6d5 libselinux: improve the file_contexts.5 manual page
Manual page improvements for the file_contexts and related policy
configuration files (section 5):

- create links to selabel_file.5 not only for file_contexts.5 but
  also for the other optional policy configuration files (including
  the so-called file contexts "substitution" files);
- clarify the above mentioned manual page(s), in particular relatively
  to the action performed by the so-called file contexts "substitution"
  policy configuration files (aliasing/equivalence versus substitution);
- improve the explanation of the form that the "substitution" files
  shall have.

Signed-off-by: Guido Trentalancia <guido@trentalancia.com>
Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 21:14:43 -04:00
Dan Walsh
1c8a7c194d libselinux: Ensure that we only close the selinux netlink socket once.
Taken from our Android libselinux tree.  From Stephen Smalley.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 21:06:55 -04:00
Eric Paris
4d04f4c443 libselinux: label_file: only run array once when sorting
Instead of running the array two times, sorting the 'hasMeta' the first
time and the !hasMeta the second, run the array once putting hasMeta in
the front and !hasMeta in the back.  Then ONLY run the !hasMeta section
a second time reversing its order so its sorted as it should be.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:51:51 -04:00
Eric Paris
36ab97dadc libselinux: label_file: struct reorg
Use char instead of int, reorder to put the chars together.  Just litle
things.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:51:51 -04:00
Eric Paris
de5bc062ca libselinux: label_file: break up find_stem_from_spec
Right now find_stem_from_spec does a number of things:
- calculate the length of th stem
- look for that stem
- duplicate the stem
- add the stem to the array

break those things up a bit because the mmap version isn't going to need
to do some of those things.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:51:50 -04:00
Eric Paris
16b578895e libselinux: label_file: new process_file function
We currently duplicate code 3 times for the main file, the homedirs, and
the local file.  Just put that stuff in its own function so we don't
have to deal with it multiple times.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:51:50 -04:00
Eric Paris
79b6a8d78f libselinux: label_file: only run regex files one time
We currectly run all of the regex files 2 times.  The first time counts
the lines and does the simple validatation.  We then allocate an array
of exactly the right size to hold the entries and run them a second time
doing stronger validation, regex compile, etc.

This is dumb.  Just run them one time and use realloc to grow the size
of the array as needed.  At the end the array will get sized perfectly
to fit by the sorting function, so even if we accidentally allocated
entra memory we'll get it back.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:51:49 -04:00
Eric Paris
ee88185aff libselinux: label_file: add accessors for the pcre extra data
When we use an mmap backed version of data we need to declare the pcre
extra data since we are only given a point to the data->buffer.  Since
sometimes the spec will hold a pointer to the extra data and sometimes
we want to declare it on the stack I introduce and use an accessor for
the extra data instead of using it directly.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:51:49 -04:00
Eric Paris
247759031a libselinux: label_file: move regex sorting to the header
We want to do the same thing in the compiler and as we do in in the code
which reads regexes in from the text file.  Move that sorting into the header.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:51:48 -04:00
Eric Paris
dd61029c54 libselinux: label_file: fix potential read past buffer in spec_hasMetaChars
An illegal regex may end with a single \ followed by nul.  This could
cause us to search past the end of the character array.  The loop
formation looks like so:

        c = regex_str;
        len = strlen(c);
        end = c + len;

        while (c != end) {
		switch (*c) {
		...
                case '\\':      /* skip the next character */
                        c++;
                        break;
		...
                }
                c++;
	}

If the \ is the last character then we will increment c and break from
the switch.  The while loop will then increment c.  So now c == end+1.
This means we will keep running into infinity and beyond!  Easy fix.
Make the loop check (c < end).  Thus even if we jump past end, we still
exit the loop.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:51:48 -04:00