Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp612680pxk; Thu, 24 Sep 2020 13:50:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzm4qnhjEaq2ywAF9nvxmq0kDMo5Pu1P2ep0uWf1XNuKwx+5LYEJuPuc8LXO+2d0+0ff02t X-Received: by 2002:a17:906:a45a:: with SMTP id cb26mr451192ejb.387.1600980624617; Thu, 24 Sep 2020 13:50:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600980624; cv=none; d=google.com; s=arc-20160816; b=JBLUX4GdNr3Np/os7XhcWdjyg9/vKzkCARsuZLZuZKmOgB/7/Gp2AAGSNwI46e0Ird vmUO8h8vhGG5ByDLRONCE/Jb0CBesYbWs1X/GI4bYhZwqOt+2u64/d82s/YRBDWxOPZA rrg/a5ceSKim7EKgoQvzdK9+lIlUfAhyI21pMh0bGdGJiM6uRF9ft6QQFTDfi9/IoKE2 bypg6c1CcEqXRS9IQfi5lQmVQq8FMCjvKDpyy8C9SMidwYz+mrjuTRrccbcMCya27ndw IVTUg6rnGNfWLxT3ah0Qwe91RyXJ3PhhtLMHb0FJ35ptFDiukFiYgzUSPaq5k5XaMw/7 qrXA== 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=hNWgf5JR/cvx4+k2/k8//+NsLRafA9SikURsJTJxHl8=; b=zGwaeDO8ndDz49e7FnwLaghyxV3WrDpIiUSy7a/tivAVT3r4SG0G9fKsatwGCUhDOZ t1njjgc9qSOQkgC4v4a2AY6IMT7XbyfdbKou0Ft4GeANtOa1qqrcFAtA7SqCK/bZ8Ns0 JJH3S5B9O07tWRuinitgsAu5Xeypp8+4LqthGQY+HUNSnHZQBDyA/7uSC6k9LTmpL3br MYd90sdeB/rn/eqh5UUUUSioo3azkB+xiqKDHmlFonc5OLcZ4pgfOjaM9b+syq5gWDsy yBTmfujZKDJPX915ZbyEicAjwDyqvGUlYC+9pmFzEYhAjZf3V8kWFRo9FD6J7ee1LrJW tvcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b="N/W4hr3E"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v18si435304eda.321.2020.09.24.13.50.00; Thu, 24 Sep 2020 13:50:24 -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=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b="N/W4hr3E"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726239AbgIXUqS (ORCPT + 99 others); Thu, 24 Sep 2020 16:46:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726210AbgIXUqS (ORCPT ); Thu, 24 Sep 2020 16:46:18 -0400 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00AB1C0613D3 for ; Thu, 24 Sep 2020 13:46:17 -0700 (PDT) Received: by mail-ed1-x542.google.com with SMTP id j2so272050eds.9 for ; Thu, 24 Sep 2020 13:46:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hNWgf5JR/cvx4+k2/k8//+NsLRafA9SikURsJTJxHl8=; b=N/W4hr3EM1UoBKdrsToiPIHVsXsZea5kjUdS8aVBO0VqX+vlNG+bO2voUqHrH92lkx v+cCb7BIpfE7J0COXu9ZveiX7hBiBESo1VPhidpBI1JkRyqPepo3jqNxoErSa7ggD7Bj MLUMxpjuK+mfC0nMTCX4DLvJzLTliYNOhloeeWBzNrArRN2m8nCyPvgHXMO/qRm9xIP9 yDphfjjdEEvwDc1H58P3k8bEMGyF3FdmngMgF+y095/bdm8FGMsTS2nWw1Bvs8iIGz40 6fSaqQQ8BTbKoWXpnnOg8j1RUBcZ/ah40mqYQZ90MYPclO65VlQGxG253bBnA8WCIAyt MFzA== 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=hNWgf5JR/cvx4+k2/k8//+NsLRafA9SikURsJTJxHl8=; b=n5iAqduTonhEsEIIJSP6/Azszeqz/6IWF1YEXzCtWraQAPySS3fMXeVsqmIBv7qLBw r8H4i2VJX9D0jDhmsTqP1kkKROlnAX2HnrJ+mGpKz5omrlURmb5/dOx4+DW0CAuD31zD 5qVtKjRuZ87fPeH6lFaSX7emSOu4SPIT6TmIvWwkrfSevuvkmcCXLkWy3som6OPdlplp 7p+6tXBtyPu2CzioWwjPIx6JYSnsJaymznXm2WwszKO/d+5HRgW+IXIa69u/EBj1cluK wnVkYW/U6jAkj+zCFgEFO/l5N03zzazht2m1NEQw3Fme6Oloc8NEsd64ncxjBzT7dcXK rRSw== X-Gm-Message-State: AOAM530oMzv6r8UcnSTBTBQdiE7ni8hKDXSS7zGnU7BeGbdViUMuKa+L cFNwuXsDj4QxwYcoBwU6dTDbsbCrif8ggWgvWuhn X-Received: by 2002:aa7:cd06:: with SMTP id b6mr625058edw.196.1600980376408; Thu, 24 Sep 2020 13:46:16 -0700 (PDT) MIME-Version: 1.0 References: <20200923232923.3142503-1-keescook@chromium.org> <20200923232923.3142503-5-keescook@chromium.org> <202009240038.864365E@keescook> <202009241251.F719CC4@keescook> In-Reply-To: <202009241251.F719CC4@keescook> From: Paul Moore Date: Thu, 24 Sep 2020 16:46:05 -0400 Message-ID: Subject: Re: [PATCH 4/6] seccomp: Emulate basic filters for constant action results To: Kees Cook 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? -- paul moore www.paul-moore.com