Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp290744pxa; Wed, 12 Aug 2020 01:59:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHWMQd1FiD1Zl/H9HkVlauYg9zsM0WrIl9+YepnRyZ5KshGvJtPt4kn88bhF0vDvLmdT3c X-Received: by 2002:a17:906:ca4d:: with SMTP id jx13mr29624549ejb.548.1597222756009; Wed, 12 Aug 2020 01:59:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597222756; cv=none; d=google.com; s=arc-20160816; b=laFOn6krzSmKnp95LAQflYzGZ2OfqmWK+1fANJQIofxyCYt6iPMXc/wS6ixoU7wpcm VmYppnn7FoYRFBKWFRz8FpiS4Mrb158xX9AQg71HBehNZ3yx1PbjJBKu+u8rTIBOHcZI QBzF1HiXvET068baEedWzXHlrONHNDtxnrPwgUcgHRYWKPvtYE3pP1nQJqaHJLZbt+SB IUpxmmrY1/m+68tP1KATj+QytRTX7iu/aX/cUWB1vPkRz5FNHbXHEZfHRSg2bst7bytl z0WMP4vApoT35pA686SKRzFcZYIhq2yO5dMENy+C7XXbceMjZt+4164hxg6eDRWqUkhl tlsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=bl7N1LI1Nubz0UAPdU8XMb37w37wTMA1dS67zxjJs9s=; b=blslzpIxfIl1+kC827UEpOjN0zPJvJ5jh2q4Fm5SZ4UYsvUw1Ewu4toBNbelbl7De3 VKb3hWxyTc+VftZ3e+rrXb+lfiVY2BuFkHKbNgM3xju5kzynK7YvmDdm7WCFNbdTaV8N oSlqqepSOKoF3FCKqud6iH0K5j0CdexfEonzYVL1ct/KEWoQx3AwhQf7kpCZT0e0tE39 HzcBcAVEukKUwgIUeqWme+yL7AhIIHpDXxsTkmbVu14Z+Ppe4461H9yugv2I4IbebNsj D+KXpFx37pMk7ZjN7l0wHex9ESYA73QiGuDRVQ7zeeRQbknHTW2wdLcsXrjafoAsCGxZ ugaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Mq48PKcD; 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 fi14si744059ejb.628.2020.08.12.01.58.53; Wed, 12 Aug 2020 01:59:16 -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=Mq48PKcD; 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 S1727077AbgHLI5J (ORCPT + 99 others); Wed, 12 Aug 2020 04:57:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:44742 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726990AbgHLI5J (ORCPT ); Wed, 12 Aug 2020 04:57:09 -0400 Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6611A2083B for ; Wed, 12 Aug 2020 08:57:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597222628; bh=OpdSJrDe6VRA6KahHe+zVXP/Gug35Hv/eCOg8dbd9DY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Mq48PKcDAKPCs4uHN1OeOkS3bDpt771NTXFrCiRP7g1tQgfAQVG5PFzRN3n+6VQBj 52V+BNWhpbjp/CVcMwvCMFHhgDs9sLVoZyzgfJsO8aBnnaAHBx+YAhI7PQ3nMBysb3 6vutoL+B2atRXi/4iKBq6fUa2PLHAx6OnQeGiPQ0= Received: by mail-ot1-f45.google.com with SMTP id h22so1329546otq.11 for ; Wed, 12 Aug 2020 01:57:08 -0700 (PDT) X-Gm-Message-State: AOAM531gvggMuAb7PpkIn5oTpl5JvwR3FFFf37MHLrPafFdLhjQSQTM3 JmkAlJFW3Jp/KxxCL4R14Pxj233dk8tIBdYAzY0= X-Received: by 2002:a9d:6251:: with SMTP id i17mr8034568otk.90.1597222627672; Wed, 12 Aug 2020 01:57:07 -0700 (PDT) MIME-Version: 1.0 References: <20200403171303.GK20760@hirez.programming.kicks-ass.net> <20200808101222.5103093e@coco.lan> <20200810092523.GA8612@linux-8ccs> <20200810150647.GB8612@linux-8ccs> <20200811163427.6edbf343@coco.lan> <20200811145524.GE2674@hirez.programming.kicks-ass.net> <20200811172738.2d632a09@coco.lan> <20200811160134.GA13652@linux-8ccs> In-Reply-To: <20200811160134.GA13652@linux-8ccs> From: Ard Biesheuvel Date: Wed, 12 Aug 2020 10:56:56 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] module: Harden STRICT_MODULE_RWX To: Jessica Yu Cc: Mauro Carvalho Chehab , Peter Zijlstra , Linux Kernel Mailing List , Thomas Gleixner , Kees Cook , Josh Poimboeuf , Miroslav Benes , Mark Rutland Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 11 Aug 2020 at 18:01, Jessica Yu wrote: > > +++ Mauro Carvalho Chehab [11/08/20 17:27 +0200]: > >Em Tue, 11 Aug 2020 16:55:24 +0200 > >peterz@infradead.org escreveu: > > > >> On Tue, Aug 11, 2020 at 04:34:27PM +0200, Mauro Carvalho Chehab wrote: > >> > [33] .plt PROGBITS 0000000000000340 00035c80 > >> > 0000000000000001 0000000000000000 WAX 0 0 1 > >> > [34] .init.plt NOBITS 0000000000000341 00035c81 > >> > 0000000000000001 0000000000000000 WA 0 0 1 > >> > [35] .text.ftrace[...] PROGBITS 0000000000000342 00035c81 > >> > 0000000000000001 0000000000000000 WAX 0 0 1 > >> > >> .plt and .text.ftrace_tramplines are buggered. > >> > >> arch/arm64/kernel/module.lds even marks then as NOLOAD. > > > >Hmm... Shouldn't the code at module_enforce_rwx_sections() or at > >load_module() ignore such sections instead of just rejecting probing > >all modules? > > > >I mean, if the existing toolchain is not capable of excluding > >those sections, either the STRICT_MODULE_RWX hardening should be > >disabled, if a broken toolchain is detected or some runtime code > >should handle such sections on a different way. > > Hi Mauro, thanks for providing the readelf output. The sections marked 'WAX' > are indeed the reason why the module loader is rejecting them. > > Interesting, my cross-compiled modules do not have the executable flag - > > [38] .plt NOBITS 0000000000000340 00038fc0 > 0000000000000001 0000000000000000 WA 0 0 1 > [39] .init.plt NOBITS 0000000000000341 00038fc0 > 0000000000000001 0000000000000000 WA 0 0 1 > [40] .text.ftrace_tram NOBITS 0000000000000342 00038fc0 > 0000000000000001 0000000000000000 WA 0 0 1 > > ld version: > > GNU ld (GNU Binutils) 2.34 > Copyright (C) 2020 Free Software Foundation, Inc. > This program is free software; you may redistribute it under the terms of > the GNU General Public License version 3 or (at your option) a later version. > > And gcc: > > aarch64-linux-gcc (GCC) 9.3.0 > Copyright (C) 2019 Free Software Foundation, Inc. > This is free software; see the source for copying conditions. There is NO > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > > I'm a bit confused about what NOLOAD actually implies in this context. From the > ld documentation - "The `(NOLOAD)' directive will mark a section to not be > loaded at run time." But these sections are marked SHF_ALLOC and are referenced > to in the module plt code. Or does it just tell the linker to not initialize it? > > Adding Ard to CC, I'm sure he'd know more about the section flag specifics. > The module .lds has BYTE(0) in the section contents to prevent the linker from pruning them entirely. The (NOLOAD) is there to ensure that this byte does not end up in the .ko, which is more a matter of principle than anything else, so we can happily drop that if it helps. However, this should only affect the PROGBITS vs NOBITS designation, and so I am not sure whether it makes a difference. Depending on where the w^x check occurs, we might simply override the permissions of these sections, and strip the writable permission if it is set in the PLT handling init code, which manipulates the metadata of all these 3 sections before the module space is vmalloc'ed.