From nobody Sat Jan 29 01:11:14 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id C2DEC1990B52; Sat, 29 Jan 2022 01:11:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Jlx9G3zmkz4klf; Sat, 29 Jan 2022 01:11:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643418674; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=o0/jLz2BpGEcvCIheadg+whr/tpKkafTQXVsKKsr3Dk=; b=buSPRtlKL7/YnZ3EeRV71lCGQ3rFBlhRg0FGU7a5cAYb4T3ytIJp+UOLtWhyBhCBk+wgvX RYwXP11nSkkdCTNuoXarewyZbHfGxB2/qVebBHap2dufPkDhFfP/a38Ofi3hZqCSTd5f8o J5uipbOxOxL2APOHUFaMKnXLB8P2cEvGEOjgzgPQOS8Namq5jhMl/O6iYOqu3gOpkBEgM7 /m+ahDK9ryKD8fviCLwR5XYCebXVE+XzmNiLMlB8vbZdZGtfjHELWg/6rcbiKETjyyInCq xg/mn2uzfrNAyJcOE1wYxKGoY2RbvddtH08HU+88Cux+3jxWjEb7bisgjsDpCg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 51E2F47E3; Sat, 29 Jan 2022 01:11:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20T1BE5O039448; Sat, 29 Jan 2022 01:11:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20T1BEOE039447; Sat, 29 Jan 2022 01:11:14 GMT (envelope-from git) Date: Sat, 29 Jan 2022 01:11:14 GMT Message-Id: <202201290111.20T1BEOE039447@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: fbdc76539b8a - stable/13 - Add security.bsd.allow_ptrace sysctl List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: fbdc76539b8ad1364da0fb00f2c7e367df9d8fad Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643418674; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=o0/jLz2BpGEcvCIheadg+whr/tpKkafTQXVsKKsr3Dk=; b=F6gf3eYPOa4Rxavmr4BGmmsLPKt8qcCF+RGb/CZXWgs8dyfbtLk4yKBgmXC1uREjNOItdj Hy59QtG0+GpCvQOjD41tSAe+jm9o8Gr/LzNtqj6KYaouYJQ8Gx+3vBQSxrS6ekOlNKukvl t07ghOTl0ZDbVThc/o2HyIFItBBpq9WxayvVmaAdHO2bzOtT06bETyz57FJlUWPaQAh3xa VLEhBGnaCnLWWkUkngJiFoOqw9YuGcZ3+y2Y9gKSy8cF/np9JdKn/os8j09YNcv37UCKW7 9lV4HEi1NlIs55Y4NtYc9uAlt/KJ3CVgIQHqn94AimXDnt6VXdguTd8EcoCf/Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1643418674; a=rsa-sha256; cv=none; b=rz9++B91cjqO0Q2NvnEEPl1vbVaQ4f9gY//TvYWZJ9gAqJkgkLgu2v4FZ2ckqXa2rOiIQm drKRLZ6HZb9Sqx9y4lhnzC/Ps7cLz/ZpO0+xjsvWHBinrKHdEZ7bpgOeu1QsGokuZyKlxA hjnJkbjT38nVBBi7czE/tX6lind8Hy7h3WBOiq+YTUt2WUBDnaImMtt8oGl5hgZAK61HpT nbCH39A6uGsG/M1xDQAOEWX1T1eL+Ap4vbNOKYKf8D6Tfx3wfbbPC2hsiLMyJmzjE8qxPT 8HN4pwcLDXC3vE54BFIkDl5zHe6LTEWdc2UdnwmBRFA8s4hSqEAp3uwAPfbSIQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=fbdc76539b8ad1364da0fb00f2c7e367df9d8fad commit fbdc76539b8ad1364da0fb00f2c7e367df9d8fad Author: Konstantin Belousov AuthorDate: 2022-01-21 21:52:35 +0000 Commit: Konstantin Belousov CommitDate: 2022-01-29 01:10:44 +0000 Add security.bsd.allow_ptrace sysctl (cherry picked from commit fe6db727081936c43250f97a4ff4b9de20eb0091) --- sys/amd64/linux/linux_ptrace.c | 3 +++ sys/compat/freebsd32/freebsd32_misc.c | 6 +++++- sys/kern/kern_prot.c | 6 ++++++ sys/kern/sys_process.c | 6 +++++- sys/sys/ptrace.h | 2 ++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/sys/amd64/linux/linux_ptrace.c b/sys/amd64/linux/linux_ptrace.c index d209590e3680..e158059ec423 100644 --- a/sys/amd64/linux/linux_ptrace.c +++ b/sys/amd64/linux/linux_ptrace.c @@ -573,6 +573,9 @@ linux_ptrace(struct thread *td, struct linux_ptrace_args *uap) pid_t pid; int error, sig; + if (!allow_ptrace) + return (ENOSYS); + pid = (pid_t)uap->pid; addr = (void *)uap->addr; diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c index 5e70a3194c1a..2360d28c15d0 100644 --- a/sys/compat/freebsd32/freebsd32_misc.c +++ b/sys/compat/freebsd32/freebsd32_misc.c @@ -937,7 +937,11 @@ freebsd32_ptrace(struct thread *td, struct freebsd32_ptrace_args *uap) struct ptrace_sc_ret32 psr; } r32; void *addr; - int data, error = 0, i; + int data, error, i; + + if (!allow_ptrace) + return (ENOSYS); + error = 0; AUDIT_ARG_PID(uap->pid); AUDIT_ARG_CMD(uap->req); diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index 484ebed95118..b39cc635e778 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -58,6 +58,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -2485,3 +2486,8 @@ change_svgid(struct ucred *newcred, gid_t svgid) newcred->cr_svgid = svgid; } + +bool allow_ptrace = true; +SYSCTL_BOOL(_security_bsd, OID_AUTO, allow_ptrace, CTLFLAG_RWTUN, + &allow_ptrace, 0, + "Deny ptrace(2) use by returning ENOSYS"); diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index 2515a9cf1e4f..eb628c040cd9 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -480,7 +480,11 @@ sys_ptrace(struct thread *td, struct ptrace_args *uap) int ptevents; } r; void *addr; - int error = 0; + int error; + + if (!allow_ptrace) + return (ENOSYS); + error = 0; AUDIT_ARG_PID(uap->pid); AUDIT_ARG_CMD(uap->req); diff --git a/sys/sys/ptrace.h b/sys/sys/ptrace.h index 1e7c1c71056b..4cd7a3fceaec 100644 --- a/sys/sys/ptrace.h +++ b/sys/sys/ptrace.h @@ -243,6 +243,8 @@ int proc_write_dbregs32(struct thread *_td, struct dbreg32 *_dbreg32); void ptrace_unsuspend(struct proc *p); +extern bool allow_ptrace; + #else /* !_KERNEL */ #include