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=-3.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 F10F0C4727D for ; Mon, 21 Sep 2020 22:51:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B050C23A63 for ; Mon, 21 Sep 2020 22:51:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QUzlApk9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728696AbgIUWvH (ORCPT ); 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-Google-Smtp-Source: ABdhPJwIh4TG2lZRhS3+puFxuT098Mmba2FlJSMwTw8F7EzbCgRWoakQWoggppEyR++U27sLmfWb4dSxPkRHVJRWJEg= 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