Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2662363ybt; Tue, 16 Jun 2020 11:38:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwC0uhkvxwDU2GdlzxBtwhfSITrIXlVoFFKnqMz0FT2jjKNpsJHyo+yySERXuAf8WfTFZvc X-Received: by 2002:a17:906:a288:: with SMTP id i8mr4202270ejz.324.1592332689866; Tue, 16 Jun 2020 11:38:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592332689; cv=none; d=google.com; s=arc-20160816; b=iJjpxopOx1L3nckEZoY5Ketonf8Lof8SCQgtlU+QODRwtvy/RYNpGLhRf+rYMqzRLd Esr0n7+/4ASwlS74BTrDIJ14cOa60JPuyTdETuZnbW8wO+vHtrxcVlBFcdrP3Hw7jvEH W+qLwpw9+3MQZqPLg8072injtk4Nixe3KuQtfOoy/lHxFfCoYTQS9U5q8aeFf9UulIlv e49N4f4IzbjgjnAJAH//5SB6/yilxCMsQh1Y8LvOoXCAyMj+mXRQdpL1Yl6KuItP2hJw egMb7yNuG6S/OhnEuVIEcuXKuVY76pM0aYK762vrRddN3WPFMpfhZXJnsL4o5Je8LAp6 +HgA== 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=Gv5SyNbN+YalOOMpT+lUR6zrSKOxyXFsPO4eN2yYyhE=; b=CRl+NdSaBbiaNXXB4N+/QB7zO4L9KC5tTUq0cArw1Lotja0jQrc/tzcIx03rCBTWGD MT4f8hvmOIf1Kz1km25SWwvqhEAEo7QpkZDTAinFB73uA6JzvCZj+vmtOSTWFBw56O1J w4TgkpKQOM8iSPOPugznx/DHKG1KdyQB64rjU6rp5N2RVfpMAIFTftms+uTK03u7VJr8 ja5cUxnU0+BKoHmXCdOTsyT9EMO4TmH+h/+3iDjb1W5esOkssMYhgyAHwmFWg5fMT5Fl DgnttVdbnZp2Aa19O2yIWMEgZH4qTuldaU5O36B/W3AoMjttYgALmBcYW+8EYEDiVJZd 9Ljw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AIBG74jG; 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 g6si10484814edr.432.2020.06.16.11.37.46; Tue, 16 Jun 2020 11:38:09 -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=AIBG74jG; 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 S1726881AbgFPSft (ORCPT + 99 others); Tue, 16 Jun 2020 14:35:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725896AbgFPSfs (ORCPT ); Tue, 16 Jun 2020 14:35:48 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90D10C06174E for ; Tue, 16 Jun 2020 11:35:48 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id u8so1809841pje.4 for ; Tue, 16 Jun 2020 11:35:48 -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=Gv5SyNbN+YalOOMpT+lUR6zrSKOxyXFsPO4eN2yYyhE=; b=AIBG74jGGwjgO6WBXM4vpHq8cFCM4p4Psqbxkb87Jqwbz68+d4zZle3XICqvnmKg9t 6G7DW5BrZDAeXEvDllsiq4n65S1+BsdnQf1eWYTN7zFu4VjIZ8MlVpW5fEDEMrw8tSVT uUCSHHX4FBSHO1H3yJ7TrYinRqzogRKaDRzI0= 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=Gv5SyNbN+YalOOMpT+lUR6zrSKOxyXFsPO4eN2yYyhE=; b=KGt8TOM1iIKPnTcqPqhli4V/797cUUV4j7UBlj/7lsmpsF+NtYvtFlt2fILH545pco eFKnGvl+MVAGuLZFzzjf9dC6JhOwqS7RwOQWebWoLUS96XyACS/U6QHvBxwbvEakQnoH wB45NKfuG/bu6Y9b3v5IVYwZE2UsncSTILuEMQMnc5ufhhExWL6g0sckAtv7xqCF/T9u nP2euVKHKRKgvLiGYp5dDecXrbtDWUtsQJcDdQHvUImf6HEfZ6UPf4e6/l9+qbKUbXdz Y4zjPaWZ6D5zi4s4GstIUxnQM2ni1kg8FiU9w25IrhuYUtWRz6GvHBgPQp4yS1kSm8e9 r/Vg== X-Gm-Message-State: AOAM5307B3/XCwq84E+6RVa/CGLFasNyUWo3JDB8sN9VWxNZCN+vzhry UcNz/6/BzpGt0E5J+yXz0THwdg== X-Received: by 2002:a17:902:201:: with SMTP id 1mr3268685plc.195.1592332548117; Tue, 16 Jun 2020 11:35:48 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id d184sm7822774pfd.85.2020.06.16.11.35.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2020 11:35:47 -0700 (PDT) Date: Tue, 16 Jun 2020 11:35:46 -0700 From: Kees Cook To: Andy Lutomirski Cc: LKML , Christian Brauner , Sargun Dhillon , Tycho Andersen , Jann Horn , "zhujianwei (C)" , Dave Hansen , Matthew Wilcox , Will Drewry , Shuah Khan , Matt Denton , Chris Palmer , Jeffrey Vander Stoep , Aleksa Sarai , Hehuazhen , X86 ML , Linux Containers , LSM List , Linux API Subject: Re: [RFC][PATCH 0/8] seccomp: Implement constant action bitmaps Message-ID: <202006161131.5A21C01@keescook> References: <20200616074934.1600036-1-keescook@chromium.org> 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, Jun 16, 2020 at 10:01:43AM -0700, Andy Lutomirski wrote: > On Tue, Jun 16, 2020 at 12:49 AM Kees Cook wrote: > > > > Hi, > > > > > In order to build this mapping at filter attach time, each filter is > > executed for every syscall (under each possible architecture), and > > checked for any accesses of struct seccomp_data that are not the "arch" > > nor "nr" (syscall) members. If only "arch" and "nr" are examined, then > > there is a constant mapping for that syscall, and bitmaps can be updated > > accordingly. If any accesses happen outside of those struct members, > > seccomp must not bypass filter execution for that syscall, since program > > state will be used to determine filter action result. > > > > > During syscall action probing, in order to determine whether other members > > of struct seccomp_data are being accessed during a filter execution, > > the struct is placed across a page boundary with the "arch" and "nr" > > members in the first page, and everything else in the second page. The > > "page accessed" flag is cleared in the second page's PTE, and the filter > > is run. If the "page accessed" flag appears as set after running the > > filter, we can determine that the filter looked beyond the "arch" and > > "nr" members, and exclude that syscall from the constant action bitmaps. > > This is... evil. I don't know how I feel about it. It's also Thank you! ;) > potentially quite slow. I got the impression that (worst-case: a "full" filter for every arch/syscall combo) ~900 _local_ TLB flushes per filter attach wouldn't be very slow at all. (And the code is optimized to avoid needless flushes.) > I don't suppose you could, instead, instrument the BPF code to get at > this without TLB hackery? Or maybe try to do some real symbolic > execution of the BPF code? I think the "simple emulator" path[1] might get us a realistically large coverage. I'm going to try it out, and see what it looks like. -Kees [1] https://lore.kernel.org/lkml/202006160757.99FD9B785@keescook/ -- Kees Cook