Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp212785pxa; Fri, 21 Aug 2020 05:30:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkgBHGHzc/vcyRc6uufVU3hSZdEEYAGMGEHnexkU62aeVsq4XHwd350L3/Dh54ZrulHRsE X-Received: by 2002:aa7:c5c3:: with SMTP id h3mr2687514eds.246.1598013025713; Fri, 21 Aug 2020 05:30:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598013025; cv=none; d=google.com; s=arc-20160816; b=ujg0q/Zia3jngbj1rsJu+IHafxZG0vl9O4G+vbSy3qy4q2dR6uMughpfbmJ4CfoAQ3 246VHUUhbLBt5My0FoCg3HdI5hKIInet61hDBI6eUznf3OBtF59Vbb5GsgDUkYtlzC2A MCzolhOZBQ7QkvDOFBW6v6D6gbEtfZKldxwpyC/CVQkDf1inFDLZKxlrcYAAUAuwUKs+ 1tZxFqeR0FrxQJ4O7PY9dXKe/k2oVFIplxsAqkZW83n6BFsB8ZB1CcdndAA4BtPxKt+i bqAliHPNffmyMsgpR2MF10Nr2L3Y8GgOErWBSb4LjBZd1WAQWbfy+7btgp1b1Zlof2dc bpUw== 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=OaId4M/yCtOLGY7oo9EMubEd9xZMUseU9KPmEQ0g8Ic=; b=pVil8lvxczw9WGVKiIybfvNAOPEgDdMATB/mFBGk2Wj/IQJxY2hUldQj5GqkZsh0RU vGa1jdjFyRTuGXeHtFgN+dTvseWR0gj94P9sBwDyWNFKRMg15UBe1pn4hKraUgZL81Gg cke6ey9f2G/KLyoShoefUMkZOXubCGbXTf539kcejt3pY5csLxXuUO7dYNXKd60qAvSl gYMSvkXnlJxGZWL4v5RwzvW2iagMpJr4OQxFenIOs5ve6RBLHvk+waaP4azHhbZq1dwn 2DsAszO7pJ/6JWFfoolhDvdCOlCtSsywnZuPctxsMmKY+Oy4UIQnOdMkRx6MeYyEoeMy FPhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cXIZAyZJ; 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 u17si1029142ejt.560.2020.08.21.05.30.01; Fri, 21 Aug 2020 05:30:25 -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=cXIZAyZJ; 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 S1728253AbgHUM1V (ORCPT + 99 others); Fri, 21 Aug 2020 08:27:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:34590 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725935AbgHUM1T (ORCPT ); Fri, 21 Aug 2020 08:27:19 -0400 Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) (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 645CF207DF for ; Fri, 21 Aug 2020 12:27:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598012838; bh=zry6Or1kr2aFqLBbV3onaCN8a/kdLAuY9x+g5pVkg1Y=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=cXIZAyZJKu08fvDG/T0UYw+UZV4KkVgsa5bMEkogyPKKdCLFOWNyOpOvx720EbR/c RMu4BXg+rq8ZrUe/NzgVucM9ycSE/L8k/G11dh3JoqHCR0ybGUI3eXxvQi6GhOVyKY fdLTPVKgCW0f5zzdjqJlrhJqO90ompXZT+hzagaU= Received: by mail-oi1-f181.google.com with SMTP id u63so1351194oie.5 for ; Fri, 21 Aug 2020 05:27:18 -0700 (PDT) X-Gm-Message-State: AOAM5312GMinovy6P+g3HtOImLqOuP+nyUEypI8cGIYhF/WBpK7kPjHm brulodkZysdSxjE2KWN6bq9uKBsMCtCUmCKn45k= X-Received: by 2002:a05:6808:b37:: with SMTP id t23mr1640590oij.174.1598012837736; Fri, 21 Aug 2020 05:27:17 -0700 (PDT) MIME-Version: 1.0 References: <20200812104005.GN2674@hirez.programming.kicks-ass.net> <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> In-Reply-To: <20200821121959.GC20833@willie-the-truck> From: Ard Biesheuvel Date: Fri, 21 Aug 2020 14:27:05 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] module: Harden STRICT_MODULE_RWX To: Will Deacon 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 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.