Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp698913ybb; Fri, 3 Apr 2020 10:10:10 -0700 (PDT) X-Google-Smtp-Source: APiQypJgufqS6DWZOf/xE1IwMTvussWOZZQf9ppxBSiB+8x1s08yKWA/XUhxU0PlI0shdGAVAq7o X-Received: by 2002:aca:6042:: with SMTP id u63mr3961269oib.179.1585933810756; Fri, 03 Apr 2020 10:10:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585933810; cv=none; d=google.com; s=arc-20160816; b=AOM/aOoKBD4BgVoYRC0kI/1c2d7gk+5ggxoRkxmc6TyyXSKe/DA+h2AGkcDX6f3ril KKTpOfuxAAglyz5rTIWXtPdGNFK3BJ2o0abar3XpTSn/5H4gCOQcvTsfN/8Dyc8aZLwK hEkwSmYB2E1hP+qgyCt9P1YKvsZT8wwGR4lSewiDtwiD1Zjz2x+aZQZc8SVfyfWWdPkS HypgpvgVGMoL0RSQtW/YiV0TH/4A3lgB/6Mx8jDFQ8nWM0z/xVgYraFojxFcHWEns5V7 mRyOXwUB81+C4V/CVSelL0FupWV6zws8VrO9ZwKhHzEWP0OZa/MCU6BXGFUjdkfVRWlj oFfg== 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=hDLEXGgzViXf1DCMcUvy65LKYBSnQEyHhsdc8RLosOM=; b=LtjymMyrBokDWzewEYqB6HqV4k2uKtC67m/xNxsFXV8fM85fpPAxBGDH9q5OAnTcwd D2mXIEN6pWBbGGqHplQ3hazGDWAI2r86TO5+AZOmKU/3htiEnfzc78PjoG3ScR2rGAbj ap2QYEvyNKOqlsRS/x+x6iG7R4qyTRZgobk/hMUvOVukw1Sn4aZcpBORZRlFAIt9PUB7 ocmofSVeHrK0inIxm1JRQjYICYPNiUDQGR5TmVFxr1bsgGHvvYiNaAlhs25jdgWPJUUh Q8p/9NPjYsjrMOj1zOzCTfygNV64CjEfBzjMrlFj5ysNnxQz3/h8j4Fb42nyA5Rm0N1o cM8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=yW6Vofu5; 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 r6si3949712oti.159.2020.04.03.10.09.56; Fri, 03 Apr 2020 10:10:10 -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=merlin.20170209 header.b=yW6Vofu5; 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 S2390962AbgDCRI7 (ORCPT + 99 others); Fri, 3 Apr 2020 13:08:59 -0400 Received: from merlin.infradead.org ([205.233.59.134]:49680 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728363AbgDCRI6 (ORCPT ); Fri, 3 Apr 2020 13:08:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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=hDLEXGgzViXf1DCMcUvy65LKYBSnQEyHhsdc8RLosOM=; b=yW6Vofu5kRfWmF438nd/cZzufr xy6DkKg78VB3MynYBQr5D35pzeoH6K0APvY3Sb7cmS5iJ7M8uTo0XNxwozEB5bKaNY0ROw7E3S/E5 9G696kzpf9TeGkf/LRpO6epo/Gh5s3ZIUiQw7FgW2cv0p+S0f5Ue8DgLzVzKqVBDMIO0oHXIF9T8u N+7QgFTvdY0bIQh8eOyA2dPCDbBVFaAOmm8ctGzCUIhpdZ7WyWQatHJAYhxqbun9jzlEkxh5YQkdw ht0/Lam0bNfY+aPgMAWWB5GFflqXPtWkwOIzipGajGdL3ZR8Ur2p9rYuJpw90zBYh9FDpzuiVvhBU 3wFXBUKg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jKPoK-0003kI-BL; Fri, 03 Apr 2020 17:08:52 +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 B611B30477A; Fri, 3 Apr 2020 19:08:50 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id A78D22B124EC1; Fri, 3 Apr 2020 19:08:50 +0200 (CEST) Date: Fri, 3 Apr 2020 19:08:50 +0200 From: Peter Zijlstra To: Josh Poimboeuf Cc: jeyu@kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , keescook@chromium.org, Miroslav Benes Subject: Re: [PATCH] module: Harden STRICT_MODULE_RWX Message-ID: <20200403170850.GA20730@hirez.programming.kicks-ass.net> References: <20200403163716.GV20730@hirez.programming.kicks-ass.net> <20200403165631.hrxxm3pnzqa4vxln@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200403165631.hrxxm3pnzqa4vxln@treble> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 03, 2020 at 11:56:31AM -0500, Josh Poimboeuf wrote: > On Fri, Apr 03, 2020 at 06:37:16PM +0200, Peter Zijlstra wrote: > > > > 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) > > Cc: Jessica Yu > > Cc: Kees Cook > > --- > > kernel/module.c | 24 ++++++++++++++++++++++++ > > 1 file changed, 24 insertions(+) > > > > --- a/kernel/module.c > > +++ b/kernel/module.c > > @@ -2044,9 +2044,28 @@ 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_rwx_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs, > > + char *secstrings, struct module *mod) > > A verb would be nice: "module_enforce_rwx_sections"? > > Shouldn't this be under STRICT_MODULE_RWX instead of > ARCH_HAS_STRICT_MODULE_RWX? > > > +{ > > + int i; > > + > > + for (i = 0; i < hdr->e_shnum; i++) { > > + if (sechdrs[i].sh_flags & (SHF_EXECINSTR|SHF_WRITE)) > > + return -ENOEXEC; > > I think you only want the error when both are set? > > if (sechdrs[i].sh_flags & (SHF_EXECINSTR|SHF_WRITE) == (SHF_EXECINSTR|SHF_WRITE)) > Duh. yes. Let me respin.