Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4396419pxa; Mon, 10 Aug 2020 08:10:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTTJlHaI2BjCcdPZ/jn9S3TokD35qZqgEEb5z8FZ1Vjn6ujPppvfaDXBIIb/16B+yrYbe/ X-Received: by 2002:a50:f687:: with SMTP id d7mr19219269edn.306.1597072224597; Mon, 10 Aug 2020 08:10:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597072224; cv=none; d=google.com; s=arc-20160816; b=djxazFSuLZA+RhX8joiRJTPubQj6yVv7fgx9nhWGmjPQTAKTE2xov1Jn/NnSa2Ezq5 GPQ/r+Nu3Sqw67LTvbLe70GrL2H2JGhH2r21gO5PEI94w3W+PUsU3IEre9ksXFhQHoad 9HTQB1W7cay/YF02hVQecOWtf7dxlmkk3W2S7j6BPClFX8UDAxxCVSo0SguTu7bANe1I mYXjZQCqKKbQduF2YpEfBFlGzfrE/R/NmNmtbATpNS/wv2v0UD9W3C9YaXmKfiomi69h /rBY8crgn4J+iFUbRP2z5Me8R2Sct70OMXOc7PwexZoP3cnbSKW9pAC90SVTW2NMwNYp g2WA== 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=L1mOdJtE1tET60isINHHGIyVvtO+L24xf8XuxfCp4dI=; b=vlEdQ+FJYtvFwf7n94Pgu7L5LdIMYxnVmk+x7opKthh5H6y9cgVIm5y8r+Vs/DQ//u jhR+scvXWY2Sv5LH+YZjdY4LSZz6gFBBjyjY0vEOM03pDB7/DXBPwhyngiiU1Tucn7pG z1PflM8QAIMwkhYhdSUw06ml0e7m7G9nT7p+Udy5Ix+KDmraqpHDw55xTNf2lks74LR3 yAAhBIVz+5wdc9AU7iptqUC57ExebY21UANKDQcVT72BBPGzNKNzr/J0+8S74tdJt9n/ 0OnSJSdXfToA5tq+mfYQtjPR56tHbmUmeV5TGoStGVRJz4X+63dR6XGON+z8xJz6ZUDu u1iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="uIS/n6MV"; 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 e17si12599013edc.382.2020.08.10.08.10.01; Mon, 10 Aug 2020 08:10:24 -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="uIS/n6MV"; 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 S1726529AbgHJPG7 (ORCPT + 99 others); Mon, 10 Aug 2020 11:06:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:42464 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726115AbgHJPGz (ORCPT ); Mon, 10 Aug 2020 11:06:55 -0400 Received: from linux-8ccs (p57a236d4.dip0.t-ipconnect.de [87.162.54.212]) (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 6660C2076B; Mon, 10 Aug 2020 15:06:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597072014; bh=YZy2YZvqtBOSoxa9pOWWX5q5MbckXDWFu6szjgvgk3w=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=uIS/n6MVd8SISJgvsgLgWAvfmKAKezEXqiK+r8LrgVivrNOPINd1Y8ao1iQvUOoTH RP9JYTq2Hj/UGqhs8aU6RvcGYY/MOReCkHDUkhODIunkAmXY3oYvJz+OJ2yeQPA4Pf dUqPdupdOqsxHXEGuB/PiKSBgJ+zXvF6k9E4T+oY= Date: Mon, 10 Aug 2020 17:06:50 +0200 From: Jessica Yu To: Mauro Carvalho Chehab Cc: Peter Zijlstra , 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: <20200810150647.GB8612@linux-8ccs> References: <20200403171303.GK20760@hirez.programming.kicks-ass.net> <20200808101222.5103093e@coco.lan> <20200810092523.GA8612@linux-8ccs> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20200810092523.GA8612@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 +++ Jessica Yu [10/08/20 11:25 +0200]: >+++ Mauro Carvalho Chehab [08/08/20 10:12 +0200]: >[snip] >>Right now, what happens is: >> >> # modprobe wlcore >> modprobe: ERROR: could not insert 'wlcore': Exec format error >> >>This seems to be failing for all modules, as doesn't show anything >>probed. >> >>Btw, IMO, it would be useful to have some pr_debug() infra in order to >>explain why insmod is failing, or to have more error codes used there, >>as nothing was printed at dmesg. That makes harder to debug issues >>there. I ended losing a lot of time yesterday rebuilding the Kernel >>and checking the FS, before deciding to add some printks inside the >>Kernel ;-) >> >>In order for modprobe to start working again, I had to apply this >>dirty hack: >> >> >>diff --git a/kernel/module.c b/kernel/module.c >>index 910a57640818..10d590dc48ad 100644 >>--- a/kernel/module.c >>+++ b/kernel/module.c >>@@ -2051,11 +2051,12 @@ static int module_enforce_rwx_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs, >> const unsigned long shf_wx = SHF_WRITE|SHF_EXECINSTR; >> int i; >> >>+#if 0 >> for (i = 0; i < hdr->e_shnum; i++) { >> if ((sechdrs[i].sh_flags & shf_wx) == shf_wx) >> return -ENOEXEC; >> } >>- >>+#endif >> return 0; >>} >> [ I somehow munged the To: header in the last mail. Sorry about that, it's fixed now. ] >All this hunk does it reject loading modules that have any sections >that have both the writable and executable flags. You're saying it's >happening for all modules on your setup - I am curious as to which >sections have both these flags - what does readelf -S tell you? Hmm, I was not able to reproduce this with a cross-compiled kernel using the attached config (gcc 9.3.0 with vanilla v5.8 kernel). I am curious if the failing sections are also SHF_ALLOC - in that case, the code is doing what it is intended to do, which is rejecting loading any modules with writable and executable sections. If the problematic sections are *not* SHF_ALLOC, then we might be able to work around that by ignoring non-SHF_ALLOC sections as they are not copied to the final module location anyway. Jessica