Commit graph

707 commits

Author SHA1 Message Date
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
Eric Paris
48682e2853 libselinux: label_file: move spec_hasMetaChars to header
So we can use it in the new compile utility, move the
spec_hasMetaChars() function, which looks for things like .*?+^$ in
regular expressions into the internal header file.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:51:47 -04:00
Eric Paris
fcc895661d libselinux: label_file: drop useless ncomp field from label_file data
The libselinux label_file backend counted the number of regexes which
had been compiled.  We didn't use it and it wasn't useful information.
Stop doing it.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:51:47 -04:00
Eric Paris
9937685cbe libselinux: label_file: move stem/spec handling to header
We want to be able to find the stem and the spec from our new utility.
So move those functions to the header file.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:51:47 -04:00
Eric Paris
b9482941ce libselinux: label_file: move error reporting back into caller
If we want to use these functions in utilities we shouldn't call such
libselinux internal functions.  Move the error reporting up to the
caller.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:50:17 -04:00
Eric Paris
f744f239fb libselinux: label_file: do string to mode_t conversion in a helper function
So the string to mode_t conversion in a helper function so it can be
used later by a regex compilation program.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:50:17 -04:00
Eric Paris
c27101a583 libselinux: label_file: move definitions to include file
We want to use some label_file internals in a utility to compile
fcontext files into binary data for fast use.  So start pushing
structures and such into a header file.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:50:16 -04:00
Eric Paris
dc1db39e28 libselinux: label_file: remove all typedefs
I hate them.  They just indirectly you needlessly.  Just use the struct
definitions.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:49:33 -04:00
Eric Paris
091eb526dd libselinux: label_file: use PCRE instead of glibc regex functions
The PCRE functions are about x10 faster than the glibc functions.  So
use the external library.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:49:32 -04:00
Eric Paris
ac5f5645b6 libselinux: stop messages when SELinux disabled
If SELinux is disabled we should send any messages.  We shouldn't do
anything.  Just return.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:42:29 -04:00
Chris PeBenito
01723ac2ce libsepol: Add always_check_network policy capability
Currently the packet class in SELinux is not checked if there are no
SECMARK rules in the security or mangle netfilter tables.  Similarly, the
peer class is not checked if there is no NetLabel or labeled IPSEC.  Some
systems prefer that these classes are always checked, for example, to
protect the system should the netfilter rules fail to load or if the
nefilter rules were maliciously flushed.

Add the always_check_network policy capability which, when enabled, treats
these mechanisms as enabled, even if there are no labeling rules.

Signed-off-by: Chris PeBenito <cpebenito@tresys.com>
Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:30:24 -04:00
Chris PeBenito
1f3bca77e0 libsepol: check for missing initial SID labeling statement.
If an initial SID is missing a labeling statement, the compiler will
segfault when trying to copy the context during expand.  Check for this
situation to handle it gracefully.

This fixes ocontext_copy_selinux() and ocontext_copy_xen().

Signed-off-by: Chris PeBenito <cpebenito@tresys.com>
Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:30:23 -04:00
Chris PeBenito
e26b58b08e libsepol: Move context_copy() after switch block in ocontext_copy_*().
If an initial SID is missing a labeling statement, the compiler will
segfault on the context_copy().  Move the context copy after the
switch block so that the existance of the initial SID label can be checked
before trying to copy the context.

This fixes both ocontext_copy_selinux() and ocontext_copy_xen().

