Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7708463rwb; Tue, 6 Dec 2022 08:56:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf5EPfGDiodgguKIXXzolRJpgL1PHP3/pUGSRIPANFEXgFYZSzvW68Ff4oLj51SIIkVMyfWj X-Received: by 2002:a05:6402:505:b0:46b:aa:856a with SMTP id m5-20020a056402050500b0046b00aa856amr39581634edv.171.1670345782950; Tue, 06 Dec 2022 08:56:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670345782; cv=none; d=google.com; s=arc-20160816; b=Xe4Ix3Z8qQ4+rSvJRfo1XMqzUkgoNIm1qDTDCfS02BrMh/xARApnpbAHV2gQHmYbx0 tKPFin55q2CeSodTvOYhVULPSB9OrWEAbAYyX0bOd95cuT8ek0UxoTZFw7PwPjb6WsLK 1VuRKzLE44ARswIM1GkejKOuSfvxGbCWKsqEOM3XKROKsTpm89NcMcE1hyeOg+jd3gei I5mx6y3wmKAqFlICAeBBZoNRjrABgJe2v5aTDrLolgUBGX3gweijD1W5zA6czur0YoO2 +3N4Ie6VuDaPv96uxKnQiL8fr4xjENX66yaDlXIbo4odwVS+fH27otsufzUlHb/M8z0A OEkw== 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=kMLZzJ1FZuH4nLPo+jEbrPYP/j/5iDkl5dcaSiZ9uGg=; b=0291wW5HDzbo+6PZWnI503eexTgNJe89jkIhp6FffkKEMl2IZZFapA4Wd3r6plmEBv 3rkUCsUKckZ3noSjo695JenHzAb9zTX6Icb9v6p5hK7YcSSFE1rTJiYLhlV22/IqtZiO nu+gPNraHq3kJcEakJ2qCr5y6wgjhf7YQJ2J7Li2BYkncCfNAx4cHVXDXS6SdNrFmWD9 vjyH337lTGG6sQO/XXbA3A9PkYTNlLT0VYzOHAq3F55ZlSnycfydGs8n+bA6Bu15a484 MAjZFj7OVoaCCiJO/Hjdbzhoo7mgwMxEU3nZDtHXqN/1y13BC+y2FZuWlXta7TdECWiL U0lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PYt4F+B6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hu8-20020a170907a08800b007c10bb5b4b3si1804906ejc.681.2022.12.06.08.56.03; Tue, 06 Dec 2022 08:56:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PYt4F+B6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235416AbiLFQgo (ORCPT + 77 others); Tue, 6 Dec 2022 11:36:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234599AbiLFQgO (ORCPT ); Tue, 6 Dec 2022 11:36:14 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2271DB2; Tue, 6 Dec 2022 08:35:35 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 51C1FB81AB2; Tue, 6 Dec 2022 16:35:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 425BBC433D6; Tue, 6 Dec 2022 16:35:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1670344532; bh=xLPfb9uCpOGAMWazbtHia2mg57Cvx5Vy+jhdYipW07Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PYt4F+B6zxS4blgAEKoWiYg7l3jca0OPluig0ko3yvCJEICgp9uHUMKVfQ+H1hrNu QP74wZEjlBTLdO6+wWL2tm28BVWMHF/mKUDSK6kQ2Q9xdQUcW/rGgavWKKU326bChP Tt9KveMsw9qXnuDJVTCGwTZ+vyRKDJV0X5STADsU= Date: Tue, 6 Dec 2022 17:35:29 +0100 From: Greg KH To: Jeff Xu Cc: jeffxu@chromium.org, skhan@linuxfoundation.org, keescook@chromium.org, akpm@linux-foundation.org, dmitry.torokhov@gmail.com, dverkamp@chromium.org, hughd@google.com, jorgelo@chromium.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, jannh@google.com, linux-hardening@vger.kernel.org, kernel test robot Subject: Re: [PATCH v5 3/6] mm/memfd: add MFD_NOEXEC_SEAL and MFD_EXEC Message-ID: References: <20221206152358.1966099-1-jeffxu@google.com> <20221206152358.1966099-4-jeffxu@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 06, 2022 at 08:26:30AM -0800, Jeff Xu wrote: > On Tue, Dec 6, 2022 at 8:04 AM Greg KH wrote: > > > > On Tue, Dec 06, 2022 at 03:23:55PM +0000, jeffxu@chromium.org wrote: > > > --- a/kernel/pid_namespace.c > > > +++ b/kernel/pid_namespace.c > > > @@ -110,6 +110,11 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns > > > ns->ucounts = ucounts; > > > ns->pid_allocated = PIDNS_ADDING; > > > > > > +#if defined(CONFIG_SYSCTL) && defined(CONFIG_MEMFD_CREATE) > > > + ns->memfd_noexec_scope = > > > + task_active_pid_ns(current)->memfd_noexec_scope; > > > +#endif > > > > .c files should never have #if in them. Can't you put this in a .h file > > properly so that this does not get really messy over time? > > > > > Thanks for reviewing. > It seems to me that checking for CONFIG_XXX is common in c code in > kernel/ path. Maybe, but please don't make it any worse if at all possible. It's tough to maintain code like that. > Do you have a sample code pattern (link/function) that I can follow? Any of the zillions of #if statements in .h files :) thanks, greg k-h