Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp208269pxa; Fri, 21 Aug 2020 05:22:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzS3Y4ds4YAQwCnyjdLIXpki40tDuzJDM7/Ohgnn5QM4/C8XJG1QiydpyxJ0v1NmB70lJeM X-Received: by 2002:a17:906:354e:: with SMTP id s14mr2460687eja.327.1598012567489; Fri, 21 Aug 2020 05:22:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598012567; cv=none; d=google.com; s=arc-20160816; b=mRCBc4fMiY9y13EBN9SiHNV/HdHF9YekkmXQTmJ+79IULnJ/DvCAO0lxhI36Pm4SDE tWhnJ+xFJD2m1qBw3zLGwlvxwLWFSsrRfbgq1lP86gK6nLZmKIeLcnrEJq16SEUPv7Bu fh+7y54UfBkD9hehIBc2Y2I8yCcO527o4CdKs6+t7i/KF78KiyPyMhPAeAqn+fJ2UbIF TFFmpjZZVAG39XtwCtMGJ+tv6zdJB1Yx7vjtIMF4/dMouLS4JG71zMRZ8ZQkPVWkMe2i YKw4YW9DeZxk+WTFhWVUygI2IBKmtVLWbRwoWts5V2ZnOf7JdzIA7TNdkXg3x39ACFNM Vu9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ZMKN/9csDjXon2aEn9d8MqPEAuj8eBg8iokVwxMZJ/E=; b=ZhmYTV8Vs2kSF0zeIBzbVYzzB+4+9UnpZTphbYZMHArApnOl9gO5k0G0SjnVut7L6a GgbigjrSyNeLLZwf5Oq0dufycLtbIj2LYG/NTBRO1lNuPgiVGYXC75U6hHqzr3lWsKUz QzEYqJUNh3bMpybGSed5Pge94U46DAITqzU1RUVgNiTNB8589r5PhE5GBlKfwI4xQV2r xK4v2T6/CCsVAp5x9b6jvIM2Uh+Tx2LPBt4Wdvmj/iJC+V2BW8r2TC83IHwuxIXST4tb 7mWAbXtQNtcUgZhvtQsAeDCAVPhX6frJu/x5anUsAf8kh4uloKuuuk687uXQOjTb/O+d W+aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Lu/9DkAt"; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n19si1088511ejc.243.2020.08.21.05.22.24; Fri, 21 Aug 2020 05:22:47 -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=@kernel.org header.s=default header.b="Lu/9DkAt"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728582AbgHUMVN (ORCPT + 99 others); Fri, 21 Aug 2020 08:21:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:53938 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728305AbgHUMUG (ORCPT ); Fri, 21 Aug 2020 08:20:06 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7E9C920724; Fri, 21 Aug 2020 12:20:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598012405; bh=dyzu8JJ2FTVbgIo72WlGH/VPEaryNWuRCr3LcXdqh4U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Lu/9DkAtOB95J4Ms4k9gmDWfffQIS72eFLvyILY0YFPx/9OPsNw7L9blTvB+RML2e cHAKxOgMKoyELaprbdI0V5apssBPfSPYWc7PFijT3N0ro9KWOqjzyldA+NaTv+6Ram /dTH146HYvby4S9XHjrCAIgHqL25RK7OLHgOiQQg= Date: Fri, 21 Aug 2020 13:20:00 +0100 From: Will Deacon To: Ard Biesheuvel Cc: Jessica Yu , Peter Zijlstra , Szabolcs Nagy , Mauro Carvalho Chehab , Linux Kernel Mailing List , Thomas Gleixner , Kees Cook , Josh Poimboeuf , Miroslav Benes , Mark Rutland , nd Subject: Re: [PATCH v2] module: Harden STRICT_MODULE_RWX Message-ID: <20200821121959.GC20833@willie-the-truck> References: <20200812104005.GN2674@hirez.programming.kicks-ass.net> <20200812125645.GA8675@willie-the-truck> <20200812141557.GQ14398@arm.com> <20200812160017.GA30302@linux-8ccs> <20200812200019.GY3982@worktop.programming.kicks-ass.net> <20200813130422.GA16938@linux-8ccs> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 13, 2020 at 03:07:13PM +0200, Ard Biesheuvel wrote: > On Thu, 13 Aug 2020 at 15:04, Jessica Yu wrote: > > > > +++ Ard Biesheuvel [13/08/20 10:36 +0200]: > > >On Wed, 12 Aug 2020 at 22:00, Peter Zijlstra wrote: > > >> > > >> On Wed, Aug 12, 2020 at 06:37:57PM +0200, Ard Biesheuvel wrote: > > >> > I know there is little we can do at this point, apart from ignoring > > >> > the permissions - perhaps we should just defer the w^x check until > > >> > after calling module_frob_arch_sections()? > > >> > > >> My earlier suggestion was to ignore it for 0-sized sections. > > > > > >Only they are 1 byte sections in this case. > > > > > >We override the sh_type and sh_flags explicitly for these sections at > > >module load time, so deferring the check seems like a reasonable > > >alternative to me. > > > > So module_enforce_rwx_sections() is already called after > > module_frob_arch_sections() - which really baffled me at first, since > > sh_type and sh_flags should have been set already in > > module_frob_arch_sections(). > > > > I added some debug prints to see which section the module code was > > tripping on, and it was .text.ftrace_trampoline. See this snippet from > > arm64's module_frob_arch_sections(): > > > > else if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE) && > > !strcmp(secstrings + sechdrs[i].sh_name, > > ".text.ftrace_trampoline")) > > tramp = sechdrs + i; > > > > Since Mauro's config doesn't have CONFIG_DYNAMIC_FTRACE enabled, tramp > > is never set here and the if (tramp) check at the end of the function > > fails, so its section flags are never set, so they remain WAX and fail > > the rwx check. > > Right. Our module.lds does not go through the preprocessor, so we > cannot add the #ifdef check there currently. So we should either drop > the IS_ENABLED() check here, or simply rename the section, dropping > the .text prefix (which doesn't seem to have any significance outside > this context) > > I'll leave it to Will to make the final call here. Why don't we just preprocess the linker script, like we do for the main kernel? Will