From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E647C433DF for ; Fri, 9 Oct 2020 05:43:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 25C052222F for ; Fri, 9 Oct 2020 05:43:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="gLtNphPu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731181AbgJIFlS (ORCPT ); Fri, 9 Oct 2020 01:41:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731076AbgJIFlR (ORCPT ); Fri, 9 Oct 2020 01:41:17 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8410C0613D4 for ; Thu, 8 Oct 2020 22:41:17 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id x22so5895265pfo.12 for ; Thu, 08 Oct 2020 22:41:17 -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:content-transfer-encoding:in-reply-to; bh=BtDQZIEMLmhF49jnffnO6s6n101uAcwJbVqfJI9bloU=; b=gLtNphPuxO/huMzVOdahNog6vTAfDxOKzwZr8kuLPoDx3zhHExJBFO1FNqXWYHyQB1 7T1XE/NlhFzFDGSZExn+kdBVZhsW+rVHOhFCneh+yKUT/h46cdWw0qUO4HnlW9dVFynH V0rPgGpCr2hIx9M7HyNH1gY3MnOae078/ROgQ= 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:content-transfer-encoding :in-reply-to; bh=BtDQZIEMLmhF49jnffnO6s6n101uAcwJbVqfJI9bloU=; b=ebJG/07WXhtWX9oa+qQ6az2xk1odb8HlutWWS6jG6QIjA7h2BchAsKDrKM252llDvW b6Wj73CUC52Vzgm/KRrQMxVZmylZmvNTYLIHeV91FF6UmZx0MKoxKaldAaDG7pjI+SQ7 o0+U7TVMwDI2UKmQR1cDWbvtzBhkddq8YTmPg0izRBOz6qZHJVvzzZ79QYfQ7EXxlvJf cgna+2cWZskz3kvZoaTqRap9LQki083VHkFR7LkXqkXwT2f8BIwO8EcwYIqjEQECFpyq PkH4NnsCcKwF02YYz6h+2K64l4HHd5Ji7J+UiopqsrxaRBf2u+UaYKzUxIDWIzEWI9FK ZgEw== X-Gm-Message-State: AOAM532Z6f9qdCOK7miR9qBo+aq6J1Lw2/8rNMNh/2x0u/micxBX3Fgn VJTik7L2FvBURqbirt/ZCHAHkgl9M8eqKA== X-Google-Smtp-Source: ABdhPJx5nhK9QmdRyfBWqhmKPI9k3k7mtwxMc2RozKFPrmPt2YIUBzplio+r3UmWZcjh8f12k2UeKA== X-Received: by 2002:a17:90a:248:: with SMTP id t8mr3002688pje.64.1602222077073; Thu, 08 Oct 2020 22:41:17 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id z73sm9693620pfc.75.2020.10.08.22.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 22:41:15 -0700 (PDT) Date: Thu, 8 Oct 2020 22:41:14 -0700 From: Kees Cook To: YiFei Zhu Cc: Linux Containers , YiFei Zhu , bpf , kernel list , Aleksa Sarai , Andrea Arcangeli , Andy Lutomirski , David Laight , Dimitrios Skarlatos , Giuseppe Scrivano , Hubertus Franke , Jack Chen , Jann Horn , Josep Torrellas , Tianyin Xu , Tobin Feldman-Fitzthum , Tycho Andersen , Valentin Rothberg , Will Drewry Subject: Re: [PATCH v3 seccomp 2/5] seccomp/cache: Add "emulator" to check if filter is constant allow Message-ID: <202010082235.3D6A5F2@keescook> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 08, 2020 at 11:47:17PM -0500, YiFei Zhu wrote: > On Wed, Sep 30, 2020 at 10:20 AM YiFei Zhu wrote: > > @@ -544,7 +577,8 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog) > > { > > struct seccomp_filter *sfilter; > > int ret; > > - const bool save_orig = IS_ENABLED(CONFIG_CHECKPOINT_RESTORE); > > + const bool save_orig = IS_ENABLED(CONFIG_CHECKPOINT_RESTORE) || > > + IS_ENABLED(CONFIG_SECCOMP_CACHE_NR_ONLY); > > > > if (fprog->len == 0 || fprog->len > BPF_MAXINSNS) > > return ERR_PTR(-EINVAL); > > I'm trying to use __is_defined(SECCOMP_ARCH_NATIVE) here, and got this message: > > kernel/seccomp.c: In function ‘seccomp_prepare_filter’: > ././include/linux/kconfig.h:44:44: error: pasting "__ARG_PLACEHOLDER_" > and "(" does not give a valid preprocessing token > 44 | #define ___is_defined(val) ____is_defined(__ARG_PLACEHOLDER_##val) > | ^~~~~~~~~~~~~~~~~~ > ././include/linux/kconfig.h:43:27: note: in expansion of macro ‘___is_defined’ > 43 | #define __is_defined(x) ___is_defined(x) > | ^~~~~~~~~~~~~ > kernel/seccomp.c:629:11: note: in expansion of macro ‘__is_defined’ > 629 | __is_defined(SECCOMP_ARCH_NATIVE); > | ^~~~~~~~~~~~ > > Looking at the implementation of __is_defined, it is: > > #define __ARG_PLACEHOLDER_1 0, > #define __take_second_arg(__ignored, val, ...) val > #define __is_defined(x) ___is_defined(x) > #define ___is_defined(val) ____is_defined(__ARG_PLACEHOLDER_##val) > #define ____is_defined(arg1_or_junk) __take_second_arg(arg1_or_junk 1, 0) > > Hence, when FOO is defined to be 1, then the expansion would be > __is_defined(FOO) -> ___is_defined(1) -> > ____is_defined(__ARG_PLACEHOLDER_1) -> __take_second_arg(0, 1, 0) -> > 1, > and when FOO is not defined, the expansion would be __is_defined(FOO) > -> ___is_defined(FOO) -> ____is_defined(__ARG_PLACEHOLDER_FOO) -> > __take_second_arg(__ARG_PLACEHOLDER_FOO 1, 0) -> 0 > > However, here SECCOMP_ARCH_NATIVE is an expression from an OR of some > bits, and __is_defined(SECCOMP_ARCH_NATIVE) would not expand to > __ARG_PLACEHOLDER_1 during any stage in the preprocessing. > > Is there any better way to do this? I'm thinking of just doing #if > defined(CONFIG_CHECKPOINT_RESTORE) || defined(SECCOMP_ARCH_NATIVE) > like in Kee's patch. Yeah, I think that's simplest. -- Kees Cook