Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3659193ybb; Mon, 23 Mar 2020 05:22:45 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvnaBSYzqJTJsrJzs4xPuRLS2eZ7UiKgSVR5v9Ynkkmk22mBq3QDZnfCF21VpBYJFN5Qyn2 X-Received: by 2002:a4a:674f:: with SMTP id j15mr282226oof.41.1584966164995; Mon, 23 Mar 2020 05:22:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584966164; cv=none; d=google.com; s=arc-20160816; b=CCX6F9u72gX5yNyiJ3Ye+1XYoC3ohKB0pA+X21/mounFKUuUZkjXOmEX8CflOiDsb1 J24FJx1Ml+rI0Ng00wEcIki9fFVgpzZ3fyQiAiBoRKHla8USnjdwDxbz+yoL5Z8Yp/kH rClIhLka5pTXTLI7l4S4L9t1qco+dkCWiEFGK3Y6C7jHSer/cyJIVRmwq0uiN3Mrf8L2 42CrTbGFSkPB8fQ7QwW+aAZ+L+rOFh+htct/tLGcTiZVofibxpDrAdOy/KVyl68kBb1o J1vha5l64zoMVtwW9aa+zCweQ9qPK2674EdtZlwN2y/5uNBoF8ERD+FeCOiMSw9bFUA2 ftpw== 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; bh=l0lkXQhwjpyPMiQIrzfn86chlilZd304Kl2NDMUhH5g=; b=s1nMZWXbMAqCCcW580Y3Xmwqp5107m/vXiWGzB5TD27xplwLFRBBHpQf+JaPXI5lBl us3+WZnhEqX7B3HxQpmcDW9uFdCM0/cgGxglrPQlFBTjK/vITAMb5Lh7oSflTPsTtWPM pgj6JecvdFTcIVBcOnWJtqBKCPWow0d+HOB+mQeSIXBMO+R7xwHBEIp9+hRa4sxluEDD K88W8eEY4fVDoU1Kap8zMuqMQzgjOKX8ohPH75/q1OVj0ZfzRx1cI0f4Yr7ggTMkmO6r KGudOgJUnPNJKKEnpUrCI/iawN/ouuG/n73nBa2uEA71wBsD4kLk16A/G40BZ3j6zxPC mjpA== 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 h81si7398496oif.20.2020.03.23.05.22.21; Mon, 23 Mar 2020 05:22:44 -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 S1728132AbgCWMVu (ORCPT + 99 others); Mon, 23 Mar 2020 08:21:50 -0400 Received: from foss.arm.com ([217.140.110.172]:48184 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727531AbgCWMVu (ORCPT ); Mon, 23 Mar 2020 08:21:50 -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 C1DCC1FB; Mon, 23 Mar 2020 05:21:49 -0700 (PDT) Received: from mbp (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7AFEC3F52E; Mon, 23 Mar 2020 05:21:46 -0700 (PDT) Date: Mon, 23 Mar 2020 12:21:44 +0000 From: Catalin Marinas To: Szabolcs Nagy Cc: Mark Brown , 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: <20200323122143.GB4892@mbp> References: <20200316165055.31179-1-broonie@kernel.org> <20200320173945.GC27072@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200320173945.GC27072@arm.com> 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, Mar 20, 2020 at 05:39:46PM +0000, Szabolcs Nagy wrote: > The 03/16/2020 16:50, Mark Brown wrote: > > This patch series implements support for ARMv8.5-A Branch Target > > Identification (BTI), which is a control flow integrity protection > > feature introduced as part of the ARMv8.5-A extensions. > > i was playing with this and it seems the kernel does not add > PROT_BTI to non-static executables (i.e. there is an interpreter). > > i thought any elf that the kernel maps would get PROT_BTI from the > kernel. (i want to remove the mprotect in glibc when not necessary) I haven't followed the early discussions but I think this makes sense. > i tested by linking a hello world exe with -Wl,-z,force-bti (and > verified that the property note is there) and expected it to crash > (with SIGILL) when the dynamic linker jumps to _start in the exe, > but it executed without errors (if i do the mprotect in glibc then > i get SIGILL as expected). > > is this deliberate? does the kernel map static exe and dynamic > linked exe differently? I think the logic is in patch 5: +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. -- Catalin