Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp845513ybg; Mon, 1 Jun 2020 16:21:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGaidmzzm4qAeo8dgBjXGubooMzK/znAp+rrqDyWd/jyKzAVCZoZOH5dmQTwbAofFlqLDy X-Received: by 2002:a17:906:e2d5:: with SMTP id gr21mr10973220ejb.219.1591053671463; Mon, 01 Jun 2020 16:21:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591053671; cv=none; d=google.com; s=arc-20160816; b=ExG7HIcmUPUnYMud0bwBPR3DR5rrQblKROnzOfNJykP1xp49d46wpEFTYqRH0PsEs2 Qcz09BqNZkUjly1ey2WPh+lu5+jjnGGZNmngaw8CwVKJOh9DVaCmBBVhV4npzawVLCXZ 6brnKA6QtVo15eoowUqqI7cVxPxB7JAW8bHgvuwmJycZaC3GjEXSb0mX9J9D7mFYInwo ildnBgvHrU7WknmyqacCrPYrmuTzbrTHc5uIGnBQkP6S+eMdj7vpPfriTs3UNiLEFIIu bCEHVMwrxqf9XXLtW+29Hrdb7n49X/LPAh8BgPrRxHJ2EMkjGiNIPDFM33hbcN84Ja/m uUcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=zWcQoGtuyIzKuylqOf+u13ZR8Ge5LtJMQ2QXL8UT810=; b=aULLWi0+g+estM9jQMV7MGZLevcrH0fQexPB2AU/84U15S8igfmR6lLHmhOxzSgwxW iQ1ys0bE07jvIkIU6Z/dyk84BQ/g5yXLO1N0ay9TOkKIrjnkL1xJe4NtEICyXtkPtmB5 yOaO1QJnOSS5fFLGASSIjS2IiJhS9yFOVabQfsftCJi05wFHKYrwQzaFwhe9RNzG6SDh mVQSUZiW0N00q5vrWfwihjSStL8PqHQc8lh/rJ/3p3x0PgUVOaukBPDipYCVFb9NoYhR ILxnZZYvG6rZgUZV0M9MuJUHGv5mZvE6N+3EwRTFcEm1c2uKWRJbq7o/4AsO0iawSDc2 q53Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=L3qZgGCD; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j21si507357ejc.497.2020.06.01.16.20.48; Mon, 01 Jun 2020 16:21:11 -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=@kernel.org header.s=default header.b=L3qZgGCD; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728428AbgFAXSm (ORCPT + 99 others); Mon, 1 Jun 2020 19:18:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:54250 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726099AbgFAXSm (ORCPT ); Mon, 1 Jun 2020 19:18:42 -0400 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EBB55207BB for ; Mon, 1 Jun 2020 23:18:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591053521; bh=vG7dpOcajSi/mt4/We78ONhQ6W10E0sko1pNjj1dhKo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=L3qZgGCD1KwPW+AzHVpCLxbtFMIbF8YoDBXINYIN9StTf6HaAHbtZYUevfjha89GT P4SXM5QubUZ7cE7/FYz9/lp6VGJohG7ThZqriBrgsA5x6aZQ7dmbKCmUMCL7/mTr2i gwuBMglfxUU18LuGxEbZ0DAhZL3Wc7Y2BHOtUXKw= Received: by mail-wr1-f45.google.com with SMTP id h5so1467735wrc.7 for ; Mon, 01 Jun 2020 16:18:40 -0700 (PDT) X-Gm-Message-State: AOAM5327qk8uENiABX3Wxx5KvkWSfGeRTvk4GwkXaIDa/TYi8ldrU4Cd T2y0FRQtwJu2oh+IlYC79kjB+DB9j5F/CU1hzSSmYw== X-Received: by 2002:adf:ea11:: with SMTP id q17mr23050302wrm.75.1591053519479; Mon, 01 Jun 2020 16:18:39 -0700 (PDT) MIME-Version: 1.0 References: <85367hkl06.fsf@collabora.com> <079539BF-F301-47BA-AEAD-AED23275FEA1@amacapital.net> <50a9e680-6be1-ff50-5c82-1bf54c7484a9@gmail.com> <202006011306.2E31FDED@keescook> In-Reply-To: <202006011306.2E31FDED@keescook> From: Andy Lutomirski Date: Mon, 1 Jun 2020 16:18:27 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH RFC] seccomp: Implement syscall isolation based on memory areas To: Kees Cook Cc: Andy Lutomirski , Paul Gofman , Gabriel Krisman Bertazi , Linux-MM , LKML , kernel@collabora.com, Thomas Gleixner , Will Drewry , "H . Peter Anvin" , Zebediah Figura Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 1, 2020 at 1:08 PM Kees Cook wrote: > > On Sun, May 31, 2020 at 02:03:48PM -0700, Andy Lutomirski wrote: > > On Sun, May 31, 2020 at 11:57 AM Andy Lutomirski wrote: > > > > > > > > > What if there was a special filter type that ran a BPF program on each > > > syscall, and the program was allowed to access user memory to make its > > > decisions, e.g. to look at some list of memory addresses. But this > > > would explicitly *not* be a security feature -- execve() would remove > > > the filter, and the filter's outcome would be one of redirecting > > > execution or allowing the syscall. If the "allow" outcome occurs, > > > then regular seccomp filters run. Obviously the exact semantics here > > > would need some care. > > > > Let me try to flesh this out a little. > > > > A task could install a syscall emulation filter (maybe using the > > seccomp() syscall, maybe using something else). There would be at > > most one such filter per process. Upon doing a syscall, the kernel > > will first do initial syscall fixups (e.g. SYSENTER/SYSCALL32 magic > > argument translation) and would then invoke the filter. The filter is > > an eBPF program (sorry Kees) and, as input, it gets access to the > > FWIW, I agree: something like this needs to use eBPF -- this isn't > being designed as a security boundary. It's more like eBPF ptrace. On a bit more consideration, I think that I have the model a bit wrong. We shouldn't think of this as a *syscall* filter but as a filter for architectural privilege transitions in general. After all, there is no particular guarantee that any given emulated program has a syscall ABI that is even remotely compatible with Linux. So maybe the filter is fed events like SYSCALL64, SYSCALL32, SYSENTER, #GP, #PF (the bad kind that would otherwise get a signal), #UD, etc. And the filter can examine process state and take some reasonable action. Think if it as a personality scheme that's programmable by user code. I imagine that even schemes like NaCl could make some use of this. This allows all kinds of interesting things. For example, it should give Wine a much nicer emulation of Windows SEH and vectored signals. And maybe it could finally allow Linux userspace to have some sensible equivalent of those Windows features -- being able to write library code that could sanely handle, say, math errors would be quite handy. This could be mocked up with cBPF, but I think a cBPF version will struggle to be a performant solution for Wine because it will have a hard time distinguishing between Windows and Linux syscalls. --Andy