Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp410498pxk; Thu, 24 Sep 2020 08:31:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZWHVN5bOP0/6ET5z1vCb1blSQSaglUIwc/5cfTNIj+3TL+RWeiuiQBan0HtpZJWvxshJl X-Received: by 2002:a17:906:c2d2:: with SMTP id ch18mr469044ejb.79.1600961481592; Thu, 24 Sep 2020 08:31:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600961481; cv=none; d=google.com; s=arc-20160816; b=kdHMKIhH36mJnL6dFjMwrkw4cbVFkjuvgaHi+a2LZzxoYo+iEkxvBWtcLUxZzFmLG7 CICNGviYaluh3l13lTEDfInEgG3rPAPXb5ivHkQSy4j6VQ+XSNwDWtXFRYCsvkOoLUG5 O+ybEL3OcH1nmkt4qSHCFV9te5LsDV0v0ilt2RomR8jL48BUSPn3s8apW4zBGsN7huns ciqpJQFPlCJrp3MaQAOcSndURh2vF0T12+Fmt0OjaCO/X4H4L+D+jRoVeSKxBNRR3Dne n9jZNKo5WbfilSyBsNnL2pWyWoUScGtn1R+znee6GYdANi+cN6MSmwnRsb4K3ix0PUOl D61w== 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=DWwrSFR+XsVbo72EXCPGN7Yvsrb6I0oZs+oVxjkh+2I=; b=zOJqy3GjC6T2JWQxBQY8rljp9QkXzttz+ud0vkWmLi9GvR5yJahwgyj825urPQhXsR doxsQCj+H8DDZXxknMGjQiZYHPi7S0mikpADFB70gF9skpeYfyxS/AH5yPiK4W/7H890 0inZl5vyrRi7t5Ed7nmduDf2a+uEND8in1BHLuACOXHYY59DR51JEJIlyHG0RfOu+RsH REnJ9+6x8+meyqchPn2temGOkFF9NJgi6C2MOx7FyZ9SsvnEBn2rVh+/Ar8oVi0aKKoZ 42FgvXCXr5PMrJeLo7pE1QZZ0gGDq5iXWcB1LIROGyodqAZ7pBPflaVjrwjUGi68JrHc s2NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b="hN3JCT4/"; 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 i22si2347728edy.183.2020.09.24.08.30.56; Thu, 24 Sep 2020 08:31:21 -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="hN3JCT4/"; 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 S1728507AbgIXP3I (ORCPT + 99 others); Thu, 24 Sep 2020 11:29:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728350AbgIXP3I (ORCPT ); Thu, 24 Sep 2020 11:29:08 -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 B082DC0613D4 for ; Thu, 24 Sep 2020 08:29:07 -0700 (PDT) Received: by mail-ed1-x542.google.com with SMTP id ay8so3770032edb.8 for ; Thu, 24 Sep 2020 08:29:07 -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=DWwrSFR+XsVbo72EXCPGN7Yvsrb6I0oZs+oVxjkh+2I=; b=hN3JCT4/0mr9lHn1el6A+W9IHJhVcZfLNiBn+2+2ptYhZ2E3ln93PIdOTyrZm4MsWg 0pPA5aEFZnOI3KgY8otAO4fYpSdYshKnZ4CmKXSbw5JqMttXF9UPXapl5M86DohboovX I3ro4WAml5gPUcfGG3zbCTYxhnoAJoBotyNRCrSyqpZDz/gaQeuJnjABGulXeW+vgul2 WfLGjGxh/urIx8OZzhTSMu8/a21/AzyXO11afB8SfNqZpdfRIv+08n215LLwBniNZZEh jK3alXiJ//9LzmOTJndQYIOo7J2mNf+tk68S7tAY55J1Ph4eY4IoKrvEDEnzodg3nw3v 1Idg== 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=DWwrSFR+XsVbo72EXCPGN7Yvsrb6I0oZs+oVxjkh+2I=; b=JmyxrOt2YRq3hGXPkweA94dR8LWkHsH+5yJ4Sl3gpEQOgmR7OU4/Mbl7TajfY7DwyD s12Ti+Os7RXl+X3nw5JS/GfKSPvlgbABefznbMbkhB0fLZ7O6QYgGL40IRppII8IuCQE XUO59NHz81gCXNQbnubuLxwxEiSDIZa3CtyUIXOwHG132zehe1kHmcPnc/FynnrimksI FvxYJj8o6761gSUNGsc3zUU5lbCj9fmq0DE8XWmrrBvp9aaIOXV1LxqkbI8vgoH9gBo9 arWjMwSgtPNonxTe3mtV0un13FqM4GFW8MAgdombaRdP2pGWMx++C0ybkWPoG09TyCIL mbmA== X-Gm-Message-State: AOAM531lG642n7LiPFREQfGc3IEQO4S7Km7M+xwmMrW3ZLTaYc8uUtco 8ZYjlqy6BododAS2428kl6fpm+3rxmtSitbSC8Es X-Received: by 2002:aa7:ce97:: with SMTP id y23mr494977edv.128.1600961346147; Thu, 24 Sep 2020 08:29:06 -0700 (PDT) MIME-Version: 1.0 References: <20200923232923.3142503-1-keescook@chromium.org> <20200923232923.3142503-5-keescook@chromium.org> <202009240038.864365E@keescook> In-Reply-To: <202009240038.864365E@keescook> From: Paul Moore Date: Thu, 24 Sep 2020 11:28:55 -0400 Message-ID: Subject: Re: [PATCH 4/6] seccomp: Emulate basic filters for constant action results To: Kees Cook , Tom Hromatka Cc: 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: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. -- paul moore www.paul-moore.com