Signed-off-by: Chris PeBenito <cpebenito@tresys.com>
Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:30:23 -04:00
Dan Walsh
30db6f423b policycoreutils: sandbox: Make sure Xephyr never listens on tcp ports
Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:30:22 -04:00
Eric Paris
b2d86f8219 libselinux: booleans: initialize pointer to silence coveriety
The coveriety scanner is too stupid to realize that the strtok_r()
function initializes the saveptr variable.  Since we are passing a
variable location without initializing it coveriety gets angry.  Just
shut up the scanner, but nothing was wrong to start with.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:30:22 -04:00
Dan Walsh
bd8ea2eb6c libselinux: seusers: Check for strchr failure
If we have a malformed seusers entry we may not find the : proceeding
the level and would thus get a NULL.  This can blow up.  Check for this
error and bail gracefully.  Found by coverity

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:30:21 -04:00
Dan Walsh
fa7a9a604e libselinux: utils: avcstat: clear sa_mask set
We were leaving random stack garbage in sa.sa_mask.  Clear it the way
one should.  (spotted by coveriety)

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:30:21 -04:00
Eric Paris
873c176651 checkpolicy: check return code on ebitmap_set_bit
This can fail due to ENOMEM.  Check and return code and return error if
necessary.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:30:20 -04:00
Eric Paris
87e8d46f29 policycoreutils: checkmodule: fd leak reading policy
We never closed the fd to the policy file.  Close this fd as soon as we
are finished with it.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:30:20 -04:00
Eric Paris
1db01640ee libselinux: matchpathcon: add -m option to force file type check
We may want to force matchpathcon to respond if the path is question is
a dir, sockfile, chr, blk, etc.  Add an option so you can force it to
hit the right rule types.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 14:23:22 -04:00
Eric Paris
b0b22829eb libsemanage: do boolean name substitution
So people can use -P and it will work.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 13:17:30 -04:00
Dan Walsh
ee6901618c libselinux: expose selinux_boolean_sub
Make selinux_boolean_sub a public method so getsebool can use it, as well as
potentially used within libsemanage.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 13:15:00 -04:00
Dan Walsh
179ee6c187 libselinux: Add man page for new selinux_boolean_sub function.
Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 13:14:29 -04:00
Dan Walsh
bac96c8c70 libselinux: getsebool: support boolean name substitution
Use selinux_boolean_sub to translate the boolean name handed in by the user.
Report back the correct name of the boolean.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 13:14:29 -04:00
Eric Paris
88c3524153 libselinux: boolean name equivalency
Add support for booleans.subs file. Basically this allows us to finally change
badly named booleans to some standard name.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2012-09-12 13:14:25 -04:00
Dan Walsh
065e5d3149 sepolgen: Allow returning of bastard matches
Return low quality matches as well as high quality matches.  Sometimes
we just want the crap with the sugar.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 12:16:19 -04:00
Dan Walsh
3babdf190b policycoreutils: semanage: use boolean subs.
This fixes a problem in xguest which is using the old
name of the boolean an blowing up on install.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 12:16:19 -04:00
Eric Paris
1024ea34c6 libselinux: libsemanage: remove PYTHONLIBDIR and ruby equivalent
We generate pkg-config --libs and use that to build the libselinux
python so file.  We do not use it to build the libsemanage versions.  We
also never use the ruby equivalent.  So stop calling pkg-config
uselessly.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 12:16:19 -04:00
Eric Paris
b2523dc167 libselinux: libsemanage: do not set soname needlessly
We explicitly set the soname of the python and ruby files.  We don't
need this.  We are using the -o name as the soname, so just let the
toolchain do its thing.  It just makes the Makefile nicer to read.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2012-09-12 12:16:18 -04:00
Eric Paris
056f23c4bf libselinux: utils: add service to getdefaultcon
Add a -s option to getdefaultcon which allows one to specify the
service in question.  This exposes all of the abilities of getseuser
instead of only the abilities of getseuserbyname.

Signed-off-by: Eric Paris <eparis@redhat.com>
2012-09-12 12:16:18 -04:00
Dan Walsh
e4f0a20ee1 polciycoreutils: setsebool: error when setting multiple options
If one were to use multiple options such as both -P and -N we would have
problems.  The issue is that for some reason instead of looking at
optind (the first non-option) we were looking at argc-optind.  These
happen to be the same if there are 0 or 1 options, but doesn't work with
more than 1 option.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2012-09-12 12:16:17 -04:00
Dan Walsh
cef1d08d1e policycoreutils: fixfiles: tell restorecon to ignore missing paths
Restorecon should default to ignore missing files.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2012-09-12 12:16:17 -04:00
Dan Walsh
f6595e357f policycoreutils: setfiles: return errors when bad paths are given
Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2012-09-12 12:16:16 -04:00
Dan Walsh
39d6b469ba policycoreutils: gui: Fix missing error function
And change to not use = with setsebool, purely cosmetic

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2012-09-12 12:16:16 -04:00
Dan Walsh
ff78e21ef8 policycoreutils: gui: polgen: follow symlinks and get the real path to the executable to be confined
Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2012-09-12 12:16:15 -04:00
Dan Walsh
f627d9a8ce policycoreutils: gui: polgen: sort selinux types of user controls
Just cosmetic.  Make them all line up the same way in case anyone ever
looks at the code.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2012-09-12 12:16:15 -04:00
Dan Walsh
7ae7858a6b policycoreutils: semodule: Add -N qualifier to no reload kernel policy
This makes semodule consistent with other commands to no reload the
policy into the kernel after the given change.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2012-09-12 12:16:15 -04:00
Dan Walsh
413b4933ee policycoreutils: setsebool: -N should not reload policy on changes
Fix setsebool to use -N to not reload policy into the kernel optional on
permanant changes.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2012-09-12 12:16:14 -04:00
Dan Walsh
82415fa1b0 policycoreutils: sandbox: manpage update to describe standard types
add some definition to the standard types available for sandboxes so
users have a way to know about them and what they are intended to be
used for.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2012-09-12 12:16:14 -04:00
Dan Walsh
e5962bb179 policycoreutils: semanage: option to not load new policy into kernel after changes
Add -N, --noreload option to semanage to prevent reloading policy into
the kernel after a change.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2012-09-12 12:16:13 -04:00
Dan Walsh
cf87e75d45 policycoreutils: return equivalency records in fcontext customized
fcontext customized was not returning the customized equivalency records.  This
patches fixes this.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2012-09-12 12:16:13 -04:00
Dan Walsh
c48b7fe336 policycoreutils: gui: remove lockdown wizard
Future systems will not support html in a pygtk window as webkit is
going away.  I decided to add the full set of gui tools and then remove
the one I don't want to support just in case someone wants to resurrect
this at some point.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2012-09-12 12:16:12 -04:00
Dan Walsh
c5cf981869 policycoreutils: Add Makefiles to support new gui code
We added new gui programs, but not Makefiles to build/install them.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2012-09-12 12:16:12 -04:00