Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1702720pxk; Tue, 1 Sep 2020 05:55:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzd+1P9ta/JOzN3q2A8IRg3ZfrHstMhMgZ3ahzNvsD9oAXhdVFFEHeMtxR/qHGZ+Bh7d9uS X-Received: by 2002:a50:e846:: with SMTP id k6mr1530749edn.27.1598964935508; Tue, 01 Sep 2020 05:55:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598964935; cv=none; d=google.com; s=arc-20160816; b=uELGOxPfDTSDv2HrL8n5eK87xqx1HbClbxG+UvFhM+12V2h6XNIr7NLr9JMPtXYXJs b3sAQL0Q5flXbeW/roXoT0mdaMJwY20i6HJAVvAnWfkNMeD7J7aPrsScVjTGXG/Pm17n fWsbxwpekBToXa+ZsaVIZETyM7+JgD0uk5WW+a+yKBUcKJ1oM8pR/FSqBkrdqSZqgDXv Wy8+IBSZPpdEpeN9Q941XNipaVsa4mOaB2PH26xjSIvinOZFxVXWYOv/GptQfXevfPbQ i13QfreeceqcTkUcAbdag+VcrxJxll3lBmsHIJEDNbey8RqpkE4H7rkLbKUNo392sB7t A3hw== 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=iI0SrUIACVJA7obOlDZv4VfQM+63a4373yCSLDz4How=; b=ZjN85YnzD5F7whnqrjGSfvYjTRLhJ8BS18EyI5+bG3FmBovNjAS5SRWw784wTrh9s6 DGAfgyg2RwKHHhJ3fV9Qtjieb9FWJhU7F7b+pUsPbK6OVNaiKbx/zZdatuubcoaXCI0W Cdg51EagAQkR9/VYxBeVmqC0RFo+2HSyGCgQO7fa6E3oospboR57u+QwEV1UUHMNDJQg RbNo5UtqScAGmQw99VU02j7FfRmj/M+XgeU7y6YZB5Au0OaugHEukuC40Q55ZAZ+XESn w/wWj+TtF+ZPhntO9VR9+/Q7IL/YfWNJBEPmsqKAULeZogvM0Tbpj1dhuonr2uSQVD9J ng1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cFQyodSg; 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 d20si586273ejz.445.2020.09.01.05.55.11; Tue, 01 Sep 2020 05:55:35 -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=cFQyodSg; 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 S1728089AbgIAMwL (ORCPT + 99 others); Tue, 1 Sep 2020 08:52:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:51126 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728110AbgIAMv1 (ORCPT ); Tue, 1 Sep 2020 08:51:27 -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 BD45E206CD; Tue, 1 Sep 2020 12:51:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598964680; bh=yg/250nrats4qE+SuiX9Do3DhW2WXHg0wipMKKK8bH4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=cFQyodSg+2l6w6kPeibO0GULGs+Vsdkq6mUZbBbB5HGS0lWEaxH3w8+UWZFU4Hh7N 08r5Ll27IpCpWu8h/3ol2IhRiKpdeQ4ieDBKZs/W+ZuX+q2UWmD3ZbFZKayubGFjH0 GPjXzsbINdvnQoMFKAdsfrLGSL5HX6OiTvvCzU/c= Date: Tue, 1 Sep 2020 13:51:15 +0100 From: Will Deacon To: Jessica Yu Cc: Ard Biesheuvel , 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: <20200901125114.GA3307@willie-the-truck> References: <20200812160017.GA30302@linux-8ccs> <20200812200019.GY3982@worktop.programming.kicks-ass.net> <20200813130422.GA16938@linux-8ccs> <20200821121959.GC20833@willie-the-truck> <20200821123036.GA21158@willie-the-truck> <20200831094651.GA16385@linux-8ccs> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200831094651.GA16385@linux-8ccs> 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 Mon, Aug 31, 2020 at 11:46:51AM +0200, Jessica Yu wrote: > +++ Will Deacon [21/08/20 13:30 +0100]: > [snipped] > > > > > > 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? > > > > > > > > > > That should work as well, I just haven't checked how straight-forward > > > it is to change that. > > > > Ok, if it's _not_ straightforward, then let's just drop the IS_ENABLED() > > altogether. > > Unfortunately I've been getting more reports about this issue, so let's just > get the aforementioned workaround merged first. Does the following look OK? > > diff --git a/arch/arm64/kernel/module-plts.c b/arch/arm64/kernel/module-plts.c > index 0ce3a28e3347..2e224435c024 100644 > --- a/arch/arm64/kernel/module-plts.c > +++ b/arch/arm64/kernel/module-plts.c > @@ -305,8 +305,7 @@ int module_frob_arch_sections(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, > mod->arch.core.plt_shndx = i; > else if (!strcmp(secstrings + sechdrs[i].sh_name, ".init.plt")) > mod->arch.init.plt_shndx = i; > - else if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE) && > - !strcmp(secstrings + sechdrs[i].sh_name, > + else if (!strcmp(secstrings + sechdrs[i].sh_name, > ".text.ftrace_trampoline")) > tramp = sechdrs + i; > else if (sechdrs[i].sh_type == SHT_SYMTAB) > > If so I'll turn it into a formal patch and we can get that merged in the next -rc. Acked-by: Will Deacon Will