Received: by 2002:a17:90a:bc8d:0:0:0:0 with SMTP id x13csp2411338pjr; Tue, 19 May 2020 14:42:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwN9jtlP7Cm1FfX3wJj2Xq58PdiCh+LjLRV6i21vxhwnlCeIa3qvcAi3eY95H5gyTelpafB X-Received: by 2002:a17:906:580e:: with SMTP id m14mr1164028ejq.457.1589924546576; Tue, 19 May 2020 14:42:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589924546; cv=none; d=google.com; s=arc-20160816; b=a09UUwoPX8FPzaRgLiRnnfIOUwQs1d40AUPf9VJIkOmbLJUWser2gKGOkcKco2rlbI 0zUQEHsCgRGFODUOHFdjholTpajsrD52ViCexchLgdOsM+qNtjDnQ5FmcbXKaZKGPASV XUoj6YkaVA8FxXeI7oKAtdIeNiciA3ZyvhnO5uuK5ASgfbpTGUb8vIqSnxYAPloDgAw3 LMalhBHQ1om0IDJXHzAkYYB9vynFdUWMLB/VBnX3BIJ12e0bAmOJ/ft9Iw4EjbLeEUEB iWF11lSzIO3m6owtcGze11RgyrdnqdBjQoP+ck47AhjL6i+yMoWZnjBnMjx9Yfa0MVr0 mXdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=qZrnOBqdIK/f9ZKEYvAl0vw/13DRB3RwIGSmwGXyTpI=; b=yyPXibtorR//IBMQf2gRc5Ar8jl4/OAShEZWABvY1vP4MG4zRSUbbtqGQWJgrxXXNL 6Jy1BTbeNiR4gXGI+iWHsVcJbD2259rXE83Z80WzlVWyHOhmGpxPOF2mKrqeaQr8ZwfF Mksn5J6nD/eaphGD8VSROOIwP/0Mk7sXc2VazLaIDx5x6xkpFnaessF2YSrZgEUAFaWE BQan/Ftyd6eBUov58zEkguxnMt4sViPuYACqvlbN0lfu+O5MKhUbaic2iCFqa3QrR/wF lbYfv5OE9/5iSIq7tM7U1556HknL4zdP2WiJknn5f+ckNGY4gRLXG6f9SCpZScMSEAoR CcFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YD0FWr1n; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a24si658032ejg.46.2020.05.19.14.42.03; Tue, 19 May 2020 14:42:26 -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=@chromium.org header.s=google header.b=YD0FWr1n; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726290AbgESVkF (ORCPT + 99 others); Tue, 19 May 2020 17:40:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725998AbgESVkE (ORCPT ); Tue, 19 May 2020 17:40:04 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D1DBC08C5C2 for ; Tue, 19 May 2020 14:40:04 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id d3so430552pln.1 for ; Tue, 19 May 2020 14:40:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=qZrnOBqdIK/f9ZKEYvAl0vw/13DRB3RwIGSmwGXyTpI=; b=YD0FWr1n4aRBwXbRpkumGdVcnRnTBzs8xC53EtpY/+CDnTQq5QrfVWZuUHWHC7t/oC GCluPTOCW1KYp8yaGOWLKDdonR1xl0cIqDBBpYL/Jc01xqzgLo2avep6uumO1EeeIe0+ sqTXfRtYYEmAKVRLMLfBHLUyJCkqlV8EfLlTU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=qZrnOBqdIK/f9ZKEYvAl0vw/13DRB3RwIGSmwGXyTpI=; b=qRV3MpkMxLn0xURaJLXtcGzbUtbhlsr7kWPGR7qBaSFomr8H8to3I3SgivfzzAVMPL d9p9zCJl22QzqIGZA4+ixZ+YKriyz+bBf2re7hOpeZcfNjdvD1/khw/95THHrcwou9Yq IEiV7PJ3EzrZbovVpbb9n/rHaLEzfjE2+VkZ52illBkLC0nQYgd2+gf8SLP3SqOEACnW 01Tm6wcfQEv4ml2idkCpTb/D69QMvrK9Qsv32MUilqMw7UWqOzxtkVgz4D1YuDL2qZgb v973rUV80i+oxkTI4byePlf7nEL22rHIdlEeAvHl+k31f401CgNWeZQDUXUTg/vQfVnO WgjA== X-Gm-Message-State: AOAM532kQYcDLdgBw4Rqha/yZay9t8bzc/I7O7IUNOrFiB39iWTM/41v m5/y7rmyNg0F5zd/CTVjWnIPEQ== X-Received: by 2002:a17:902:bb82:: with SMTP id m2mr1369227pls.291.1589924403251; Tue, 19 May 2020 14:40:03 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id n67sm370238pfn.16.2020.05.19.14.40.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 14:40:01 -0700 (PDT) Date: Tue, 19 May 2020 14:40:00 -0700 From: Kees Cook To: Alexei Starovoitov Cc: Aleksa Sarai , Jann Horn , Christian Brauner , Tycho Andersen , Sargun Dhillon , Matt Denton , Chris Palmer , Jeffrey Vander Stoep , Linux Containers , Linux API , kernel list , Daniel Borkmann , bpf Subject: Re: seccomp feature development Message-ID: <202005191434.57253AD@keescook> References: <202005181120.971232B7B@keescook> <20200519024846.b6dr5cjojnuetuyb@yavin.dot.cyphar.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 19, 2020 at 09:18:47AM -0700, Alexei Starovoitov wrote: > On Mon, May 18, 2020 at 7:53 PM Aleksa Sarai wrote: > > > > On 2020-05-19, Jann Horn wrote: > > > On Mon, May 18, 2020 at 11:05 PM Kees Cook wrote: > > > > ## deep argument inspection > > > > > > > > The argument caching bit is, I think, rather mechanical in nature since > > > > it's all "just" internal to the kernel: seccomp can likely adjust how it > > > > allocates seccomp_data (maybe going so far as to have it split across two > > > > pages with the syscall argument struct always starting on the 2nd page > > > > boundary), and copying the EA struct into that page, which will be both > > > > used by the filter and by the syscall. > > > > > > We could also do the same kind of thing the eBPF verifier does in > > > convert_ctx_accesses(), and rewrite the context accesses to actually > > > go through two different pointers depending on the (constant) offset > > > into seccomp_data. > > > > My main worry with this is that we'll need to figure out what kind of > > offset mathematics are necessary to deal with pointers inside the > > extensible struct. As a very ugly proposal, you could make it so that > > you multiply the offset by PAGE_SIZE each time you want to dereference > > the pointer at that offset (unless we want to add new opcodes to cBPF to > > allow us to represent this). > > Please don't. cbpf is frozen. https://www.youtube.com/watch?v=L0MK7qz13bU If the only workable design paths for deep arg inspection end up needing BPF helpers, I would agree that it's time for seccomp to grow eBPF language support. I'm still hoping there's a clean solution that doesn't require a seccomp language extension. > > > We don't need to actually zero-fill memory for this beyond what the > > > kernel supports - AFAIK the existing APIs already say that passing a > > > short length is equivalent to passing zeroes, so we can just replace > > > all out-of-bounds loads with zeroing registers in the filter. > > > The tricky case is what should happen if the userspace program passes > > > in fields that the filter doesn't know about. The filter can see the > > > length field passed in by userspace, and then just reject anything > > > where the length field is bigger than the structure size the filter > > > knows about. But maybe it'd be slightly nicer if there was an > > > operation for "tell me whether everything starting at offset X is > > > zeroes", so that if someone compiles with newer kernel headers where > > > the struct is bigger, and leaves the new fields zeroed, the syscalls > > > still go through an outdated filter properly. > > > > I think the best way of handling this (without breaking programs > > senselessly) is to have filters essentially emulate > > copy_struct_from_user() semantics -- which is along the lines of what > > you've suggested. > > and cpbf load instruction will become copy_from_user() underneath? No, this was meaning internal checking about struct sizes needs to exist (not the user copy parts). > I don't see how that can work. > Have you considered implications to jits, register usage, etc ? > > ebpf will become sleepable soon. It will be able to do copy_from_user() > and examine any level of user pointer dereference. > toctou is still going to be a concern though, > but such ebpf+copy_from_user analysis and syscall sandboxing > will not need to change kernel code base around syscalls at all. > No need to invent E-syscalls and all the rest I've seen in this thread. To avoid the ToCToU, the seccomp infrastructure must do the copy_from_user(), so there's not need for the sleepable stuff in seccomp that I can see. The question is mainly one of flattening. -- Kees Cook