Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp638139pxk; Thu, 24 Sep 2020 14:37:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUdWbsBpvXm/5iYoNSuVR3y7+SVPT+qvfiPnK0Eewt5GaLhxqf9KUeOtVgv00NQH+M5f/z X-Received: by 2002:a17:906:4553:: with SMTP id s19mr580187ejq.475.1600983454365; Thu, 24 Sep 2020 14:37:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600983454; cv=none; d=google.com; s=arc-20160816; b=qbyGOmjvWRfVhgUz5ygHFbWFwrg7aO0QOoPuYfHtBZbqbXY2mWjSXtmh4yAmLwyAnW aUx1KxotZNRu4uFrWm8g3w9LrKbNOMa9NNubxVpfS2IyHKs0MDMDMlgpnRb1e1wHPaLA NiAirATcYqctYkqT0OPN/0I1FXwVXAWotUHSLu47+Bh0L5kAwJd8gnnsxqLsuA6VV6YL QApAGq/PQjs8deuOThkMSkGyklWK48jObE32K39/vz0gLdc3XXQBnX6bX7OF/uYO8LUX ecTMU63S/G/DYCjMc1bUdI5B3LSgF72fxxIEcfXUJoR/T8dz8+w15YU6RsZxnojXT7fB TJaA== 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=3CW8CM9pV/u4FfPt/5+0+4IcrrDDgdR3Q+VzmdoOROI=; b=XKxtWk346+OqY9Uc6SrbkljjBOyNt8il34MIlMls/RaFrzj0Uo2wKblXCoz0DhopZR T/TQY++93T65MgUnLAWpTfU3xgTD8Q1dQ9e8kTN6acU4y4vWjDoGiikqXiE8JgMLkIDj q/QS+Y4LSevYeiak0jP1IXIX6bMoJG7l26d+BVzlRPl1ugN+i9PMH1DqyjraYUlljaJg tiij03fSB5KMzerCIxyf8tjngZldZSSZNEGJjZ+iCfsFi9aP6SpOjnSlirGS1MJY3lN9 XZWi2SL4WbVBZpnhVuZzaqtqan8jmZ48sQv1b+iULpzHy2P0DjgS/l9xjIKGsCFh/1TC vvkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CRtDJNrz; 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 c10si439086edn.316.2020.09.24.14.37.10; Thu, 24 Sep 2020 14:37:34 -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=CRtDJNrz; 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 S1726397AbgIXVfW (ORCPT + 99 others); Thu, 24 Sep 2020 17:35:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726239AbgIXVfV (ORCPT ); Thu, 24 Sep 2020 17:35:21 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F16CC0613D3 for ; Thu, 24 Sep 2020 14:35:21 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id d6so788163pfn.9 for ; Thu, 24 Sep 2020 14:35:21 -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=3CW8CM9pV/u4FfPt/5+0+4IcrrDDgdR3Q+VzmdoOROI=; b=CRtDJNrzy8wbkCV74afPa/S3o604Di/g6RRZLW1jbvaELJCnfqJ5X54uFz+2y4YVd+ JMjENCSOJ8WiO+/T8ChnYyaZuJsyEhQOs0Plk7trxC06nHNaxqpOcT8y+sEuG5d/YU/D b9pHibkXtd7atL74qEQo+eWeQ6auJ2I9asgk8= 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=3CW8CM9pV/u4FfPt/5+0+4IcrrDDgdR3Q+VzmdoOROI=; b=oXO04SwE5yn0e5rHsXBDCHGE1uzZeEHIFbNSgSI9WA5gYI8QhUi67nGzsexJn4Atlp 23+3K0+3fRFVK8dPmGr2YNkU/KEuXQHoVTxlCgn6tSBkCghPeGJ9Pe4dcHEVa9Z7Px9B bjsWmen27nqT+DyUAOxN3aPGzARrh0VTxM0J5E03k4rJA5IVHEdTNPFvZNHxywPxZp9F 7Ig5qvTx77yTQKJciFBeVoww6FGbrv8pqYqgHQukiYjof/Ti9ZsM114OhXFE789tCntK h+uwqOYaP19cCFJrBTuguQdV8ob8GvAJv5WgTRMD46/Q178CMwSk66WZuy8718R8YEBg oJSQ== X-Gm-Message-State: AOAM532zsX+XNXXenEisU4J3P8D/eElQLVUFDBlLPg+agok1PO7lfchG D9qsqvkgVy3vTdPHSb4in2vxNg== X-Received: by 2002:a62:e107:0:b029:13c:1611:658b with SMTP id q7-20020a62e1070000b029013c1611658bmr954182pfh.8.1600983320933; Thu, 24 Sep 2020 14:35:20 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 64sm378291pfz.204.2020.09.24.14.35.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 14:35:19 -0700 (PDT) Date: Thu, 24 Sep 2020 14:35:18 -0700 From: Kees Cook To: Paul Moore Cc: Tom Hromatka , Jann Horn , YiFei Zhu , Christian Brauner , Tycho Andersen , Andy Lutomirski , Will Drewry , Andrea Arcangeli , Giuseppe Scrivano , Tobin Feldman-Fitzthum , Dimitrios Skarlatos , Valentin Rothberg , Hubertus Franke , Jack Chen , Josep Torrellas , Tianyin Xu , bpf , Linux Containers , Linux API , kernel list Subject: Re: [PATCH 4/6] seccomp: Emulate basic filters for constant action results Message-ID: <202009241434.CF8C1BA1D@keescook> References: <20200923232923.3142503-1-keescook@chromium.org> <20200923232923.3142503-5-keescook@chromium.org> <202009240038.864365E@keescook> <202009241251.F719CC4@keescook> 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 Thu, Sep 24, 2020 at 04:46:05PM -0400, Paul Moore wrote: > On Thu, Sep 24, 2020 at 3:52 PM Kees Cook wrote: > > On Thu, Sep 24, 2020 at 11:28:55AM -0400, Paul Moore wrote: > > > On Thu, Sep 24, 2020 at 3:46 AM Kees Cook wrote: > > > > On Thu, Sep 24, 2020 at 01:47:47AM +0200, Jann Horn wrote: > > > > > On Thu, Sep 24, 2020 at 1:29 AM Kees Cook wrote: > > > > > > This emulates absolutely the most basic seccomp filters to figure out > > > > > > if they will always give the same results for a given arch/nr combo. > > > > > > > > > > > > Nearly all seccomp filters are built from the following ops: > > > > > > > > > > > > BPF_LD | BPF_W | BPF_ABS > > > > > > BPF_JMP | BPF_JEQ | BPF_K > > > > > > BPF_JMP | BPF_JGE | BPF_K > > > > > > BPF_JMP | BPF_JGT | BPF_K > > > > > > BPF_JMP | BPF_JSET | BPF_K > > > > > > BPF_JMP | BPF_JA > > > > > > BPF_RET | BPF_K > > > > > > > > > > > > These are now emulated to check for accesses beyond seccomp_data::arch > > > > > > or unknown instructions. > > > > > > > > > > > > Not yet implemented are: > > > > > > > > > > > > BPF_ALU | BPF_AND (generated by libseccomp and Chrome) > > > > > > > > > > BPF_AND is normally only used on syscall arguments, not on the syscall > > > > > number or the architecture, right? And when a syscall argument is > > > > > loaded, we abort execution anyway. So I think there is no need to > > > > > implement those? > > > > > > > > Is that right? I can't actually tell what libseccomp is doing with > > > > ALU|AND. It looks like it's using it for building jump lists? > > > > > > There is an ALU|AND op in the jump resolution code, but that is really > > > just if libseccomp needs to fixup the accumulator because a code block > > > is expecting a masked value (right now that would only be a syscall > > > argument, not the syscall number itself). > > > > > > > Paul, Tom, under what cases does libseccomp emit ALU|AND into filters? > > > > > > Presently the only place where libseccomp uses ALU|AND is when the > > > masked equality comparison is used for comparing syscall arguments > > > (SCMP_CMP_MASKED_EQ). I can't honestly say I have any good > > > information about how often that is used by libseccomp callers, but if > > > I do a quick search on GitHub for "SCMP_CMP_MASKED_EQ" I see 2k worth > > > of code hits; take that for whatever it is worth. Tom may have some > > > more/better information. > > > > > > Of course no promises on future use :) As one quick example, I keep > > > thinking about adding the instruction pointer to the list of things > > > that can be compared as part of a libseccomp rule, and if we do that I > > > would expect that we would want to also allow a masked comparison (and > > > utilize another ALU|AND bpf op there). However, I'm not sure how > > > useful that would be in practice. > > > > Okay, cool. Thanks for checking on that. It sounds like the arg-less > > bitmap optimization can continue to ignore ALU|AND for now. :) > > What's really the worst that could happen anyways? (/me ducks) The > worst case is the filter falls back to the current performance levels > right? Worse case for adding complexity to verifier is the bitmaps can be tricked into a bad state, but I've tried to design this so that it can only fail toward just running the filter. :) -- Kees Cook