Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp747940ybh; Wed, 18 Mar 2020 08:25:07 -0700 (PDT) X-Google-Smtp-Source: ADFU+vteDefCAKMFd/AMAuV2sYyTkUOKtBlbJmIvgBENXUphU4SobslCacU2CYpP/zSOZN/tV+If X-Received: by 2002:a9d:ac5:: with SMTP id 63mr4354957otq.239.1584545107077; Wed, 18 Mar 2020 08:25:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584545107; cv=none; d=google.com; s=arc-20160816; b=Y3m2ARCdRm7nRsHpJCmamkiVe6OEO6a5wPSr3ER0MVOwDCumb9sC/b3Kkrtp0L49nQ dE8KYtbCsu7QdADi9S3ehqy3c7Dhw5QpPVtHIRlPlZRHR/0d+cXd1d6qVHFcQeHLtEDg Cfq2SioQOYeU1gMn63t0Ccb4BozX9sLfC7ujv2DlwapE1Xk7Vf5+SqPvaMXN1IAQi9M4 nG621EoYuNdglGejkZ8auTFNgYo184opM0UaK177OwHtnG75TuhdOIOp2RPz/OsxJX1F zFSSWE6guya/V06n9UGqDni6zvm9yr9Mjmx4vxTPiiKz9SLTYD4QyVMMKeWF7ceoNWgy KwxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=FIZR9zNeI105db6KUPnQEP9FoziaF4rTuJr7IfEBA0k=; b=IftSAyKYORpzlXgmTSEWGdaxoSS57lcPCfqOIHX5njYH5y0VKXJoC6jm9BJGhPmeHY YYLVyOMY0lZzfQvC/FTwm1lQVTaRRNxtxA+HgoAdC/fdMvgOW5iOMHBGAYh/9sALpL/l b8iUBKYh/zMBvxRsfXT/zYfPwrc1VYhGwvDuvKxENni2SzpcTj2dBYQVCQyL7GfHV8P9 sfsTA05h8vFwyIv2YNv1EJumdFLdeRUxKomQo8Llwnbw66vfgjMIlRos0sVtPZhID405 4roUAmxlUnS7xtnNP8RCzI+cv8NLd6honJri6BhvVfvY8ghNvv5SzolWoJp2rDFkxrNY 5yJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rwjYB3xh; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n6si3692086otf.147.2020.03.18.08.24.54; Wed, 18 Mar 2020 08:25:07 -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=@gmail.com header.s=20161025 header.b=rwjYB3xh; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726936AbgCRPXc (ORCPT + 99 others); Wed, 18 Mar 2020 11:23:32 -0400 Received: from mail-vk1-f193.google.com ([209.85.221.193]:36013 "EHLO mail-vk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726619AbgCRPXb (ORCPT ); Wed, 18 Mar 2020 11:23:31 -0400 Received: by mail-vk1-f193.google.com with SMTP id m131so5434691vkh.3; Wed, 18 Mar 2020 08:23:30 -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:content-transfer-encoding; bh=FIZR9zNeI105db6KUPnQEP9FoziaF4rTuJr7IfEBA0k=; b=rwjYB3xh9woWZvobt7cB6CGcCipWsmk5GqRtjXPFht1ersDi+or7ClLOtiTyWYg/MY 0mFY3FeHrGUx+D2dDIOKwEQQk5WuhyBNCeYGrOyU1Muiem5WP5fV0H4y1aaANz/qtX7B P2nv593BwTETTLyYrCwCQhFC2U/1alcBGTdodbsWG2PTZJPBjBpYLUhoIgRrD8fpLxZN X6TmLNgIuDnN6BJsJsfez7YBPLq4GW3dW6eBvpuL9V0d7XP7lHOmDlCjI6jAqqgp2mc3 hP1DJi7HFQ2cfb9S2XEYb8O7ngVAG+utxnAU46cjZXgWjaZtRVY2mKFVOzmMERDTYb3j eRZA== 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:content-transfer-encoding; bh=FIZR9zNeI105db6KUPnQEP9FoziaF4rTuJr7IfEBA0k=; b=XzWNrwN0h+yxhlA7s4nmPO/ARNtS4b4GxkxVVNpFsw9J+nmtojGcUll1ut9Q7vBVxS bAEi+qcekHavX90b+OZuU9bSqBs7x8iuay4cFRMcecCx3Wwx1DtAW1PNLL0byxZHZqb6 QU693vKyJ5TcKJlhYIzl2+6MyAhliqGDKsdIdHqmWIYBspKU7/O9NUjmf7OkaDcgeerw mvdhw21c3Nz47tsy0Oi7oh0fA+yqs6CPK+Hvn3Tc5qMrFISVNp3lUjfQJnwUV2g8Me3A ryxvmCDtncE1UjE7cRZReuNXSqoPWZNdEQWOOKQUeZ4f+1h5IyJdV4DcEVUTbFEL5ZkU fiPA== X-Gm-Message-State: ANhLgQ19aUzpYq0pz1kGwa51c3D5YnqBkLzVvNrN+CoGyd2md2w/RCLC UCg1XrOa4u3ZX66ugVrX3+5fv353aAEAPa2YenI= X-Received: by 2002:a1f:6182:: with SMTP id v124mr3710291vkb.48.1584545010105; Wed, 18 Mar 2020 08:23:30 -0700 (PDT) MIME-Version: 1.0 References: <20200316163646.2465-1-a.s.protopopov@gmail.com> <202003161423.B51FDA8083@keescook> <202003171314.387F3F187D@keescook> <202003172058.3CB0D95@keescook> In-Reply-To: <202003172058.3CB0D95@keescook> From: Anton Protopopov Date: Wed, 18 Mar 2020 11:23:19 -0400 Message-ID: Subject: Re: [PATCH] seccomp: allow BPF_MOD ALU instructions To: Kees Cook Cc: Andy Lutomirski , Will Drewry , open list , Daniel Borkmann , bpf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org =D1=81=D1=80, 18 =D0=BC=D0=B0=D1=80. 2020 =D0=B3. =D0=B2 00:06, Kees Cook <= keescook@chromium.org>: > > On Tue, Mar 17, 2020 at 09:11:57PM -0400, Anton Protopopov wrote: > > =D0=B2=D1=82, 17 =D0=BC=D0=B0=D1=80. 2020 =D0=B3. =D0=B2 16:21, Kees Co= ok : > > > > > > 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 c= ase > > > > 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 gi= ve > > > > me about 15.5 instructions on average. > > > > > > Gotcha. My real concern is with breaking the ABI here -- using BPF_MO= D > > > would mean a process couldn't run on older kernels without some trick= s > > > on the seccomp side. > > > > Yes, I understood. Could you tell what would you do exactly if there > > was a real need in a new instruction? > > I'd likely need to introduce some kind of way to query (and declare) the > "language version" of seccomp filters. New programs would need to > declare the language level (EINVAL would mean the program must support > the original "v1", ENOTSUPP would mean "kernel doesn't support that > level"), and the program would have to build a filter based on the > supported language features. The kernel would assume all undeclared > seccomp users were "v1" and would need to reject BPF_MOD. All programs > declaring "v2" would be allowed to use BPF_MOD. > > It's really a lot for something that isn't really needed. :) Right :) Thanks for the explanations! > > > 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). > > > > Right, thanks! This saves about 4 more instructions for my case and > > works 1-2 ns faster. > > Excellent! > > > > Though frankly I've also been considering an ABI version bump for add= ing > > > a syscall bitmap feature: the vast majority of seccomp filters are ju= st > > > 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). > > *This* feature wouldn't need my crazy language version idea, but it > _would_ still need to be detectable, much like how RET_USER_NOTIF was > added. > > -- > Kees Cook