Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3545544pxk; Mon, 21 Sep 2020 17:22:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykVXLrKgM4Ew9gCsx37iKD5L32xebaUkEnl12OAnF+ybZmxww7I6HerQczSqZsTa9QG2nK X-Received: by 2002:a05:6402:17b5:: with SMTP id j21mr1405000edy.276.1600734169270; Mon, 21 Sep 2020 17:22:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600734169; cv=none; d=google.com; s=arc-20160816; b=xjkuZ5i5l5LFlEycmNGmpNSwXENmrpfbcPxU6J4gVShsqaHNMxveXUgm0BJo6vNuUW sBTq/IIuCAbD8Fj2pg3zjvSRj6gJ+mkMeFayz1+fTwIBDCqtCtXbRVMjGYAPU09stwKe gaanHhhgvi+xs6NSLO6B8fST74wPNjq9rgUoD7uDrBsVNjQTljd2uCrgkugVOGjQt0di I5bAn/AK/j6L5bEW9HtGKH6tKE82GPyajCPsTjpzB42O/pmqszZFN+1bIwzw7PeQMDqD oKprpicKBAvv59BMEskeZJIbQgNHZOc17q28qD1U0eCVCO/VEpUhhW4s4SEL87AxOXlQ CvDg== 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=F406dxOGL4KIyo3r913T2qYQFJYxNBYaxUNYOkHvtJo=; b=Ek6yXw2X68eYCm4hhcE+HWIemmrXAIzgPEgBqbZJeWSgPg62Tiwnca6FDIfFyiH/rP MM/eGdn4zmUTyKHyTpkNF3UV1AE/D8zRi6TUEx6J+eWJS31quu0rFrNIFDYk8p040vGk ECMLALE+Wt5sJQAKg57KW2ui2x5q25E/nlXZWUMKqdsm/DRfJikNxvYk51a9JVp1y3eQ eKgZtQaSrT7UB5SxeHuaenl+qvAiJduOSZIn7wEjc0VZDowyf62qWUU0i4jLuV5oSpPJ v9TWKSOFJlf6Yuk9ymmxM18Cx6Ll9EtT/QJlk7ugOQRRiLu1fNpCTpoz0MgMbpic57tA WsiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LOgAOhIu; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p15si9347517eds.494.2020.09.21.17.22.26; Mon, 21 Sep 2020 17:22:49 -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=@google.com header.s=20161025 header.b=LOgAOhIu; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728653AbgIUW61 (ORCPT + 99 others); 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-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.