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=-0.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 76450C433E1 for ; Tue, 16 Jun 2020 18:35:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 55375207C4 for ; Tue, 16 Jun 2020 18:35:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="AIBG74jG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728067AbgFPSfu (ORCPT ); Tue, 16 Jun 2020 14:35:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725896AbgFPSft (ORCPT ); Tue, 16 Jun 2020 14:35:49 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F4C4C061573 for ; Tue, 16 Jun 2020 11:35:48 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id v24so8763252plo.6 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=fuobHIwUxbmBchLWfQwsQhdp7DNfJvzP3nJAiAcETcJD82PhnVKNajYJSiwKRWtW2+ +L3/+Hycb61gEkYS80+0UbOKvvsNg5l+Cxj0hAItKM43iH0LxEZJDNExWivFMELxP7xf gkXF2TkPCMW2erNW3K90Z5wtOeOtPZom123q9B6XzRF0s2AMMIr4irTSgkWPByxt2sIh dPFYdENYADfQA5INCnEU8aUcLMqVjVH+yi/L++OyxXm1dJud4olMQSDloxWHXUJqLQyt 4EMsBIeBx0pQtmiOXUmUOXc0FA0tf/lFkdzd1gsUUoC+AUHvz35jNAHgiz65ZK3MIQNN gwlg== X-Gm-Message-State: AOAM531rkqfVO7hICKnq6OxrNxkyi4VqpBqkyBrj8GEEgvTLRUNwtQCH BO9MV7+D8pF5w9sv7VrpmYm1oA== X-Google-Smtp-Source: ABdhPJyorPz/hN0z0htsbMGKXDwxSMUZOCNVD6vqJvCbF6cB9/KRHU4TiB0xlr8glLU8oty9rAKq5w== 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-api-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-api@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