Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3799033ybb; Mon, 23 Mar 2020 07:56:45 -0700 (PDT) X-Google-Smtp-Source: ADFU+vveWbrynUTaoz/SfILAwo6GaMiytuTXwuF0Us/vVp+QpbjEj8/oNuzEa2ROsWXe88bveRYq X-Received: by 2002:a05:6830:6:: with SMTP id c6mr17566200otp.84.1584975405399; Mon, 23 Mar 2020 07:56:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584975405; cv=none; d=google.com; s=arc-20160816; b=xAQkzXcg46qxAZFD331Ogxt7Nv9Hasxhjy8gorVS0CLEHTulF6/V75fSefrKX+UCbo GkmpkS/o9Fso7n5Eni5m4lk8c+wWzipNhlH4Bi7GW3xTFAEKddEUEO/8GYB+pjL4AKMM 0pCip/S6WrbM4f8bO66TI5aAwdE0H7chGS9JWu9iurGJVSrABRz6HEtLLs+cOorR6Odk x1TeUqrN7gzRdj1HoMjUJXJzJhE8COLj4G+AZ4HSDlmoGErmKaHS66FNvGjsfp/bdt8K bDSLDLpuss+WLk7eMa03TkI3EdewpFEKvcmc04Z4S64k7EKM9v0mg1f+OuZRScJFd1AW o37w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=Tv4vr+D8Eei212lagjHXDCUfS1ZWP1dYTkq1XaYyMr0=; b=cOxxKeuJxn40QuzEBFTKnJVnbx2kcgL7CFns/BsMjugc1hBDLMFXPieEwQEo1Omj8o H8JT+hx2tkEIQ+ChOs3o1FqM3Wd+rHltW82r04U2vv/wiqqXhX3sf0RHWCWMMvEDul6M m5jRhvCv3RWCucpRt7XcbpJvIdG0gjLRuGvhekbkwdi7oOdeOwCyNTEAvZZe9cycSpQS kRdRePJ51RlPVde2rNo5xaOrrgaSYtXcHLXQMhkd73JcKI3V2RJ+5LUZpXWtfizahuX8 9mKabsEbrjBh6F/YMiiRs5fkygx9hUDP02kEn3B69PqDHtxwxnCCi9YRM13S6PEpcmbm lDQA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i15si7712564ots.121.2020.03.23.07.56.32; Mon, 23 Mar 2020 07:56:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727159AbgCWOzz (ORCPT + 99 others); Mon, 23 Mar 2020 10:55:55 -0400 Received: from foss.arm.com ([217.140.110.172]:50640 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727149AbgCWOzy (ORCPT ); Mon, 23 Mar 2020 10:55:54 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2F4851FB; Mon, 23 Mar 2020 07:55:54 -0700 (PDT) Received: from C02TD0UTHF1T.local (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 51F243F7C3; Mon, 23 Mar 2020 07:55:49 -0700 (PDT) Date: Mon, 23 Mar 2020 14:55:46 +0000 From: Mark Rutland To: Catalin Marinas Cc: Mark Brown , Szabolcs Nagy , Will Deacon , Alexander Viro , Paul Elliott , Peter Zijlstra , Yu-cheng Yu , Amit Kachhap , Vincenzo Frascino , Marc Zyngier , Eugene Syromiatnikov , "H . J . Lu " , Andrew Jones , Kees Cook , Arnd Bergmann , Jann Horn , Richard Henderson , Kristina =?utf-8?Q?Mart=C5=A1enko?= , Thomas Gleixner , Florian Weimer , Sudakshina Das , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, nd@arm.com Subject: Re: [PATCH v10 00/13] arm64: Branch Target Identification support Message-ID: <20200323145546.GB3959@C02TD0UTHF1T.local> References: <20200316165055.31179-1-broonie@kernel.org> <20200320173945.GC27072@arm.com> <20200323122143.GB4892@mbp> <20200323132412.GD4948@sirena.org.uk> <20200323135722.GA3959@C02TD0UTHF1T.local> <20200323143954.GC4892@mbp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200323143954.GC4892@mbp> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 23, 2020 at 02:39:55PM +0000, Catalin Marinas wrote: > On Mon, Mar 23, 2020 at 01:57:22PM +0000, Mark Rutland wrote: > > On Mon, Mar 23, 2020 at 01:24:12PM +0000, Mark Brown wrote: > > > On Mon, Mar 23, 2020 at 12:21:44PM +0000, Catalin Marinas wrote: > > > > On Fri, Mar 20, 2020 at 05:39:46PM +0000, Szabolcs Nagy wrote: > > > > > > > +int arch_elf_adjust_prot(int prot, const struct arch_elf_state *state, > > > > + bool has_interp, bool is_interp) > > > > +{ > > > > + if (is_interp != has_interp) > > > > + return prot; > > > > + > > > > + if (!(state->flags & ARM64_ELF_BTI)) > > > > + return prot; > > > > + > > > > + if (prot & PROT_EXEC) > > > > + prot |= PROT_BTI; > > > > + > > > > + return prot; > > > > +} > > > > > > > At a quick look, for dynamic binaries we have has_interp == true and > > > > is_interp == false. I don't know why but, either way, the above code > > > > needs a comment with some justification. > > > > > > I don't really know for certain either, I inherited this code as is with > > > the understanding that this was all agreed with the toolchain and libc > > > people - the actual discussion that lead to the decisions being made > > > happened before I was involved. My understanding is that the idea was > > > that the dynamic linker would be responsible for mapping everything in > > > dynamic applications other than itself but other than consistency I > > > don't know why. I guess it defers more decision making to userspace but > > > I'm having a hard time thinking of sensible cases where one might wish > > > to make a decision other than enabling PROT_BTI. > > > > My understanding was this had been agreed with the toolchain folk a > > while back -- anything static loaded by the kernel (i.e. a static > > executable or the dynamic linker) would get GP set. In other cases the > > linker will mess with the permissions on the pages anyhow, and needs to > > be aware of BTI in order to do the right thing, so it was better to > > leave it to userspace consistently (e.g. as that had the least risk of > > subtle changes in behaviour leading to ABI difficulties). > > So this means that the interpreter will have to mprotect(PROT_BTI) the > text section of the primary executable. Yes, but after fixing up any relocations in that section it's going to have to call mprotect() on it anyhow (e.g. in order to make it read-only), and in doing so would throw away BTI unless it was BTI aware. > > I think it would be best to document the current behaviour, as it's a > > simple ABI that we can guarantee, and the dynamic linker will have to be > > aware of BTI in order to do the right thing anyhow. > > That's a valid point. If we have an old dynamic linker and the kernel > enabled BTI automatically for the main executable, could things go wrong > (e.g. does the PLT need to be BTI-aware)? I believe that a PLT in an unguarded page needs no special treatment. A PLT within a guarded page needs to be built specially for BTI. Thanks, Mark.