aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* libsandbox: handle open's O_TMPFILE flagv2.7Mike Frysinger2015-09-111-1/+1
| | | | | | | | | This new flag needs us to unpack & pass down the mode rather than always sending in the value of 0. URL: http://bugs.gentoo.org/529044 Reported-by: Aidan Thornton <makosoft@googlemail.com> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: fix building w/gcc-5Mike Frysinger2015-04-151-1/+1
| | | | | | | | The preprocessed output of gcc has changed a bit to retain more whitespace, but this just confuses/breaks the scripts that parse it. Add the -P flag to normalize things a bit. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: preserve more SANDBOX env varsMike Frysinger2013-02-233-132/+238
| | | | | | | | | | | | | | | | | While we took pains to preserve the LD_PRELOAD setting, this doesn't help us too much in practice. If a process is going out of its way to blow away LD_PRELOAD, chances are good it's blowing away all vars it doesn't know about. That means all of our SANDBOX_XXX settings. Since a preloaded libsandbox.so is useless w/out its SANDBOX_XXX env vars, make sure we preserve those as well. These changes also imply some behavioral differences from older versions. Previously, you could `unset` a sandbox var in order to disable it. That no longer works. If you wish to disable things, you have to explicitly set it to "". Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: clean up open file handles in parent tracing processMike Frysinger2012-06-231-1/+2
| | | | | | | | | | | | | | Currently, if a non-static app sets up a pipe (with cloexec enabled) and executes a static app, the handle to that pipe is left open in the parent process. This causes trouble when the parent is waiting for that to be closed immediately. Since none of the fds in the forked parent process matter to us, we can just go ahead and clean up all fds before we start tracing the child. URL: http://bugs.gentoo.org/364877 Reported-by: Victor Stinner <victor.stinner@haypocalc.com> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: fix early var initMike Frysinger2013-02-241-8/+25
| | | | | | | | | | In commit 5498907383c7f1654188b6a0d02d8b03112a28c3, we tried to fix handling of ELFs that had their own constructors. Unfortunately, this broke use cases like `env -i` that screw with the environment before we get a chance to extract our settings. URL: http://bugs.gentoo.org/404013 Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* add a new message env varMike Frysinger2013-02-241-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | This is used whenever sandbox wants to display an informational message. For example, early notification of a path violation, or debugging output. We can't just pop open an fd and pass that around as apps consider that leakage and will often break assumptions in terms of free fds. Or apps that start up and cleanse all of their open fds. So instead, we just pass around an env var that holds the full path to the file we want will write to. Since these messages are infrequent (compared to overall runtime), opening/writing/closing the path every time is fine. This also avoids all the problems associated with using external portage helpers for writing messages. A follow up commit will take care of the situation where apps (such as scons) attempt to also cleanse the env before forking. URL: http://bugs.gentoo.org/278761 URL: http://bugs.gentoo.org/431638 Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: handle ENOSYS w/process_vm_readvMike Frysinger2013-02-241-1/+6
| | | | | | | If we have a newer glibc built against/running on an older kernel, the func return ENOSYS at runtime. Handle that. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* delete unused sandbox env varsMike Frysinger2013-02-241-3/+0
| | | | | | Nothing uses or cares about these vars, so punt them. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* environ: add a new is_env_var helper for checking var namesMike Frysinger2013-02-241-8/+8
| | | | | | | This is laying the ground work for processing more vars in the future than just LD_PRELOAD. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: add some likely/unlikely settingsMike Frysinger2013-02-241-7/+5
| | | | Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: reject "" paths with *at funcs before checking the dirfd ↵Mike Frysinger2013-02-241-0/+34
| | | | | | | | | | | | | | [missing file] When it comes to processing errors, an empty path is checked before an invalid dirfd. Make sure sandbox matches that behavior for the random testsuites out there that look for this. Forgot to `git add` in the previous commit :/. URL: https://bugs.gentoo.org/346929 Reported-by: Marien Zwart <marienz@gentoo.org> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: reject "" paths with *at funcs before checking the dirfdMike Frysinger2012-12-245-35/+18
| | | | | | | | | | When it comes to processing errors, an empty path is checked before an invalid dirfd. Make sure sandbox matches that behavior for the random testsuites out there that look for this. URL: https://bugs.gentoo.org/346929 Reported-by: Marien Zwart <marienz@gentoo.org> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: handle open(O_NOFOLLOW)Mike Frysinger2012-12-243-1/+3
| | | | | | | | | We don't check for O_NOFOLLOW in the open wrappers, so we end up returning the wrong error when operating on broken symlinks. URL: https://bugs.gentoo.org/413441 Reported-by: Marien Zwart <marienz@gentoo.org> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: fall back to tracing set*id programsMike Frysinger2012-12-241-5/+18
| | | | | | | | | | | | | | If we are non-root and run a set*id program, the ldso will ignore our LD_PRELOAD (rightly so). Unfortunately, this opens up the ability to run set*id apps that modify things and sandbox cannot catch it. Instead, force ptracing of these ELFs. While the kernel will disallow the set*id aspect when running, for the most part, that shouldn't be a problem if it was already safe. URL: http://bugs.gentoo.org/442172 Reported-by: Nikoli <nikoli@lavabit.com> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* sandbox: allow log files to fallback to tmpdirMike Frysinger2012-12-241-2/+2
| | | | | | | | Since non-root users typically do not have write access to /var/log, allow it to fallback to standard tmpdirs. This makes testing locally a lot easier. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: use process_vm_readv if availableMike Frysinger2012-08-121-0/+26
| | | | | | | Should speed up loading of strings from remote processes as we only have to do (usually) one syscall to extract the whole string in one shot. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: fix hppa trace codeMike Frysinger2012-07-061-2/+2
| | | | | | URL: https://bugs.gentoo.org/425062 Reported-by: Jeroen Roovers <jer@gentoo.org> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: add x32 ABI supportv2.6Mike Frysinger2012-07-035-9/+75
| | | | | | | | | | | We can trace x32 when the host is x86_64 or x32, but x32 cannot trace x86_64 due to limitations in the kernel interface -- all pointers get truncated to 32bits. We'll have to add external ptrace helpers in the future to make this work, but for now, we'll just let x86_64 code run unchecked :(. URL: https://bugs.gentoo.org/394179 Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: migrate to get/set regs interface for everyoneMike Frysinger2012-07-039-103/+80
| | | | | | | | | | Newer ports (like x32) limit what is available via the peek/poke user interface, and instead are pushing people to use the single get/set regs interface. Since this also simplifies the code a bit (by forcing all ports to use this), and cuts down on the number of syscalls that we have to make, switch everyone over to it. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* precompile headers.h to speed up build slightlyMike Frysinger2012-07-033-8/+2
| | | | | | | Since all system headers are included by way of headers.h, we can pre-compile this to speed up the build up a bit. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: do not leak file handles from tracing checksMike Frysinger2012-06-231-3/+7
| | | | | | | Make sure we use O_CLOEXEC, and clean things up before forking off a tracing process. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: regenerate trace headers when autotools changeMike Frysinger2012-06-231-1/+1
| | | | | | | | | If you re-run configure with different settings, the trace headers might be out of date. Have the generated headers depend on the Makefile so that when this situation does come up, we force sanity. This step is fairly quick, so shouldn't be a big deal. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: kill off SB_MEM_DEBUGMike Frysinger2012-06-231-17/+0
| | | | | | | | The mcheck/mtrace logic assumes we're using glibc's memory allocator, but that hasn't been true for sometime (we use our own based on mmap and such), so this code no longer serves a purpose. Punt it. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* significantly overhaul output helpersMike Frysinger2012-06-2312-237/+74
| | | | | | | | | | | | | | | | | | | | There are a few major points we want to hit here: - have all output from libsandbox go through portage helpers when we are in the portage environment so that output is properly logged - convert SB_E{info,warn,error} to sb_e{info,warn,error} to match style of other functions and cut down on confusion - move all abort/output helpers to libsbutil so it can be used in all source trees and not just by libsandbox - migrate all abort points to the centralized sb_ebort helper Unfortunately, it's not terribly easy to untangle these into separate patches, but hopefully this shouldn't be too messy as much of it is mechanical: move funcs between files, and change the name of funcs that get called. URL: http://bugs.gentoo.org/278761 Reported-by: Mounir Lamouri <volkmar@gentoo.org> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: create more defines for gcc attributesMike Frysinger2012-06-231-2/+2
| | | | Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: add uninstall target to fix distcheckMike Frysinger2012-06-231-0/+4
| | | | | | Newer distcheck runs uninstall which is apparently broken. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: add missing close to logfile fdMike Frysinger2012-03-071-2/+5
| | | | | | When we log a lot, we end up leaking fd's, so make sure to clean them. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: mark internal fds with O_CLOEXECMike Frysinger2012-03-071-2/+2
| | | | | | We don't want to bleed these across forks/execs. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: set syscall error rather than killing on violationsMike Frysinger2012-03-067-18/+65
| | | | | | | | | | | | | | | If we kill the app, then the syscall that we flagged as a violation will complete, and our entire purpose has failed -- to prevent modifications to the protected paths. Instead, set the syscall number to an invalid one, continue the syscall, then set the syscall return value (which will become the errno) after the syscall finishes. This way the bad syscall isn't actually executed, and we let the app continue to run like normal. URL: http://bugs.gentoo.org/406543 Reported-by: Marijn Schouten <hkbst@gentoo.org> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: push down constructor initMike Frysinger2012-03-051-37/+6
| | | | | | | | | | | | | | Since every consumer of sb_open gets a copy of the sbio_open data, push the init of this into the .data section of the respective consumers to avoid the runtime overhead. This just leaves sandbox_lib setup in the constructor function, but that is only needed by the execve wrapper, so push down init of that to the existing sb_init logic which happens before our execve wrapper gets used. URL: http://bugs.gentoo.org/404013 Reported-by: Mike Gilbert <floppym@gentoo.org> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: delay trace_regs #error until useMike Frysinger2011-07-081-0/+4
| | | | | | | Don't error out if we're missing trace_regs, but we don't ever actually use it. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: invert debug checking order to avoid uninitialized variablesMike Frysinger2011-07-081-1/+1
| | | | | | | We only initialize debug_log_path if debug is set, so we need to check debug first to avoid uninitialized warnings with debug_log_path. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: tweak code to avoid undefined behavior warningsMike Frysinger2011-07-081-1/+1
| | | | | | | Some gcc versions don't like the construct here where we modified a variable in the middle of multiple checks. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: catch mktemp related funcsMike Frysinger2011-07-0411-0/+107
| | | | | | URL: http://bugs.gentoo.org/374059 Reported-by: Nick Bowler <nbowler@draconx.ca> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: handle NULL filenames with futimesatMike Frysinger2011-01-011-2/+5
| | | | | | | | | We need to special case a NULL filename with futimesat just like we already do with utimensat. URL: http://bugs.gentoo.org/348640 Reported-by: Jeremy Olexa <darkside@gentoo.org> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: fix utimensat regression with NULL filenameMike Frysinger2010-11-261-1/+1
| | | | | | | | | | | The previous commit (libsandbox: handle dirfd in mkdir/open/unlink *at prechecks) unified some path checks while unifying the dirfd code, but prevented valid NULL paths from also being handled. Make sure we still handle that behavior, and add a test for it to prevent future regressions. URL: http://bugs.gentoo.org/346815 Reported-by: Jake Todd <jaketodd422@gmail.com> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: fix bug in previous dirfd unificationv2.4Mike Frysinger2010-11-235-7/+8
| | | | | | | | | | | | | | The previous commit (libsandbox: handle dirfd in mkdir/open/unlink *at prechecks) left a sizeof() in place but unfortunately no longer held the same meaning. In previous code, the function had access to the buffer decl and so could get the byte count. In the new code, the function has access to the pointer only. So sizeof() now wrongly returns the size of pointers rather than the length of the buffer. Extend the new helper function to take the length of the buffer it is given to fix this issue. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: fix thinko in previous erealpath commitMike Frysinger2010-11-221-2/+2
| | | | | | | | | | The previous change for hardened users (libsandbox: avoid passing same buffer to erealpath) made a change canonicalize() to fix the buffer usage, but missed updating the actual call to erealpath to use the new buffer set up just for it. URL: http://bugs.gentoo.org/339157 Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: handle dirfd in mkdir/open/unlink *at prechecksMike Frysinger2010-11-155-58/+123
| | | | | | | | | | Ignoring the dirfd hasn't been a problem in the past as people weren't really using it, but now that core packages are (like tar), we need to handle things properly. URL: http://bugs.gentoo.org/342983 Reported-by: Xake <xake@rymdraket.net> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: tempish mkdir hack for broken symlinksv2.3Mike Frysinger2010-08-161-1/+16
| | | | | | | | | | | | | Some gnulib tests that are bundled with multiple GNU packages stress the POSIX correctness of mkdir behavior across broken symlinks. While this specific behavior under ssandbox doesn't really matter (as packages don't create broken symlinks and then need this errno value), it isn't really feasible to patch all the random packages. So add a smallish hack for now to keep them happy until something better can be formulated. URL: http://bugs.gentoo.org/297026 Reported-by: Diego E. Pettenò <flameeyes@gentoo.org> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: mark rmdir as working on symlinksMike Frysinger2010-08-161-0/+1
| | | | | | | | | Doing rmdir(symlink) does not remove the dir the symlink points to, but will operate on the symlink itself. While it will always fail (since it is a link and not a dir), that isn't something we need worry about. Just need to avoid doing permission checking on the target of the symlink. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: avoid passing same buffer to erealpathMike Frysinger2010-08-152-2/+17
| | | | | | | | | | | | | The erealpath function modifies the storage buffer given to it in place and can misbehave if both the source and destination buffers point to the same storage in memory. So fix the one case where we were doing this in the canonicalize() function and add some run time checks to make sure this doesn't crop up again. URL: http://bugs.gentoo.org/292050 Reported-by: Hongjiu Zhang <voidprayer@gmail.com> Reported-by: Fredric Johansson <johansson_fredric@hotmail.com> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: don't swallow SIGCHLD notificationsMike Frysinger2010-08-151-1/+0
| | | | | | | | | | | | When tracing static processes, the original implementation included code that would always swallow SIGCHLD. Much has changed since then, and it doesn't seem to be needed anymore, and it is certainly breaking a few packages. So drop it, add some tests, and if it causes a regression in the future, we can look at it then (with an actual test case). URL: http://bugs.gentoo.org/289963 Reported-by: Joeri Capens <joeri@capens.net> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: disable sparc ptrace until it can be debugged furtherMike Frysinger2010-08-151-0/+5
| | | | | | URL: http://bugs.gentoo.org/293632 Reported-by: Raúl Porcel <armin76@gentoo.org> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: catch calls to remove()Mike Frysinger2009-12-203-0/+15
| | | | | | | | People rarely use this, but all it takes is one lame package. URL: http://bugs.gentoo.org/297684 Reported-by: Pacho Ramos <pacho@gentoo.org> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: use mmap directly for internal memoryMike Frysinger2009-10-263-1/+23
| | | | | | | | | | | | | | | Some packages that do library tricks like sandbox override the mmap() symbols. If their implementation ends up calling functions that sandbox has overridden, then we can easily hit an infinite loop. sb-fopen -> sb-malloc -> external mmap -> sb-open -> whoops! So for the internal memory functions, make sure we call directly to the C library's mmap() functions. This way our internal memory implementation should be free from external forces. URL: http://bugs.gentoo.org/290249 Reported-by: Diego E. Pettenò <flameeyes@gentoo.org> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: rewrite RTLD_NEXT handlingMike Frysinger2009-10-261-21/+33
| | | | | | | | | | | | The commit 0a539b142f24 tried to fix RTLD_NEXT issues seen under certain kernel/glibc combos, but in reality all it did was force dlopening of the C library for every symbol lookup. So rewrite the code to handle things on the fly as needed -- if RTLD_NEXT returned a bum symbol, load the C library and try again. URL: http://bugs.gentoo.org/202765 URL: http://bugs.gentoo.org/206678 Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: fix ptrace decode of utimensatMike Frysinger2009-10-251-1/+1
| | | | | | | | | The ptrace code skipped one too many arguments when decoding the utimensat syscall which caused random utils to fail with garbage paths. URL: http://bugs.gentoo.org/288227 Reported-by: RB <aoz.syn@gmail.com> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: handle fd's w/out files in proc fd/Mike Frysinger2009-10-251-0/+15
| | | | | | | | | | | | | | When attempting to access anonymous pipes/sockets/etc..., we should let the access go through rather than rejecting the patch because we aren't able to access it. There is no backing file after all which means there is nothing for sandbox to check against. While this was noticed with an anonymous pipe, the logic applies to any anonymous fd such as sockets or whatever the kernel throws at us. URL: http://bugs.gentoo.org/288863 Reported-by: Marcin Mirosław <bug@mejor.pl> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libsandbox: add support for tracing SPARC systemsMike Frysinger2009-10-254-15/+55
| | | | Signed-off-by: Mike Frysinger <vapier@gentoo.org>