Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp980714pxa; Sat, 22 Aug 2020 06:51:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6hQeFwdi3BIDrZFg/1dbHxBivI/n+mVhONvmF95zsg51jxw6TVX24BjRuAc3ZdtELuB2S X-Received: by 2002:a50:fd16:: with SMTP id i22mr7134804eds.281.1598104311412; Sat, 22 Aug 2020 06:51:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598104311; cv=none; d=google.com; s=arc-20160816; b=XZGspXAc9go0VhTza6Z1aLhB+3Nnbm3q1ndhXSIW+tFCuA8D6lCPDMQGewX3aw9yhr 8xPYWBgSb2+B2kal9ueXq3oa60qmAEuiDbtZ4kBerjWQK4QjPMCbYmnmM2B2zqImoVrv q2hrhPsJXBpm+FQaetgiFNNZ41/AzFSBBgtSpNOvyxMS/unxijrtDy56XM3RBHJGshse clF6qYdwN+ILHr+WKlAzWUUCe3FIHiQ38K+3Ul2FGfsGHB6SEB+24zdpWTIRbBDUa9kB F35n4OM3tRwLZkSxNE4FGI/f7tYM9d1B7RbUuXCCjX6IWl/73V1v/lqLe8cvczruXo1x XjUQ== 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=DBCPjyDgeHL0olOzG8nkNbVl9iTKqEK3PAcIjwKJz1A=; b=om3vd8wqXK2fv9ok6bEjbg/3KnycGgCDpKlEYwCIQoI6LwWI8JaIGlKgu8szsHYzpG 7wbDtKlORNCS3E33KJk6noBfxlDEceLpeHt3GJ0Z9VQIAg35rjNqhdyb4kWgfNmgcz42 bEtrkYlgciscTTdPjIVWadiivq5Q9SF2IPEOAayn1OMMBdKh6Q4VVAq3wK6cPIdq331g 9HEQzfAZ4Qm6yAEuQOxwW5rsPxJlMQWAUxJ+r2i65IZdFx9TKciM38DikNx1Vz+Iz5IM 7yOytSoQxUmfUDY419BvBAv08mQWnvKP1CJodPjcsgHsl13u9hQr9w4UUG86qQY7o2wj 4nKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=P09jrbym; 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 i21si3055918eje.143.2020.08.22.06.51.27; Sat, 22 Aug 2020 06:51:51 -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=P09jrbym; 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 S1728000AbgHVNrS (ORCPT + 99 others); Sat, 22 Aug 2020 09:47:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:60818 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727900AbgHVNrR (ORCPT ); Sat, 22 Aug 2020 09:47:17 -0400 Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) (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 82B2521741 for ; Sat, 22 Aug 2020 13:47:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598104036; bh=96L7B+okFVZq/04jywlusT8K3xmTarPedqhqNo5VI/M=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=P09jrbympqAEkN69SBz1EvE+01fNdlQ2Flk1caOFT34h84ugqwdODFoNS90KxoMlu x8dpAL7LSv20oH95Lc99/AjCv9rxPmzKLiZT9frKTjSruZ1KgC5QJGBXpe5gC2sXBZ uJdZVyODiznCS4YeXjmLG4kKQAivA+zqNhDJImaA= Received: by mail-ot1-f46.google.com with SMTP id h22so3743282otq.11 for ; Sat, 22 Aug 2020 06:47:16 -0700 (PDT) X-Gm-Message-State: AOAM5335UHZPKm1eE0ZV6T7FgRQp+mWJeJiJc5UdLKmSdWX5gtxNeIH7 juALpDEsf5Ne1nQ/MjJSbDlEEMJKn0jYy/Xon+o= X-Received: by 2002:a9d:6251:: with SMTP id i17mr5100058otk.90.1598104035809; Sat, 22 Aug 2020 06:47:15 -0700 (PDT) MIME-Version: 1.0 References: <20200812125645.GA8675@willie-the-truck> <20200812141557.GQ14398@arm.com> <20200812160017.GA30302@linux-8ccs> <20200812200019.GY3982@worktop.programming.kicks-ass.net> <20200813130422.GA16938@linux-8ccs> <20200821121959.GC20833@willie-the-truck> <20200821123036.GA21158@willie-the-truck> In-Reply-To: <20200821123036.GA21158@willie-the-truck> From: Ard Biesheuvel Date: Sat, 22 Aug 2020 15:47:04 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] module: Harden STRICT_MODULE_RWX To: Will Deacon , Masahiro Yamada Cc: Jessica Yu , Peter Zijlstra , Szabolcs Nagy , Mauro Carvalho Chehab , Linux Kernel Mailing List , Thomas Gleixner , Kees Cook , Josh Poimboeuf , Miroslav Benes , Mark Rutland , nd 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 (+ Masahiro) On Fri, 21 Aug 2020 at 14:30, Will Deacon wrote: > > On Fri, Aug 21, 2020 at 02:27:05PM +0200, Ard Biesheuvel wrote: > > On Fri, 21 Aug 2020 at 14:20, Will Deacon wrote: > > > > > > On Thu, Aug 13, 2020 at 03:07:13PM +0200, Ard Biesheuvel wrote: > > > > On Thu, 13 Aug 2020 at 15:04, Jessica Yu wrote: > > > > > > > > > > +++ Ard Biesheuvel [13/08/20 10:36 +0200]: > > > > > >On Wed, 12 Aug 2020 at 22:00, Peter Zijlstra wrote: > > > > > >> > > > > > >> On Wed, Aug 12, 2020 at 06:37:57PM +0200, Ard Biesheuvel wrote: > > > > > >> > I know there is little we can do at this point, apart from ignoring > > > > > >> > the permissions - perhaps we should just defer the w^x check until > > > > > >> > after calling module_frob_arch_sections()? > > > > > >> > > > > > >> My earlier suggestion was to ignore it for 0-sized sections. > > > > > > > > > > > >Only they are 1 byte sections in this case. > > > > > > > > > > > >We override the sh_type and sh_flags explicitly for these sections at > > > > > >module load time, so deferring the check seems like a reasonable > > > > > >alternative to me. > > > > > > > > > > So module_enforce_rwx_sections() is already called after > > > > > module_frob_arch_sections() - which really baffled me at first, since > > > > > sh_type and sh_flags should have been set already in > > > > > module_frob_arch_sections(). > > > > > > > > > > I added some debug prints to see which section the module code was > > > > > tripping on, and it was .text.ftrace_trampoline. See this snippet from > > > > > arm64's module_frob_arch_sections(): > > > > > > > > > > else if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE) && > > > > > !strcmp(secstrings + sechdrs[i].sh_name, > > > > > ".text.ftrace_trampoline")) > > > > > tramp = sechdrs + i; > > > > > > > > > > Since Mauro's config doesn't have CONFIG_DYNAMIC_FTRACE enabled, tramp > > > > > is never set here and the if (tramp) check at the end of the function > > > > > fails, so its section flags are never set, so they remain WAX and fail > > > > > the rwx check. > > > > > > > > Right. Our module.lds does not go through the preprocessor, so we > > > > cannot add the #ifdef check there currently. So we should either drop > > > > the IS_ENABLED() check here, or simply rename the section, dropping > > > > the .text prefix (which doesn't seem to have any significance outside > > > > this context) > > > > > > > > I'll leave it to Will to make the final call here. > > > > > > Why don't we just preprocess the linker script, like we do for the main > > > kernel? > > > > > > > That should work as well, I just haven't checked how straight-forward > > it is to change that. > > Ok, if it's _not_ straightforward, then let's just drop the IS_ENABLED() > altogether. > I played around with this for a while, but failed to get Kbuild to instantiate $(objtree)/arch/arm64/kernel/module.lds based on $(srctree)/arch/arm64/kernel/module.lds.S and the cpp_lds_S rule. Perhaps Masahiro has any suggestions here? Otherwise, let's just drop the IS_ENABLED() check for now.