Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp215180pxa; Fri, 21 Aug 2020 05:34:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwui947XNK0FM7nqhKr/muSJ0ZB0zpaw0aAHMwdMONVzbt74Dkg89Hq0r17L7YDBBAnA53K X-Received: by 2002:a17:906:dbd8:: with SMTP id yc24mr2632459ejb.176.1598013250680; Fri, 21 Aug 2020 05:34:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598013250; cv=none; d=google.com; s=arc-20160816; b=w33Bt376deaEVYJHBjLN3kHLVXIfoP+etkEJrhP73p/vQqXrA8r/OYKoiWyX7YRRCm nxoCkda0UcQFghCwaDQB4HSLJw9/NgVW8JpEvvqaCPwtXzlqN4jmAKmovk7pO/9OTCnt BVXHAVGdqlJdGrNG3P8wM1C49r//BrZSUESzYweaxbg4SKx9Ew1gTZFL/mCer1ufPJud Rk6cuJ+xm9L3i8OUc9i1aOLnV/7qevrLm/siHKgYaly7QGSsyYcZZVwGpFYUVu195yEJ O/TmZmuR0FCE6nzYYKLPkz94jsbR6Exdnt2yFmLYIl9aySdS5+b4XTksyCbMj5s8/fC5 ab0g== 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=wYma0xrPKh1XFVMvGJDx3k21927ixwQzny5HM7SGo/o=; b=g3dcma3oy7GWEB2IiAVazlID/JrOoQ3ue88CfQr+Uobfvnfsuy/d/vFFhVk3linUve yz6rd5ovUbgkrH9/EmJbX5BlY+LKGAAiECRTu2Ao6pUYeswkqWwDbxn+n758UIJGASNJ 9uNobv7BNj2KiStpGPFSaoPO37bl4RhgVM7u0+EqBfkg4RJSZyvP25TP1ujh0q1x97lK EH9KMxl7Q1leW+sCqMwKDw/HLM7HrX1sutZg2wa7lPcvzidWu38eVn1s9o5VcAR5qyEV tTfgrHtUDSb0YwVJRynU/EWBIPDeyF8xWzW7yAjLzFDriBdg/K79u+zhk3rR1u3qv5Bb CKsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KyEJWEd0; 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 c21si1132694edv.187.2020.08.21.05.33.46; Fri, 21 Aug 2020 05:34:10 -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=KyEJWEd0; 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 S1725935AbgHUMaw (ORCPT + 99 others); Fri, 21 Aug 2020 08:30:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:38988 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727104AbgHUMam (ORCPT ); Fri, 21 Aug 2020 08:30:42 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (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 2FA3520724; Fri, 21 Aug 2020 12:30:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598013042; bh=EYzeQyKbsyoYnxtSyFAJUuKt7H7T5SLVEFASRIYw5eE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KyEJWEd0IHbfvhGb9bY0cgzrF9WvhjDFh5PYOofSP0BNqyXAeJm2aaku8FWEOnI1J PNeuXObtjumPpe1J5yGBwsNWhe5NVcIEA+MNq8FJAXrXw0AUKydoEN9JJ3soORcGfk Mz7pS57vRO2MrQrzgcSX/V7nGBM7Yga3vpvXdvZY= Date: Fri, 21 Aug 2020 13:30:37 +0100 From: Will Deacon To: Ard Biesheuvel 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 Subject: Re: [PATCH v2] module: Harden STRICT_MODULE_RWX Message-ID: <20200821123036.GA21158@willie-the-truck> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 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. Will