Commit graph

27 commits

Author SHA1 Message Date
Nicolas Iooss
f978b1b071 policycoreutils/sandbox: fix debug build
Building from the root directory with "make DEBUG=1" enables -Wshadow
option.  This makes the compilation fails with the following error:

  cc -g3 -O0 -gdwarf-2 -fno-strict-aliasing -Wall -Wshadow -Werror -g
  -I/usr/include -DPACKAGE="\"policycoreutils\"" -Wall -Werror -Wextra
  -W   -c -o seunshare.o seunshare.c

  seunshare.c: In function 'spawn_command':
  seunshare.c:141:6: error: declaration of 'child' shadows a global declaration [-Werror=shadow]
    int child;
        ^
  seunshare.c:58:12: error: shadowed declaration is here [-Werror=shadow]
   static int child = 0;
              ^

Fix this error by renaming the "child" variable in spawn_command.

Acked-by: Steve Lawrence <slawrence@tresys.com>
2014-10-02 09:55:53 -04:00
Andy Lutomirski
74d27a9733 seunshare: Try to use setcurrent before setexec
If seunshare uses PR_SET_NO_NEW_PRIVS, which certain versions of
libcap-ng set, setexeccon will cause execve to fail.  This also
makes setting selinux context the very last action taken by
seunshare prior to exec, as it may otherwise cause things to fail.

Note that this won't work without adjusting the system policy to
allow this use of setcurrent.  This rule appears to work:

    allow unconfined_t sandbox_t:process dyntransition;

although a better rule would probably relax the unconfined_t
restriction.

Signed-off-by: Andy Lutomirski <luto@amacapital.net>
2014-05-12 14:14:45 -04:00
Dan Walsh
de0795a12e Remove handling of cgroups from sandbox
It never worked correctly and this should be handled with an
API to systemd going forward.
2014-05-12 14:14:42 -04:00
Dan Walsh
6ee0299ab7 Update XDG_RUNTIME_DIR directory 2014-05-12 14:14:39 -04:00
Dan Walsh
e4488ecd87 Allow users to have homedir as a symbolic link but mount on the homedir
Also do not error out on setfsuid if errno == success.  This breaks on systems
that use file capabilities rather then on setuid apps.
2013-10-24 13:58:39 -04:00
Eric Paris
221e6d4665 policycoreutils: seunshare: do checking on setfsuid
setfsuid return codes were not being checked.  Add checks to make sure
we are switching from and to what we expect.  Bail (most places) if we
didn't switch successfully.

Signed-off-by: Eric Paris <eparis@redhat.com>
2013-02-05 20:14:51 -05:00
Eric Paris
0a5dc30456 policycoreutils: sandbox: seunshare: do not reassign realloc value
We were doing x = realloc(x, )  which is a big no no, since it leaks X
on allocation failure.  Found with static analysis tool from David
Malcolm.

Signed-off-by: Eric Paris <eparis@redhat.com>
2013-02-05 20:14:50 -05:00
Laurent Bigonville
2ad5471bd3 policycoreutils: fix ftbfs with hardening flags
We are now building our packages with -Werror=format-security enabled.
The attached patch fix the FTBFS. More patch related to this could
follow.

Signed-off-by: Laurent Bigonville <bigon@debian.org>
Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2012-03-28 14:52:14 -04:00
Dan Walsh
1f0b5bd920 policycoreutils: seunshare: Only drop caps not the Bounding Set from seunshare
This means you can still run setuid programs, but don't need special
perms to run seunshare.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2012-03-28 14:52:13 -04:00
Dan Walsh
70c582f4e0 policycoreutils: sandbox: do not propogate inside mounts outside
Fix the handling of namespaces in seunshare/sandbox.
Currently mounting of directories within sandbox is propogating to the
parent namesspace.  This fix will basically isolate any mounting that
happens after the unshare from the parent namespace.

Signed-off-by: Eric Paris <eparis@redhat.com
Acked-by: Dan Walsh <dwalsh@redhat.com>
2012-03-28 08:39:07 -04:00
Eric Paris
e134013ab7 policycoreutils: sandbox: introduce package name and language stuff
Add support for translations to the sandbox utility.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2011-11-02 16:22:05 -04:00
Dan Walsh
5c2a0d143d policycoreutils: sandbox: Maintain the LANG environment into the sandbox
When running an app within a sandbox, the application currently
switches to no LANG.  This patch will cause the sandboxed app to use
the users LANG.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2011-11-02 16:22:05 -04:00
Dan Walsh
216f456401 policycoreutils: sandbox: cntrl-c should kill entire process control group
Change the signal handler to handle ctrl-C and exit properly

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2011-09-16 11:54:00 -04:00
Dan Walsh
e8575bf497 policycoreutils: sandbox: add level based kill option
add kill option to seunshare to kill all processes that are still running
with the execcon MCS label.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2011-09-16 11:54:00 -04:00
Eric Paris
31edb319af policycoreutils: sandbox: rewrite /tmp handling
seunshare now creates a runtime temporary directory owned by root and
with the sticky bit set properly.  Files from the user-specified directory
are copied to the runtime directory and the changes synced back (using rsync)
at the end of the seunshare run.

