Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp298154pxx; Thu, 29 Oct 2020 02:58:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxf4VEOev5Y4bHcOxhhA/PsqVoWDRbuud1KD3Qlr50p4PgEqUEPKq+AG2L4UwcV9CR9pQ+C X-Received: by 2002:aa7:d843:: with SMTP id f3mr3207922eds.354.1603965528438; Thu, 29 Oct 2020 02:58:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603965528; cv=none; d=google.com; s=arc-20160816; b=RDVhj7VRRIfzh5ZkKfVBc8dirld/UpRjJ/4iXPPKvPO2e/nvrbXAyh8oukT8YcFaKe PRKYCPnH3ndx2UUgOYM+X/puhSk13ww+KnGsYkY0JQ7PnDXzesYY81la+wxtLXwXBO1p xQ0znSdDIXVJoGeMkYi20JYCFCrr//cNWtty1CqRYI9FJf1QaLval+n9HPZFD3Re83/7 y29/uQTvUYN9cP8tI4R02zdxyPRcboiwWnRKnen69dPAecMK1Di35bke7ehMZtphVohQ OHpogetwaH1U7R7rakE1L3ALq78l5QZms0syipk8lZeYmSs8Ipef6vf0RaeyivyYs4Xk hnkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=QS4EnFX6AmlcEUTn4kjwTeWHhMAjTaD3XA3AGB+7TY0=; b=S4urScOm8x7cb9SMy5XRFUy8kXyikDbfBJ3xaXj5eKeCkIQJoUHhyxBl4b8nhCio+d dPVSJ5cZeHE8minySi1UWbA1hKuzpuCaCeRJMKBv1rDX+mpi8tu5FXEz4LglMQTxv2nP PiwsPkpXAVur3NxN2nzrDHdMswGuoKpjpffYV0uvFi0u6VRZ0C0PDog36pNyFPVBt0GB 2xpmmQ7kkxT0c+2TUWsil7bcU2j0z80bwDR+khRirgehlfMD0mWOri2TZEhvyAfSFKcQ p22bNarFXOjgKfjHwuM/dBjy9/iaD/utK9hEdl55Kzn3FJf1SijO5PAXY3JRdsh/Podu MjDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KZ3UwAfj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r7si1424916eji.675.2020.10.29.02.58.26; Thu, 29 Oct 2020 02:58:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KZ3UwAfj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388972AbgJ1Win (ORCPT + 99 others); Wed, 28 Oct 2020 18:38:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388950AbgJ1WiW (ORCPT ); Wed, 28 Oct 2020 18:38:22 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1022C0613CF for ; Wed, 28 Oct 2020 15:38:21 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id s9so732255wro.8 for ; Wed, 28 Oct 2020 15:38:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QS4EnFX6AmlcEUTn4kjwTeWHhMAjTaD3XA3AGB+7TY0=; b=KZ3UwAfj5i+27klN0a4tHXuGvuCSU0mg8fvYSBx4qvDhaq/mwBMAWFYqRVtNV+ESBQ +9O9IfocZjEAQPwma+h6htQNL+WIcAGDhMvJvO4FMvd61nvKItJvYP9x6XJLuLMonnQt galgbj3msWdda+NdxziyuM1YkzYG4mxjWMpvAz5Nl8ZgpkGDyYUplIfCfNSk1BwSB3jI +MIjJchtbYHFovczUlnObt3lkaqAR3xoLfxl7RZoK/RsXTMISUmd4ICm4KU8pNjBqg8n YD7F3VrRPi5T+IDEh6iOqu9J5weC6Cuh7MrmEPwZB/yMAqC9rIIeZbX3gSRRV4zB4Gp8 Ap8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QS4EnFX6AmlcEUTn4kjwTeWHhMAjTaD3XA3AGB+7TY0=; b=GswvPkpLfPAVhvWEKKzjafEOtpzlJ/U5hIVYow0R6XEeEd2Q87yARMknGeRJQpo5x6 ELY91SoSkycfMEd+r2TQXxoM3vzCH1M07DrET+vv9hXkP0Zj0QdBWKDQKQhoZUfEG34I lR2DCUXzkd136HP3ggVBWD/H53QC06873ijXDH9kn28YdzaEtHx1SFNvGU19jJvQuUsa oKrwKVLvIpgwcUXOL/6/y71ugNL7kqN8hk/7HZ79LF8JYDH0/d7UqyruxwAW+QHnIXOC EEEvM3MoylNeeprQTwbVRoHW+XklP3G1Et9LeFnENTeUZvCSEiAqyH0D/YpH8hLGqnuX ACYw== X-Gm-Message-State: AOAM531IutS7jmMeHkakxAlfM1LSSx1yhnQo6YwvdPeK9n+NVujKPmO2 ml7JDNMU9XWDwFRCGjOhytkNbx3fvaRmZBiMzOgbhvO+vuLCLA== X-Received: by 2002:a19:c357:: with SMTP id t84mr154089lff.34.1603909572173; Wed, 28 Oct 2020 11:26:12 -0700 (PDT) MIME-Version: 1.0 References: <20201028164936.GC534@brightrain.aerifal.cx> <20201028175241.GD534@brightrain.aerifal.cx> In-Reply-To: <20201028175241.GD534@brightrain.aerifal.cx> From: Jann Horn Date: Wed, 28 Oct 2020 19:25:45 +0100 Message-ID: Subject: Re: [seccomp] Request for a "enable on execve" mode for Seccomp filters To: Rich Felker Cc: Camille Mougey , Kees Cook , lkml , Tycho Andersen , Sargun Dhillon , Christian Brauner , "Michael Kerrisk (man-pages)" , Denis Efremov , Andy Lutomirski Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 28, 2020 at 6:52 PM Rich Felker wrote: > 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. I guess we might be able to expose the listener status through a bit / a field in the struct seccomp_data, and then filters could branch on that. (And the kernel would run the filter twice if we raced with filter detachment.) I don't know whether it would look pretty, but I think it should be doable...