From owner-freebsd-arch@FreeBSD.ORG Tue Dec 30 15:39:07 2014 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B507183D for ; Tue, 30 Dec 2014 15:39:07 +0000 (UTC) Received: from mail-qc0-x229.google.com (mail-qc0-x229.google.com [IPv6:2607:f8b0:400d:c01::229]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 664AC1E41 for ; Tue, 30 Dec 2014 15:39:07 +0000 (UTC) Received: by mail-qc0-f169.google.com with SMTP id w7so10685334qcr.28 for ; Tue, 30 Dec 2014 07:39:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:user-agent:in-reply-to :references:mime-version:content-type; bh=YdV8fxBib6dNpqEkh5USML09Q4q0tqt7H7saymH10S8=; b=jvBMnmDIuax1S1Z+gphFfmWUnKI4kKGc0I1tt5zepbf1+MdN8gYgRmRZ+UYwIL7SIv 3IztpX9v6SNl51PCMt0p3Mfex2hiYLJmIb01BzO5a9tfLjXACmlPNy9yyU9bQfaHGjuO RAMgAddkZtHbJDVgW540Fk89abBIEjFjJGohpqbmot8dakJUH3cyuhOzdK5+F8BG5jv/ laDrFmPpWrzD4Y/te7tX0VevLvvY+N5axO55C7TGP6o2wVqfiWq8FCwKjrfWH2aVR3Qm N+BVObY1VUVyLXS9eF78j7sO8HJRjmqMyVS8kW/ezQgPuMk9iN5lY16Ob07YQNGGYACL dnCw== X-Received: by 10.140.92.202 with SMTP id b68mr95875023qge.10.1419953946590; Tue, 30 Dec 2014 07:39:06 -0800 (PST) Received: from shawnwebb-laptop.localnet ([73.173.99.185]) by mx.google.com with ESMTPSA id k88sm36195660qge.13.2014.12.30.07.39.05 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Dec 2014 07:39:05 -0800 (PST) From: Shawn Webb To: freebsd-arch@freebsd.org Subject: Re: Disabling ptrace Date: Tue, 30 Dec 2014 10:38:56 -0500 Message-ID: <3368390.qHnOScdmzK@shawnwebb-laptop> User-Agent: KMail/4.14.2 (FreeBSD/11.0-CURRENT; KDE/4.14.2; amd64; ; ) In-Reply-To: <20141230140709.GA96469@stack.nl> References: <20141230111941.GE42409@kib.kiev.ua> <20141230140709.GA96469@stack.nl> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart12681731.czNAJhFhVz"; micalg="pgp-sha256"; protocol="application/pgp-signature" Cc: Konstantin Belousov , Jilles Tjoelker X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Dec 2014 15:39:07 -0000 --nextPart12681731.czNAJhFhVz Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" 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. 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 --nextPart12681731.czNAJhFhVz Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAABCAAGBQJUoscQAAoJEGqEZY9SRW7ukGAP/AqEpfrkmjxZCjykuTs66Nxx CvSKtToVU3Rh3ymcS0QrOZAp8DlDFkFl00ZY+5/hdvEpLeMQ02yRiPikzbEpTjQ9 fcsPW2pRRR5GLwPWBxfeXPE5KfIxN8f22lFbCO4Xaf9PIUR4jzxwM9JpvjO3ZtJB zwfTinR3PsOnYf5zvROp/QmdYgjbI1BXft9Yhwyn6MblIG7WL2HfWYO6NpDOz1R/ KyUlw/GI+KNyXSIwhe9zm+eD/ASx1rlh5vQyZlyDevGSJdgCgpbwylPE2rjp+ikx YrVMZhEgUSTOia/cOQoq6QsLJiq0FU/YQZgPg39OcyA2YS9t/u+Di0Ut2/AJ7qtv TqxYq7ylr+QDIfreYqJwPzMQBnFPY67cReDq2P5m2jgychvmWmYqK5SbW+SPm740 NSlGg/wbpfVbJ84hxXIz+KTpcftzxheuatFDVW38FBsxAIjz40OGoWafA6jdtAH1 Xj/lLW2OjJMm+hVgFOFmJjlFJIcDifKq6SPyH/Gi00ZUlQGukmqsj/TzLbVa/WPX 0Omcfye9yTFAafMZqszlrS8i5qU8pf0dVUQy6Po46W14CqZKa7YVhFTP7R5W0ZOS gk53U6itNTURFlXixblMMYLgCdpkoTREVWO9iUl4pKbPIdpggXkCFg+LRgutJgkI cTa1vQdKG4sgLiS6UbV3 =VgnI -----END PGP SIGNATURE----- --nextPart12681731.czNAJhFhVz--