Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp891979ybb; Wed, 8 Apr 2020 11:56:08 -0700 (PDT) X-Google-Smtp-Source: APiQypKcQ0xvAx83ahxIoOkV3u5QaQtV7ZepoyxeFrJ68OBtHg9WB6n+UBREnlP7tmQNP+yNfGgs X-Received: by 2002:a05:6830:1d90:: with SMTP id y16mr7087207oti.157.1586372168264; Wed, 08 Apr 2020 11:56:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586372168; cv=none; d=google.com; s=arc-20160816; b=xRbTe+RMw2L2a7OYV4KZi5Ao0u2vwdQWZFzoIJLhEoxDeiimVDQoLZTxYgSkmeE4S/ fOhqg1qYMnOeFl3PiV53WCUiGdZLArLA8zXmWsbgxGuKVAxv7HdmNyKazHKKqitUNb9j 3dMVcqz/At5Pyt3STAfsrOWTa3kVm9QL7JbEGoplIa4Jw+30i0fWkB0E7nXx0DqREBqo zjnSCXqoERSqRJWKO+Y+tJPyXzXijydXEE3V0cwPRsosSKs6Q8q2+KyMf7gj2J//3aT8 UmrfkfIpnQXMqaF9gz1Ja8FyfoC+HvtydSsoL5xLqZKVTjg2+xgQjl3/lmWBS6Nvyqhi 0Z6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=I046T5NYEXXComMYfFLIbN9Cazs44K1u/PrUj66bzFg=; b=Wt8vFvN0wmBD10RZAebbBWewzQZLpq19AVEnMcfBT6Wmhsq/qrWclxD9sFDESYcF6J tzvS/l7ikgAskzoAFI9ZcTJGO3BdArrfXqK2vGtR6Tj8/s5yh/bxB6jjqyibEpdN9XI+ L4hqvJAqKkb68+V9LRDZh6wUM19xIoVDn1boHVlXped/ncmkTgNmoXFIEc85OWJcDJVU BzZT4tj2ovqcLNInZoV0iQHb7CZqgL4xsXCcHeo6sC8gEfflArBVbyhq+qNUju63P8mL On8O0vcGwefH9TRBPiVhVFxduQ+vcIezQzNgsdKkP1+UBk2gr1CTZTIPfbN7kYhWqphK w5zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=HmTprzgO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 15si2367801oix.96.2020.04.08.11.55.55; Wed, 08 Apr 2020 11:56:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=HmTprzgO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729648AbgDHP5Z (ORCPT + 99 others); Wed, 8 Apr 2020 11:57:25 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:50572 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729506AbgDHP5Z (ORCPT ); Wed, 8 Apr 2020 11:57:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=I046T5NYEXXComMYfFLIbN9Cazs44K1u/PrUj66bzFg=; b=HmTprzgO5Copd6ZM1O4M8f7lqo f8qIXu5dpV028o2e5sdn8xVqUUhTBYMQR+GMGt+hJ1IJecOoARrlIKWLg415az9UIqcusPvyl8uz+ miEvVeFzuoWIwXHmxbpQn9kXE0Zas5RB8foRfxDbRqXEE1JvZqQnSEP/BR14QJ8RGny6GZPORiuzW 3zPAsgt0GKmqaDA5wfUroIwZzNwWqa5Oyt6/WJuuqfiC3vdwvl5PUdye6VavZzTWOkYtVAE4iIArN cvABGFvjeu//zLY3E1yYaVOEUFd/poCBrOiG2T2x6VW/3y6aif4Ofo8fqQH8SGVdD4lSSL/d/1spP ewOsulXA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jMD4r-00074a-PV; Wed, 08 Apr 2020 15:57:21 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id BD0BA300130; Wed, 8 Apr 2020 17:57:19 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id AE5DA2BB02700; Wed, 8 Apr 2020 17:57:19 +0200 (CEST) Date: Wed, 8 Apr 2020 17:57:19 +0200 From: Peter Zijlstra To: Jessica Yu Cc: linux-kernel@vger.kernel.org, Thomas Gleixner , keescook@chromium.org, Josh Poimboeuf , Miroslav Benes Subject: Re: [PATCH v2] module: Harden STRICT_MODULE_RWX Message-ID: <20200408155719.GQ20730@hirez.programming.kicks-ass.net> References: <20200403171303.GK20760@hirez.programming.kicks-ass.net> <20200408153249.GA26619@linux-8ccs> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200408153249.GA26619@linux-8ccs> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 08, 2020 at 05:32:49PM +0200, Jessica Yu wrote: > +++ Peter Zijlstra [03/04/20 19:13 +0200]: > > > > We're very close to enforcing W^X memory, refuse to load modules that > > violate this principle per construction. > > > > Signed-off-by: Peter Zijlstra (Intel) > > --- > > kernel/module.c | 25 +++++++++++++++++++++++++ > > 1 file changed, 25 insertions(+) > > > > --- a/kernel/module.c > > +++ b/kernel/module.c > > @@ -2044,9 +2044,29 @@ static void module_enable_x(const struct > > frob_text(&mod->core_layout, set_memory_x); > > frob_text(&mod->init_layout, set_memory_x); > > } > > + > > +static int module_enforce_rwx_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs, > > + char *secstrings, struct module *mod) > > +{ > > + const unsigned long shf_wx = SHF_WRITE|SHF_EXECINSTR; > > + int i; > > + > > + for (i = 0; i < hdr->e_shnum; i++) { > > + if ((sechdrs[i].sh_flags & shf_wx) == shf_wx) > > + return -ENOEXEC; > > + } > > + > > + return 0; > > +} > > Just to clarify, did we want to enforce this only when > CONFIG_STRICT_MODULE_RWX=y? Because here it's still in the > CONFIG_ARCH_HAS_STRICT_MODULE_RWX block. > > Unfortunately, when we add module_enforce_rwx_sections() in the > CONFIG_STRICT_MODULE_RWX block, we'll need two empty stubs, one for > !CONFIG_ARCH_HAS_STRICT_MODULE_RWX and one for !CONFIG_STRICT_MODULE_RWX. > > This is because the CONFIG_STRICT_MODULE_RWX block is currently nested > within ARCH_HAS_STRICT_MODULE_RWX :/ Yeah, so the primary reason it's under that ARCH_HAS thing is indeed the mess and the extra stub required (I'm a lazy sod at times). I then rationalized this decision to myself that having it under ARCH_HAS give a more consistent module loading behaviour. But I really don't care too much, my most my .config's have CONFIG_MODULE=n, and the ones that do not very much have the STRICT_RWX set. Put it where you think it's best. Thanks!