This is hoped to address CVE-2011-1011

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2011-09-16 11:53:46 -04:00
Eric Paris
4347a5c01d policycoreutils: sandbox: add sandbox cgroup support
Add cgroup support

Signed-off-by: Eric Paris <eparis@redhat.com>
2011-09-15 19:20:44 -04:00
Dan Walsh
a0e2e16878 policycoreutils: sandbox: Allow seunshare to run as root
Signed-off-by: Dan Walsh <dwalsh@redhat.com>
2011-08-26 14:31:56 -04:00
Eric Paris
f6558d9cec policycoreutils: sandbox: seunshare: introduce helper spawn_command
Introduce a helper which will spawn children and wait for them to exit
so we don't have to keep writing that code over and over.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2011-08-26 14:31:50 -04:00
Eric Paris
bf22cff3ea policycoreutils: sandbox: seunshare: introduce new filesystem helpers
These are just simple new helpers which make it easy to check uid, gid,
if two stat results are the same and things like that.

Signed-off-by: Eric Paris <eparis@redhat.com>
2011-08-26 14:28:25 -04:00
Dan Walsh
149afc688a policycoreutils: sandbox: add -C option to not drop all capabilities
Some sandbox might want to be able to run a suid app.  Add the -C option
to allow capabilities to stay in the bounding set, and thus be allowed
inside the sandbox.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2011-08-26 14:28:23 -04:00
Eric Paris
d6c09608cd policycoreutils: sandbox: split seunshare caps dropping
Split drop_capabilities into drop_privs, which does the same thing, and
drop_caps, which only drops caps but doesn't affect the uid.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2011-08-26 14:28:22 -04:00
Eric Paris
da7ae7951c policycoreutils: sandbox: do not require selinux context
seunshare can be used on non-selinux systems.  It can also be used
without transition to a new context.  Thus we should not require that a
context be set.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2011-08-26 14:28:16 -04:00
Eric Paris
406ae12e31 policycoreutils: sandbox: move seunshare globals to the top
Just coding style, globals go at the top of .c files, not randomly
throughout.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2011-08-26 14:28:05 -04:00
Eric Paris
89e3dd6c30 policycoreutils: sandbox: whitespace fix
couple of whitespace at the end of the line.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2011-08-26 14:28:03 -04:00
Eric Paris
39066bd0ac policycoreutils: seunshare: define _GNU_SOURCE earlier
If one tries to build policycoreutils it won't work because of:

seunshare.c: In function ‘main’:
seunshare.c:242:21: error: ‘CLONE_NEWNS’ undeclared (first use in this
function)
seunshare.c:242:21: note: each undeclared identifier is reported only
once for each function it appears in
make[1]: *** [seunshare.o] Error 1

Moving the #define _GNU_SOURCE earlier in the file means it is set when
sched.h is includes via some of dependancy chain.  Thus it can build.

Signed-off-by: Eric Paris <eparis@redhat.com>
2011-08-02 13:58:07 -04:00
Steve Lawrence
582fd00c7b Author: Steve Lawrence
Email: slawrence@tresys.com
Subject: Updated sandbox patch.
Date: Mon, 07 Jun 2010 17:53:41 -0400

