Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3545487pxk; Mon, 21 Sep 2020 17:22:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUyRZJBxTQCWKGurH01foQcuy8Zc7UjeXHC7CrjX2GYoXnbvc3v5mguPIOfDd8OXOXfu9P X-Received: by 2002:aa7:d29a:: with SMTP id w26mr1447285edq.106.1600734162219; Mon, 21 Sep 2020 17:22:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600734162; cv=none; d=google.com; s=arc-20160816; b=Qq61eqeAUSLQL2O54pYcwieogog/3ysW2eL6RmOFnVT8ImadXM3QIci8dC8J+APZvN WRDUmq1bq4iI31WV9A1HXYBCPrseqYIDm/cOgNLC6u0z/fPjgXEiF23C0mrpD01tEmxP CxZvNQiE2hA67pqT54xmS5t3cXhyHFEOkWX3pXwg9cja5qeTFOUP+ajCWkEdU6oN5D3K pbgopa9GMgqm2+DO0AEUacb7j0uMwLq+sr1lfVK46997+VLMFE7dCzSmn/vChCc9velP Yhui5cq7oivQWLY1r/oepLMh0mmJshHn/s136U6QfT2DOtZiCpzpoe5/WjzZgA2riwk7 ZarA== 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=vGTBAGvWDFjbodpOJVDhuski4CeBWH0Uvr/+Kwfo5Oo=; b=rPsItGFdL7WxKviDHxGJcbeM/osWgIA9M0a6GNzePiSUTZOEHaQ4VGQ2fHsZtCG/tZ sWahyWoFS871bfuH3BFwHRtaj79O6BDj11NB7Gdf4PcZY2ELPYS+l18zq4DV7byaHgVt ekvWVfcnJq2C/ezkdRmKz4KtOiGIduXI4wtxTt0H172IjiCCwBYu7WcEI6aTrSTeaNm5 UlGX1cUDmjesU1QkSOvJkS7V+1k0NSChEXTDRODWhrg/hqorzxd4tjqXBTC/TVD0DDqZ scrY57YpZqV9SJiPWUp2MTev52nq6HpcN7Q1yDZBozDcSu2dg8XyIwkeE6eE7axeNt4a FUgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QUzlApk9; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p34si10080055edb.470.2020.09.21.17.22.18; Mon, 21 Sep 2020 17:22:42 -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=@gmail.com header.s=20161025 header.b=QUzlApk9; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728689AbgIUWvH (ORCPT + 99 others); Mon, 21 Sep 2020 18:51:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727693AbgIUWvH (ORCPT ); Mon, 21 Sep 2020 18:51:07 -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 1A65BC061755; Mon, 21 Sep 2020 15:51:07 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id u3so513310pjr.3; Mon, 21 Sep 2020 15:51:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vGTBAGvWDFjbodpOJVDhuski4CeBWH0Uvr/+Kwfo5Oo=; b=QUzlApk96W2T2IaCs5WGQXm3ZTGAUMjBN/NJE6GKiP7ihH3Ebqvf1sHDE9qe4eUNlB tcBhVT3a9ZWJQvvKj20pUNmbF66KiPV+zPIn9Dd4lQLRM2xnQDH+SAkD5dugk079Dxdd DAsPEvRmAKxUcH/DWv5tqex3OSuRmnqd8/JaS18pmiTNeigKozmXI8D0cTk144lI/9QZ WCQCyMawJHanLv7XM+51axli469ZW0hFiWgZHdyfJGksgGrmtJ5rAUkCNGnWCbBzxxQN yH4Dm7doaWUhWhrbFqrbPgSS4pe2eiq/nbqCWensqlbCjVNAuzGC3mD6iot+s4WjMKVT sY4A== 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=vGTBAGvWDFjbodpOJVDhuski4CeBWH0Uvr/+Kwfo5Oo=; b=iCwjd8G/XOXR6fZu6e+R8mJBb1DpfFf5G5tBT1CcBK2r5ZWK834E4z8Cry1/h07Xp1 T/lbaJF4pw0x66L2TfIqe5NQp6cNNNcVxQLMFuTRhJGbBxC/auHGdpakSYmjaegZSBo1 LfkLdYwvTTKsc7IRZBfVT1izty9WuX3t6OB2z+8Dy+Cf4QozUKXe5HXbbhjkpc/PsFBB 49us/ljN5Jyzh1wkCAzUcxKR446u2JQNkjApXfpIe+JaJaRngc2PZd9cDBAuCUpWYaxJ +FafbHVBtZNchO83oeZGe///yq56yUDulX7C7lG0LwsJmvNvGXtyNJq/rxRs1rgysVhk edow== X-Gm-Message-State: AOAM531Jc/Y4lXcmOVL3PpxLnOZ4IVtqW5/F4Yjfd5eEq9e72B8Q/MrG pxiQd2wn8ZLWr6aIVszyxEJlZ0SE24G4IbVOe75oxzGwsTDLGA== X-Received: by 2002:a17:90b:4b82:: with SMTP id lr2mr1303431pjb.184.1600728666628; Mon, 21 Sep 2020 15:51:06 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: YiFei Zhu Date: Mon, 21 Sep 2020 17:50:55 -0500 Message-ID: Subject: Re: [RFC PATCH seccomp 2/2] seccomp/cache: Cache filter results that allow syscalls To: Jann Horn Cc: Linux Containers , YiFei Zhu , bpf , Andrea Arcangeli , Dimitrios Skarlatos , Giuseppe Scrivano , Hubertus Franke , Jack Chen , Josep Torrellas , Kees Cook , Tianyin Xu , Tobin Feldman-Fitzthum , Valentin Rothberg , Andy Lutomirski , Will Drewry , Aleksa Sarai , kernel list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 21, 2020 at 1:09 PM Jann Horn wrote: > > On Mon, Sep 21, 2020 at 7:35 AM YiFei Zhu wrote: > [...] > > We do this by creating a per-task bitmap of permitted syscalls. > > If seccomp filter is invoked we check if it is cached and if so > > directly return allow. Else we call into the cBPF filter, and if > > the result is an allow then we cache the results. > > What? Why? We already have code to statically evaluate the filter for > all syscall numbers. We should be using the results of that instead of > re-running the filter and separately caching the results. > > > The cache is per-task > > Please don't. The static results are per-filter, so the bitmask(s) > should also be per-filter and immutable. I do agree that an immutable bitmask is faster and easier to reason about its correctness. However, I did not find the "code to statically evaluate the filter for all syscall numbers" while reading seccomp.c. Would you give me a pointer to that and I will see how to best make use of it? YiFei Zhu