Date: Tue, 30 Dec 2014 17:58:40 +0200 From: Konstantin Belousov <kostikbel@gmail.com> To: Shawn Webb <lattera@gmail.com> Cc: Jilles Tjoelker <jilles@stack.nl>, freebsd-arch@freebsd.org Subject: Re: Disabling ptrace Message-ID: <20141230155840.GI42409@kib.kiev.ua> In-Reply-To: <3368390.qHnOScdmzK@shawnwebb-laptop> References: <20141230111941.GE42409@kib.kiev.ua> <20141230140709.GA96469@stack.nl> <3368390.qHnOScdmzK@shawnwebb-laptop>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Dec 30, 2014 at 10:38:56AM -0500, Shawn Webb wrote: > On Tuesday, December 30, 2014 03:07:10 PM Jilles Tjoelker wrote: > > On Tue, Dec 30, 2014 at 01:19:41PM +0200, Konstantin Belousov wrote: > > > The question about a facility to disable introspection functionality > > > (ptrace etc) for a process was asked several times. The latest query > > > made me actually code the feature. Note that other systems, e.g. Linux > > > and OSX, do have similar facilities. > > > > > > Patch is below, it provides two new procctl(2) requests. > > > PROC_TRACE_ENABLE enables or disables tracing. It includes core > > > dumping, ptrace, ktrace, debugging sysctls and hwpmc. > > > PROC_TRACE_STATUS allows to get the tracing state. > > > > > > Most interesting question is how should disabling of trace behave > > > with regard of fork and exec. IMO, the right model is to protect > > > access to the _program_ address space, which translates to inheritance > > > of the attribute for fork, and reenabling the tracing on exec. > > > > I agree. I imagine this will be useful for programs like ssh-agent, to > > protect their unlocked key material. > > > > This is also what Linux provides, and it is simpler than this patch: > > prctl(PR_SET_DUMPABLE) lets a process make their issetugid() equivalent > > return true, including preventing tracing by unprivileged users. You > > could call that unification a hack. > > > > > On the other hand, I understand that some users want to inherit the > > > tracing disable on exec, so there are PROC_TRACE_SET_DISABLED and > > > PROC_TRACE_SET_DISABLED_EXEC, the later makes disable to be kept after > > > exec. > > > > This is apparently meant to protect a whole process tree as a hardening > > measure, or instead of PROC_TRACE_SET_DISABLED if it is undesirable to > > modify the program with key material. > > > > > Note that it is trivial for root on the host to circumvent the feature. > > > > I'd prefer if root can still trace normally, without needing any hacks. > > Philosophically, FreeBSD should serve the system administrator first and > > only then the application programmer. Also, the debugging facilities may > > be needed to debug FreeBSD itself (e.g. procstat -k), not just the > > application. > > It's easy even for non-root to disable or work around ptrace disabling. > LD_PRELOAD, nopping out the instructions, dtrace, etc. Note that for SUID > applications, such tricks don't work. The point is that such protections are > very easily disabled, even by non-root users for non-SUID applications. Google for 'It rather involved being on the other side of this airtight hatchway'. > > I'm curious what the use case was that brought this up. And why the requester > thinks it's actually useful. > > We at HardenedBSD have introduced a ptrace hardening patch that limits those > who can use ptrace to a certain group. We've also added hardening around > [lin]procfs. I believe those to be effective against ptrace abuse to a greater > extent. It doesn't, though, handle dtrace, something we still need to > research. > > Thanks, > > Shawn
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20141230155840.GI42409>