On Thu, 2010-05-27 at 08:57 -0400, Daniel J Walsh wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 05/26/2010 04:06 PM, Steve Lawrence wrote:
> > On Wed, 2010-05-19 at 15:59 -0400, Daniel J Walsh wrote:
> > Fixed patch that handles Spaces in homedir.
>
> > The following patch makes a few updates the the sandbox patch, though I
> > have a question:
>
> > Is the sandbox.init script needed anymore? It looks like seunshare was
> > changed to now bind mount and make private the necessary directories.
> > The only thing that seems missing is making root rshared. Also, if the
> > init script is obsolete, do the mounts also need the MS_REC flag for
> > recursive bind/private like they are mounted in the init script? e.g.
>
> The init script is needed for the xguest package/more specifically
> pam_namespace, but also needed for
> mount --make-rshared /
>
> Whether the init script belongs in policycoreutils is questionable though.
>
>
> > mount(dst, dst, NULL, (MS_BIND | MS_REC), NULL)
> > mount(dst, dst, NULL, (MS_PRIVATE | MS_REC), NULL)
>
> We probably should add these.  Although it is not likely.
>
> > Changes the following patch makes:
>
> > sandbox.py
> > - Removes unused 'import commands'
> > - Fixes the chcon function, and replaces the deprecated os.path.walk
> >   with os.walk. I think this way is a bit easier to read too.
>
> I think chcon should be added to libselinux python bindings and then
> leave the recursive flag.  (restorecon is currently in python bindings._
>
> > - Removes the 'yum install seunshare' message. This tool is not specific
> >   to RPM based distros.
>
> People are using seunshare without X now that I have added the -M flag.
>  So I will move it from the -gui package to the base package with
> sandbox and then this should not be necessary.
> > - Remove try/except around -I include to be consistent with the -i
> >   option. If we can't include a file, then this should bail, no matter
> >   if it's being included via -i or -I.
>
> Ok, I was thinking you could list a whole bunch of files in the -I case
> and if one does not exist, allow it to continue.  But I don't really care.
> > - Fix homedir/tmpdir typo in chcon call
>
> > sandbox.init (maybe obsoleted?)
> > - Fix restart so it stops and starts
> > - unmount the bind mounts when stopped
> I doubt this will work.  Two many locks in /tmp /home
> > - Abort with failure if any mounts fail
>
> > seunshare.c
> > - Define the mount flag MS_PRIVATE if it isn't already. The flag is only
> >   defined in the latest glibc but has been in the kernel since 2005.
> > - Simplify an if-statment. Also, I'm not sure the purpose of the
> >   strncmmp in that conditional, so maybe I've oversimplified.
> This is wrong.  The problem comes about when you mount within the same
> directory.
>
> seunshare -t /home/dwalsh/sanbox/tmp -h /home/dwalsh/sandbox/home   ...
>
> seunshare -t /tmp/sandbox/tmp -h /tmp/sandbox/home
>
> If you do not have the check one of the above will fail.
>
> In the first example if Homedir is mounted first,
> /home/dwalsh/sanbox/tmp will no longer exist when seunshare attempts to
> mount it on /tmp.
>
> Similarly, if /tmp is mounted first in the second example.
> /tmp/sandbox/home will no longer exist.
>
> You have to check to make sure one of the directories is not included in
> the other.
>
> It seems
> >   like maybe an error should be thrown if tmpdir_s == pw_dir or
> >   homedir_s == "/tmp", but maybe I'm missing something.
>
> See above.
>
> I was blowing up because I use
>
> ~/sandbox/tmp and ~/sandbox/home for my mountpoints.

<snip>

Below is an updated patch that makes a few changes the the latest
Sandbox Patch [1]. This requires the chcon patch [2].

Changes this patch makes:

sandbox.py
- Remove unused 'import commands'
- Uses new chcon method in libselinux [2]
- Removes the 'yum install seunshare' message
- Converts an IOError to a string for printing a warning if a file
  listed in -I does not exist

sandbox.init
- Print the standard Starting/Stoping messages with the appropriate
  OK/FAIL
- Abort with failure if any mounts fail

seunshare.c
- Add the MS_REC flag during mounts to perform recursive mounts
- Define the mount flags MS_PRIVATE and MS_REC if they aren't already.
  The flags are only defined in the latest glibc but have been in the
  kernel since 2005.
- Calls realpath(3) on tmpdir_s and homedir_s. If relative paths are
  used, it wouldn't correctly detect that tmpdir is inside homedir and
  change the mount order. This fixes that.

[1] http://marc.info/?l=selinux&m=127429948731841&w=2
[2] http://marc.info/?l=selinux&m=127594712200878&w=2

Signed-off-by: Chad Sellers <csellers@tresys.com>
2010-06-10 16:37:59 -04:00
Daniel J Walsh
d6848ea77d Author: Daniel J Walsh
Email: dwalsh@redhat.com
Subject: Updated sandbox patch.
Date: Wed, 19 May 2010 15:59:28 -0400

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Fixed patch that handles Spaces in homedir.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAkv0QyAACgkQrlYvE4MpobNBXQCgmUu92HsN5PiksOTZoGxSp0W+
1noAoKoCujFPLHduJ9BP3hrveeXvGKXO
=iqC+
-----END PGP SIGNATURE-----

Signed-off-by: Chad Sellers <csellers@tresys.com>
2010-06-10 16:35:55 -04:00