Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp822989ybb; Wed, 8 Apr 2020 10:33:49 -0700 (PDT) X-Google-Smtp-Source: APiQypLksXgBIGs3qTI81+32XrP0tuTWTH7cZ8X0v7iC52v1XvmYg7c6XsVWV3hILAz0TFjI1n7Z X-Received: by 2002:aca:574a:: with SMTP id l71mr3273608oib.148.1586367229765; Wed, 08 Apr 2020 10:33:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586367229; cv=none; d=google.com; s=arc-20160816; b=f34SeUSoU+WCDeHBFZ669yLg1RtUazAmw87cV50U+0YWHQ0E6NerjqyQnK1GV/4whJ s1aAsmpzvsQoS0qeiN6N3y1PEbluPS+K2Sac4Wqmu+63LvWOytxjEiK6xHIjlEdIGnwb EkJiFsc+O9CZg4m77T+UE69hdsn7bHEqJPaAvA9AtGhaGmxRCVia8SdIwdXFWN6wz3aF W9v4bgVhMeEMsKdGaadgsHQBes4HaNyRGn0khQK4krGYrSSVZRxHdkn4bAO4cHwGRG1x /8Kqeqa9dA3QlaJSUCSpAK79w7EVk1oITS3pUh+d38KZEMVLZ+8nhmPjh7yvFVsA/id1 RpVA== 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=Fq8fQtubtfc9GaVaGtisHHAhmfBVEqlmB7WkYjBarIw=; b=QGzK6s3fd3oFBWQQhkknUcMOAFoos7pVmV+pWfgv0E0ApJu9dss9LjmHwXV8A6//wm 9HTjazZKsMpjQ/khj1NY4P5Q+H1iZzu/bVYXjnTWZK/6Wmr6g8IEY2o6Ko2UKAgdVsav Vcr89dMSD0GFIs8Cj07T3q/1vWNjf1fcvm4knFNF/GPCFqHmwGS+pap75R39fWBj013r KO9+pm+quql9YYZSRMAOItUElHL19lN7bifLf/uHLxTjFy3Ija9M0tubG0qKNhD+Ioro Ymfz8HwUfOwLDoEU6b5UWWoL5hxgparF9jK9Tz1/85VoQ1lF8HqYs4BsscYuOznb81ye QHHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=F7lL3+zq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e14si3307470otf.226.2020.04.08.10.33.36; Wed, 08 Apr 2020 10:33:49 -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=pass header.i=@kernel.org header.s=default header.b=F7lL3+zq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729057AbgDHPc5 (ORCPT + 99 others); Wed, 8 Apr 2020 11:32:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:43280 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728705AbgDHPcy (ORCPT ); Wed, 8 Apr 2020 11:32:54 -0400 Received: from linux-8ccs (p3EE2C7AC.dip0.t-ipconnect.de [62.226.199.172]) (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 29D17206F7; Wed, 8 Apr 2020 15:32:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586359974; bh=KR8dtiLzQM0I3iyqbpU/CmxNVf+o2K/a6r8i0w0Cym0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=F7lL3+zq930cGJDkQFlvjc5XwGkBDapjKHOG/9UgM4JsnogiMHRXglF92jzF4dBtJ k58QaErsFbYiAp7A6O8NHs5RlRQJPN7p0kSsuhmxTpE1VGNt/fmS9YAIgYHmbE9vKm 032kuJB/Eh5dFYkwaGL6WDgvjpIuzCRU+WDoFIvI= Date: Wed, 8 Apr 2020 17:32:49 +0200 From: Jessica Yu To: Peter Zijlstra 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: <20200408153249.GA26619@linux-8ccs> References: <20200403171303.GK20760@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20200403171303.GK20760@hirez.programming.kicks-ass.net> X-OS: Linux linux-8ccs 4.12.14-lp150.12.61-default x86_64 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 +++ 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 :/ That unholy nested ifdef mess needs to be fixed. I will post a patch shortly that gets rid of this nesting and you could rebase on top of it if you want to move module_enforce_rwx_sections() under CONFIG_STRICT_MODULE_RWX. Then you'll only need to provide one empty stub for !CONFIG_STRICT_MODULE_RWX. Thanks, Jessica