Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3280654pxk; Mon, 28 Sep 2020 13:06:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjki8fhyRev2+h9Utek5ojGFu4g/XZnfdMxWqdZGXnLEdSB/YyqZXWoFkGERzJn8r5ePkh X-Received: by 2002:a50:99d6:: with SMTP id n22mr3723808edb.265.1601323571681; Mon, 28 Sep 2020 13:06:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601323571; cv=none; d=google.com; s=arc-20160816; b=rJxgLMXcSe7I5I9Bfbn5pNaXeDtjFb82aqsghEvwKtGk4HKu7YYV4du9Fqi5EVcxKS QF4MswPR1oH/Ln+Cjr7NaEQOMsy0opcfzWViUKn8LruwMm67VjG9JjMhWXWYXdgi83Ri Vwj6uXNit9aUXkI+NIZRLb3ejsVGDG1FoMmFLPX4JFhmM0CCaJs5M7iCccKZj6Want2Q pbFgky2dJzXbGwy3aSWQUY5dnr0Sp1jsCGOemHeUdCDwFagC5QiU9NbiVp5DE4F1orQn ITS7SkBDCTfgplWrcu/+/TjhsjrZqQ7lTtFSt4QAcAqHyR9zne6UCfvvyBcbszVcMiEe Zqlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=DrORwxFSTGYgq7rDpyN+PgrRRMbvRryObis6SlzlegQ=; b=inb9JlJUUvRkLG5o9BF12AeYhRxWn52L/wzdr40bCIObLpxwjLWYSHz1TOMjqW07fZ wmAJSWKpK7a7JvEdcPB/UJuauMCeCZmbV/JXr1sviYYNL/0l1jlgDFMRK6ACHxbNJ3nz T0O8pDnsQCmB5808NlM2UUSBZILXoCCF53HdQz8G6ZwpbB3tIcZZe9VIBhzwltfTvHlg UmR3n29CPAmt6qsHjr44oQu0jyWzZCY0z/9uXB4HPhaKPIVQweV/KfckjMFlDPskugSj jrnMPMHe4TiVzNSoyhB55QkyFk7uxC75kgNeKc18VAjtf58zf+O/Sz/3soZBFJsmPiLt ZE0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=E4DiKgHZ; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h19si1232547ejl.253.2020.09.28.13.05.47; Mon, 28 Sep 2020 13:06:11 -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=@chromium.org header.s=google header.b=E4DiKgHZ; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726732AbgI1UEx (ORCPT + 99 others); Mon, 28 Sep 2020 16:04:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726325AbgI1UEx (ORCPT ); Mon, 28 Sep 2020 16:04:53 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 039A8C0613CF for ; Mon, 28 Sep 2020 13:04:53 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id 5so1841198pgf.5 for ; Mon, 28 Sep 2020 13:04:52 -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=DrORwxFSTGYgq7rDpyN+PgrRRMbvRryObis6SlzlegQ=; b=E4DiKgHZ8+3lgXItSKuRg/Zp0KCE480TlXTghysXO3BoLDWSNo77w7adL5ZNKFzaJt JrIB8dlPqKMbNAPQuhOffpeY5lxUoDQaCkYU7Gb2rde/d/IV3kPzLjUCB6bh4IovYwuN dW8ea1YKN4Z7HbEGJI1W39qM7Swg4rgPmsp04= 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=DrORwxFSTGYgq7rDpyN+PgrRRMbvRryObis6SlzlegQ=; b=godXhxx6I3fOo065mhZNJq2AH8Kn9n3S4BRK47VxayYP3O1S4ChnVDkrQ1r/unYIL0 oP2MIkkx59hgouN+2fGFhHY6lvtWULviB7qW/t1z7bZ56wp2DobjFmE1I/S5BXRFOSNL 7kZuFeFOPg80TmFeHYtYCLri7yvL2ovcGTZxnr+k747WmEGkASNxGOJRgy6UZuR1aHzT jbMYgrhd/0E94KpQg6/LVBqg3ROwhUGx7znuJl832Rhl68oFr8SLjDh+of7SaSKmS2Aj HWIufjlQDG746SOVLvazLA936om1M2TscEur1Q4W3CKsNxVRAPIZDyv+Fh4jhEOQAqoM E3fA== X-Gm-Message-State: AOAM531pbX9wJK8ywMxnrLKS6Ytwbn1yzqkgLuuwAUVrDvdRqOXF7J0N +Kii35yjBaAdtLDCAoaLFe+bfw== X-Received: by 2002:aa7:99c2:0:b029:142:440b:fa28 with SMTP id v2-20020aa799c20000b0290142440bfa28mr961093pfi.30.1601323492379; Mon, 28 Sep 2020 13:04:52 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id w203sm2928796pff.0.2020.09.28.13.04.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 13:04:51 -0700 (PDT) Date: Mon, 28 Sep 2020 13:04:50 -0700 From: Kees Cook To: YiFei Zhu Cc: Rasmus Villemoes , YiFei Zhu , Andrea Arcangeli , Giuseppe Scrivano , Will Drewry , bpf , Jann Horn , Linux API , Linux Containers , Tobin Feldman-Fitzthum , Hubertus Franke , Andy Lutomirski , Valentin Rothberg , Dimitrios Skarlatos , Jack Chen , Josep Torrellas , Tianyin Xu , kernel list Subject: Re: [PATCH v1 0/6] seccomp: Implement constant action bitmaps Message-ID: <202009281259.D7D18AE95@keescook> References: <20200923232923.3142503-1-keescook@chromium.org> <43039bb6-9d9f-b347-fa92-ea34ccc21d3d@rasmusvillemoes.dk> <27b4ef86-fee5-fc35-993b-3352ce504c73@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Sep 26, 2020 at 01:11:50PM -0500, YiFei Zhu wrote: > On Fri, Sep 25, 2020 at 2:07 AM YiFei Zhu wrote: > > I'll try to profile the latter later on my qemu-kvm, with a recent > > libsecomp with binary tree and docker's profile, probably both direct > > filter attaches and filter attaches with fork(). I'm guessing if I > > have fork() the cost of fork() will overshadow seccomp() though. > > I'm surprised. That is not the case as far as I can tell. > > I wrote a benchmark [1] that would fork() and in the child attach a > seccomp filter, look at the CLOCK_MONOTONIC difference, then add it to > a struct timespec shared with the parent. It checks the difference > with the timespec before prctl and before fork. CLOCK_MONOTONIC > instead of CLOCK_PROCESS_CPUTIME_ID because of fork. > > I ran `./seccomp_emu_bench 100000` in my qemu-kvm and here are the results: > without emulator: > Benchmarking 100000 syscalls... > 19799663603 (19.8s) > seecomp attach without fork: 197996 ns > 33911173847 (33.9s) > seecomp attach with fork: 339111 ns > > with emulator: > Benchmarking 100000 syscalls... > 54428289147 (54.4s) > seecomp attach without fork: 544282 ns > 69494235408 (69.5s) > seecomp attach with fork: 694942 ns > > fork seems to take around 150us, seccomp attach takes around 200us, > and the filter emulation overhead is around 350us. I had no idea that > fork was this fast. If I wrote my benchmark badly please criticise. You're calling clock_gettime() inside your loop. That might change the numbers. Why not just measure outside the loop, or better yet, use "perf" to measure the time in prctl(). > Given that we are doubling the time to fork() + seccomp attach filter, > I think yeah running the emulator on the first instance of a syscall, > holding a lock, is a much better idea. If I naively divide 350us by > the number of syscall + arch pairs emulated the overhead is less than > 1 us and that should be okay since it only happens for the first > invocation of the particular syscall. > > [1] https://gist.github.com/zhuyifei1999/d7bee62bea14187e150fef59db8e30b1 Regardless, let's take things one step at a time. First, let's do the simplest version of the feature, and then let's look at further optimizations. Can you send a v3 and we can continue from there? -- Kees Cook