From owner-svn-src-stable-10@freebsd.org Tue Nov 3 08:31:02 2015 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 82005A25882; Tue, 3 Nov 2015 08:31:02 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 47D6E1A1B; Tue, 3 Nov 2015 08:31:02 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tA38V1sM058581; Tue, 3 Nov 2015 08:31:01 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tA38V1qm058580; Tue, 3 Nov 2015 08:31:01 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201511030831.tA38V1qm058580@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Tue, 3 Nov 2015 08:31:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r290324 - stable/10/sys/kern X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Nov 2015 08:31:02 -0000 Author: kib Date: Tue Nov 3 08:31:01 2015 New Revision: 290324 URL: https://svnweb.freebsd.org/changeset/base/290324 Log: MFC r289660,r289664: Do not allow to execute ptrace(PT_TRACE_ME) when the process is already traced or when there is no parent which can trace the process. Modified: stable/10/sys/kern/sys_process.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/kern/sys_process.c ============================================================================== --- stable/10/sys/kern/sys_process.c Tue Nov 3 08:28:47 2015 (r290323) +++ stable/10/sys/kern/sys_process.c Tue Nov 3 08:31:01 2015 (r290324) @@ -442,7 +442,7 @@ ptrace_vm_entry(struct thread *td, struc } #ifdef COMPAT_FREEBSD32 -static int +static int ptrace_vm_entry32(struct thread *td, struct proc *p, struct ptrace_vm_entry32 *pve32) { @@ -743,7 +743,18 @@ kern_ptrace(struct thread *td, int req, */ switch (req) { case PT_TRACE_ME: - /* Always legal. */ + /* + * Always legal, when there is a parent process which + * could trace us. Otherwise, reject. + */ + if ((p->p_flag & P_TRACED) != 0) { + error = EBUSY; + goto fail; + } + if (p->p_pptr == initproc) { + error = EPERM; + goto fail; + } break; case PT_ATTACH: