From owner-freebsd-bugs@FreeBSD.ORG Fri May 30 23:10:01 2014 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7CC229FA for ; Fri, 30 May 2014 23:10:01 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (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 67E9A29D0 for ; Fri, 30 May 2014 23:10:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.8/8.14.8) with ESMTP id s4UNA0aU071080 for ; Fri, 30 May 2014 23:10:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.8/8.14.8/Submit) id s4UNA0oc071079; Fri, 30 May 2014 23:10:00 GMT (envelope-from gnats) Date: Fri, 30 May 2014 23:10:00 GMT Message-Id: <201405302310.s4UNA0oc071079@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Jilles Tjoelker Subject: Re: kern/121073: [kernel] [patch] run chroot as an unprivileged user Reply-To: Jilles Tjoelker X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 May 2014 23:10:01 -0000 The following reply was made to PR kern/121073; it has been noted by GNATS. From: Jilles Tjoelker To: bug-followup@FreeBSD.org, jille@quis.cx Cc: Subject: Re: kern/121073: [kernel] [patch] run chroot as an unprivileged user Date: Sat, 31 May 2014 01:02:46 +0200 In FreeBSD PR kern/121073, you wrote: > We (Ed and I) thought it should be possible to chroot as non-root, > This should (hopefully) increase the security, because no setuid-root > and privilege dropping after the chroot(2) call is longer needed. This change may be useful for package building without root. The disable setuid/setgid part looks similar to Linux's prctl(PR_SET_NO_NEW_PRIVS). In Linux, this is a separate operation that is a precondition for certain operations if unprivileged. I found two possible security risks with this: Firstly, unprivileged chroot might be used to break out of a chroot. For example, a directory file descriptor may be put onto a unix socket (to defeat kern.chroot_allow_open_directories), chroot to a subdirectory, get the file descriptor back, fchdir and abuse "..". If this is the first chroot, fd_jdir will stop it but other chroots (but not nested jails) can be escaped from. This can be fixed by only allowing a first or second chroot (fdp->fd_jdir == NULL || fdp->fd_jdir == fdp->fd_rdir). Due to locking this check must be in change_root(). Secondly, a mac_vnode_execve_will_transition could lower as well as increase privilege; it may be better to reject the exec entirely if a MAC transition is denied. -- Jilles Tjoelker