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=-11.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 89B3FC4727C for ; Mon, 21 Sep 2020 22:58:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4373023A1B for ; Mon, 21 Sep 2020 22:58:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="LOgAOhIu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728754AbgIUW61 (ORCPT ); Mon, 21 Sep 2020 18:58:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728662AbgIUW6Z (ORCPT ); Mon, 21 Sep 2020 18:58:25 -0400 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EA51C0613CF for ; Mon, 21 Sep 2020 15:58:25 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id l17so14353891edq.12 for ; Mon, 21 Sep 2020 15:58:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=F406dxOGL4KIyo3r913T2qYQFJYxNBYaxUNYOkHvtJo=; b=LOgAOhIuOtK3NEGs5lfUfr3Z1we8cm+fSTqcM/nC5XdWVc8G8zUtABSkKkmAQ52+H1 1c+W8yeUe6zOPyRAQkzv3YmZ68wzpCBSZbYpsAWqo96ic0X65rNdGYH8LmIb255U+BxI AcFVi2WBYPbN5eWFHSV+GoQejC0hhUjgTozpchXclGf2pMYARIw5Nn8kswl3yTi8QH3C /ZfNRcxgNstUkYZjsvuhuq1/CuGAyIibmjz/JC+desNVgZG3j59Jh+dsDzUufv5E4g2T 7ubxNAIyknRIdYm8G4IcLOiL79DsMCINz7MAtuidpGEXowsl8CAhQTvDIVfsZbFNiQOz m26A== 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=F406dxOGL4KIyo3r913T2qYQFJYxNBYaxUNYOkHvtJo=; b=mJCugIBkMA5wZ6i9rLEXGehtGDpySvoIWjeJ0wYNSvf3f1FftnumoIZTBmtnHONiWU js3x5Sqp5EjXNtxzatGoocBJXczj35a/yw3LGMS7O0Abowdrxn76ehal8UQGwq5H+gE6 PM4Q2OKLmq8KrLjBm/lHVIZTsM7dPCitsWw2ZqCivwkdTqyYvVMgzSgBkRvyZ7fxDWZJ OHXBNyhhafIdq7HO3iBlH488jRFsQom6O5MHUF7HcbF9AT7bvNjdMghEwCuJ62+QSpWU 09Q9Qi0wS4TAfUOCVYlIngdj/eDgvFiReNbTsbZLo6DSB8jEFm1ndncYzZgKn1Gv5IRv vb5g== X-Gm-Message-State: AOAM530aq6k/+SU+uRVp+z1dIJYbzO3ulQRszhNYH6pqEjsN4Oe+qoaW rlLNCMaJ2KieXQjJOpsyWj5oQfGqGSIyN++zLB9g4A== X-Google-Smtp-Source: ABdhPJzKQ8pt68rKwhcn6462p221HnYSc7PT1gfTLQQr7Dyyt5sp+3GSHllwhbLNcRdd6ZR5P19GP5X7qwPc+u0bf/A= X-Received: by 2002:a05:6402:cba:: with SMTP id cn26mr1188410edb.230.1600729104142; Mon, 21 Sep 2020 15:58:24 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jann Horn Date: Tue, 22 Sep 2020 00:57:58 +0200 Message-ID: Subject: Re: [RFC PATCH seccomp 2/2] seccomp/cache: Cache filter results that allow syscalls To: YiFei Zhu 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 Tue, Sep 22, 2020 at 12:51 AM YiFei Zhu wrote: > 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? I'm talking about the code you're adding in the other patch ("[RFC PATCH seccomp 1/2] seccomp/cache: Add "emulator" to check if filter is arg-dependent"). Sorry, that was a bit unclear.