From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=3.0 tests=BAYES_00,DATE_IN_PAST_03_06, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83EDEC4363A for ; Thu, 29 Oct 2020 02:07:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3668E20709 for ; Thu, 29 Oct 2020 02:07:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727063AbgJ1ViD (ORCPT ); Wed, 28 Oct 2020 17:38:03 -0400 Received: from brightrain.aerifal.cx ([216.12.86.13]:38084 "EHLO brightrain.aerifal.cx" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726997AbgJ1ViB (ORCPT ); Wed, 28 Oct 2020 17:38:01 -0400 Date: Wed, 28 Oct 2020 13:52:41 -0400 From: Rich Felker To: Jann Horn Cc: Camille Mougey , Kees Cook , lkml , Tycho Andersen , Sargun Dhillon , Christian Brauner , "Michael Kerrisk (man-pages)" , Denis Efremov , Andy Lutomirski Subject: Re: [seccomp] Request for a "enable on execve" mode for Seccomp filters Message-ID: <20201028175241.GD534@brightrain.aerifal.cx> References: <20201028164936.GC534@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 28, 2020 at 06:34:56PM +0100, Jann Horn wrote: > On Wed, Oct 28, 2020 at 5:49 PM Rich Felker wrote: > > On Wed, Oct 28, 2020 at 01:42:13PM +0100, Jann Horn wrote: > > > On Wed, Oct 28, 2020 at 12:18 PM Camille Mougey wrote: > > > You're just focusing on execve() - I think it's important to keep in > > > mind what happens after execve() for normal, dynamically-linked > > > binaries: The next step is that the dynamic linker runs, and it will > > > poke around in the file system with access() and openat() and fstat(), > > > it will mmap() executable libraries into memory, it will mprotect() > > > some memory regions, it will set up thread-local storage (e.g. using > > > arch_prctl(); even if the process is single-threaded), and so on. > > > > > > The earlier you install the seccomp filter, the more of these steps > > > you have to permit in the filter. And if you want the filter to take > > > effect directly after execve(), the syscalls you'll be forced to > > > permit are sufficient to cobble something together in userspace that > > > effectively does almost the same thing as execve(). > > > > I would assume you use SECCOMP_RET_USER_NOTIF to implement policy for > > controlling these operations and allowing only the ones that are valid > > during dynamic linking. This also allows you to defer application of > > the filter until after execve. So unless I'm missing some reason why > > this doesn't work, I think the requested functionality is already > > available. > > Ah, yeah, good point. > > > If you really just want the "activate at exec" behavior, it might be > > possible (depending on how SECCOMP_RET_USER_NOTIF behaves when there's > > no notify fd open; I forget) > > syscall returns -ENOSYS. Yeah, that'd probably do the job. (Even > though it might be a bit nicer if userspace had control over the errno > there, such that it could be EPERM instead... oh well.) EPERM is a major bug in current sandbox implementations, so ENOSYS is at least mildly better, but indeed it should be controllable, probably by allowing a code path for the BPF to continue with a jump to a different logic path if the notify listener is missing. Rich