Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp968624pxk; Mon, 31 Aug 2020 06:30:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8ZFkWYRNv3PD2WrheBKeBR5TaJoupDIHD3JL1A8tbacvDhEN2Fb48xKXlMWb4hYarPoUt X-Received: by 2002:a05:6402:212:: with SMTP id t18mr1347667edv.124.1598880613044; Mon, 31 Aug 2020 06:30:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598880613; cv=none; d=google.com; s=arc-20160816; b=ljHIwaGms/O+Ve9sU4gXR6O9J/620eB6F0UX165kMn3pFYeRh9qrtrjP8q1V8yoy2W 9czMF7J1/rjpblXU2l5iw7SqVCpTAEWHqH8nY05zDqO0MOLbpEnfLW9drtZwK+o4RA4w sArMhfjLjf1cTttm+BAOpeZWcSXPPXacdp7KStqMPms8sRMYX07oLLjFSPYKCq6gHQlP VUwTM4TW3ctN6/GkJbpaQK4mnSfnUBevZwMAPX4s2pwmEDF/IPYKV2Mfu3ro2Eyi4/9J BenXmkHxA0qn5bMzkQZNIy+PKfDJAOoo0xqiRDOus+cmUYZSSd8D/75K28VMXPxNFzyc qLGQ== 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=eVrwUtPr9CoJB1xx8UkIz4/vOTCibMQvu6D3qMD7luA=; b=ViGiBYbaxujrvsD2MGNu7Y1ZIWkbCWg85fD/5vxcGMn5KAVO5o3dB03w4vbHIrEznS QewAZvoCixjabL1McA8jBU2FqifjRJdUUHHEWtfClLtceHbWSSVCkyCEmhhImobkMKg6 LZZgIeGlHhJFcuWsS9U8SyTBPFQDylAavQQvuJemD1IvAgMOIxWz0rYODhEgrwWPvHKb RL99WSwtDGHg1Hyp+VTCbrRK7wo7tlc0+rbHZkOhwl0o8OMXSM7vFLSmQ4rWmZjGQgg+ N64lQnCvu0Bx48LMvnBuy9I3wzRzzPv9vkUNVXKvolUj5ZRDu7aL4sKsrdH+X9erEtsg EZSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ND1aWjbk; 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 qo10si2721966ejb.730.2020.08.31.06.29.49; Mon, 31 Aug 2020 06:30:13 -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=ND1aWjbk; 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 S1726515AbgHaNZ4 (ORCPT + 99 others); Mon, 31 Aug 2020 09:25:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:53708 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726121AbgHaNZy (ORCPT ); Mon, 31 Aug 2020 09:25:54 -0400 Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.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 2A8662145D for ; Mon, 31 Aug 2020 13:25:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598880354; bh=PKOmHk5fDC3lzYzZxF65l1OctcEHXfTawf5ki1aiohQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ND1aWjbk7tS8kvzgMcVKptOElGjl9Xq2uVFscNvTLU/TiCUrmpo3axXCXPQR5oATe lf14bjEQR0JEpiwYWyGDsJm6WpGws3YKuDlUKxt4UnW0rpLN6YFxdhLWqWjcJ4EOqY oWtHdwQ24CE95zPKOAYTuV3N+4c5h/FKs8rgTD0w= Received: by mail-oo1-f45.google.com with SMTP id m4so1447430oos.6 for ; Mon, 31 Aug 2020 06:25:54 -0700 (PDT) X-Gm-Message-State: AOAM533INoW9NLUY6sw5RgfhmExbUDZRdVGM8Culr6wuNYy5mpdURj0Q aF3ePKIOpuDIc1IZReIZME56Mk/hqrgeqssWY+s= X-Received: by 2002:a4a:c541:: with SMTP id j1mr771180ooq.13.1598880353308; Mon, 31 Aug 2020 06:25:53 -0700 (PDT) MIME-Version: 1.0 References: <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> <20200831094651.GA16385@linux-8ccs> In-Reply-To: From: Ard Biesheuvel Date: Mon, 31 Aug 2020 16:25:42 +0300 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] module: Harden STRICT_MODULE_RWX To: Masahiro Yamada Cc: Jessica Yu , Will Deacon , 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 On Mon, 31 Aug 2020 at 13:43, Masahiro Yamada wrote: > > On Mon, Aug 31, 2020 at 6:47 PM Jessica Yu wrote: > > > > +++ Will Deacon [21/08/20 13:30 +0100]: > > [snipped] > > >> > > > 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. > > > > Unfortunately I've been getting more reports about this issue, so let's just > > get the aforementioned workaround merged first. Does the following look OK? > > > > diff --git a/arch/arm64/kernel/module-plts.c b/arch/arm64/kernel/module-plts.c > > index 0ce3a28e3347..2e224435c024 100644 > > --- a/arch/arm64/kernel/module-plts.c > > +++ b/arch/arm64/kernel/module-plts.c > > @@ -305,8 +305,7 @@ int module_frob_arch_sections(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, > > mod->arch.core.plt_shndx = i; > > else if (!strcmp(secstrings + sechdrs[i].sh_name, ".init.plt")) > > mod->arch.init.plt_shndx = i; > > - else if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE) && > > - !strcmp(secstrings + sechdrs[i].sh_name, > > + else if (!strcmp(secstrings + sechdrs[i].sh_name, > > ".text.ftrace_trampoline")) > > tramp = sechdrs + i; > > else if (sechdrs[i].sh_type == SHT_SYMTAB) > > > > If so I'll turn it into a formal patch and we can get that merged in the next -rc. > > > > Thanks, > > > > Jessica > > > > Sorry for the delay. > > Please try the attached patch. > Thanks Masahiro, I'll leave it to the maintainers to make the final call, but this does look rather intrusive to me, especially for an -rc. Renaming scripts/module-common.lds to scripts/module.lds means that the distros may have to update their scripts to generate the linux-headers packages etc, so if we do this at all, we'd better do it between releases.