Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp4157997ybh; Tue, 17 Mar 2020 13:22:16 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuFwoveGbFJIowoI9/oai32woZrJL/a/Jq/kNrZrYIBhbQVSe82n9gE2kaAl1kZrLmpdodO X-Received: by 2002:a9d:1d43:: with SMTP id m61mr917278otm.91.1584476535907; Tue, 17 Mar 2020 13:22:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584476535; cv=none; d=google.com; s=arc-20160816; b=xIijRv05WvrrExoto0OQDSx+VAw3+TLS66buBGRtKsdPoJNzlcrn27q2XOmVK4ect8 SgkzXFjYbMuFqqEXOXWTivYrJlw7SAqadO1Zq1M6BigUuQrIBxarh/14vQK4Gfjp2FXJ TnrJVJqvdTXLE6KyT2AICZm16kcwnBPhWhprXedNjdLsbNqoW2fNze2y6r4h2V9cVKwm JMV/yjugr38NAMaIYhLzkv0TqdkDw3jx3tI+vVPibno3dhEwQtj44Y9HWaY2mAsqVVsK 0GLkGEbvUWbuFa7jFkmhal4cSNVbGn+03M+mdf5KtsDwmqj0qEzDGxdROSbG6nUa5w72 63FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=9OK68t7TUQtw3LyqGzDkiyJ3oB07lydjnI/8ZCLVjiA=; b=mkPPaXAEnMbiDtXUkBngtGjZieNlrWMq4QEQZwK0KxJKNXxUaciOlmGjcRH9NAoO36 Kcla7UwRifit+PkhhBxHebaWdumL61zCBlhW3QSa+TSiMRGAaS17Y83O/0bUIFzu4Vcc aWR5h75ehQITEWEtdr0OkTlqtlZJcA9Hupq9dzCpuX0qIbKj8+sIMgIqcbPDu88qFykp yo26JJQaCVXz2SlbU5TeAAcy/28sXzSZyvGYuWy6+0SQm9bJ5ZYGUgvfCk6AvHDZlb9H xAEvrtVLTikxF8YA3almU/Ag64oivs6YTVzLygXnonQbT24fVdaj1TBBDB1cn7JTTfTq yFew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="cDuzR/o5"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id g206si2185855oib.17.2020.03.17.13.22.03; Tue, 17 Mar 2020 13:22:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="cDuzR/o5"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726770AbgCQUU7 (ORCPT + 99 others); Tue, 17 Mar 2020 16:20:59 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:40687 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726756AbgCQUU7 (ORCPT ); Tue, 17 Mar 2020 16:20:59 -0400 Received: by mail-pl1-f193.google.com with SMTP id h11so10107156plk.7 for ; Tue, 17 Mar 2020 13:20:57 -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=9OK68t7TUQtw3LyqGzDkiyJ3oB07lydjnI/8ZCLVjiA=; b=cDuzR/o52T2Hh4/O479e/RTlekL5mxBre7cYIj0XZoI4PyYPkn7+0PhzuplUknZKGj M8Pb5DqcQracDAOHvDrkuyEyb1WzfghxMRd7jeJs2zroVt62lYa4rOJqOi9DxXscZseg JYWvdXoeVPI+hKqRqvZcRz6WDkZiwSXGq5hrk= 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=9OK68t7TUQtw3LyqGzDkiyJ3oB07lydjnI/8ZCLVjiA=; b=SRbADd6V+0yzowHlRibUnWyDOAk0fZ+3TojiJWMzDT9s1bZQLRyVeLe2Ef49+H//AW 7Lj3KdxegJh+Pmz5hWs44FibKJsdhqZTgTieeVJmGnRpdBNAOjDohAf2KCmQsOz0fCN0 3FzmX2Cv9fL+o/+uGqzAz8CFEtlDKmkLgM3FgdBJagO8uNzbCb9XbO5/oqp/ad8hZK9U kDcboTnPAlsAmiz1meIBwKAJs7FejN/viunJAWa9CxQqGOx6CHkqQ0WB9yd15Q9aL5RX eZXGJfedgNdih5JMkvyH7g1WBo+5FISSVpHvB8ihApp7ZBGx2PmWYCDTR76z+Q5GMeQ/ ASUw== X-Gm-Message-State: ANhLgQ1lxdzxTeFzRoY7wMr3rzJwa40AF2OSpCmj+x9rHbOukGs4KyU7 jqGLzsdpPaA6z0Ncl/M6iA4iuQ== X-Received: by 2002:a17:902:e981:: with SMTP id f1mr416010plb.103.1584476456804; Tue, 17 Mar 2020 13:20:56 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id x18sm4033833pfo.148.2020.03.17.13.20.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Mar 2020 13:20:55 -0700 (PDT) Date: Tue, 17 Mar 2020 13:20:54 -0700 From: Kees Cook To: Anton Protopopov Cc: Andy Lutomirski , Will Drewry , open list , Daniel Borkmann , bpf Subject: Re: [PATCH] seccomp: allow BPF_MOD ALU instructions Message-ID: <202003171314.387F3F187D@keescook> References: <20200316163646.2465-1-a.s.protopopov@gmail.com> <202003161423.B51FDA8083@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 16, 2020 at 06:17:34PM -0400, Anton Protopopov wrote: > and in every case to walk only a corresponding factor-list. In my case > I had a list of ~40 syscall numbers and after this change filter > executed in 17.25 instructions on average per syscall vs. 45 > instructions for the linear filter (so this removes about 30 > instructions penalty per every syscall). To replace "mod #4" I > actually used "and #3", but this obviously doesn't work for > non-power-of-two divisors. If I would use "mod 5", then it would give > me about 15.5 instructions on average. Gotcha. My real concern is with breaking the ABI here -- using BPF_MOD would mean a process couldn't run on older kernels without some tricks on the seccomp side. Since the syscall list is static for a given filter, why not arrange it as a binary search? That should get even better average instructions as O(log n) instead of O(n). Though frankly I've also been considering an ABI version bump for adding a syscall bitmap feature: the vast majority of seccomp filters are just binary yes/no across a list of syscalls. Only the special cases need special handling (arg inspection, fd notification, etc). Then these kinds of filters could run as O(1). -- Kees Cook