From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 237E52E3B15 for ; Mon, 11 May 2026 20:18:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778530685; cv=none; b=OQKFP2IH37WTNuCbm6hZuHFi0Gq21mSGONT4Sk3VBSOzx1h+60jZ+QOZnd+zjA/b/87a9E/20Lce3gtlSYme+CKgVIorosqu/wFSxICQm26DXT+bzQsxZoae63h7hOGkBpQ5yORQepvPDnl6+HUDTaRoAoLekjnz0ZZ+Fq7vIAk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778530685; c=relaxed/simple; bh=oD450INjmtitseYpMMPgkOQ6Srvcv+1mddEf1SkONZg=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=o3mVUyOK6HkY7VpK1J39v3HsEZyRqeyiEy4CMgb9/Omtrn4Su1/h1OI0TVQ/d/57RfsVrZPhtrMzrx2KOgxYnDGUAcpBd7LS39BX941Ql/C8Tdhcin5sVFog8/C4mU1T7Jsja9aTtO7oQRMgwXBdWDVQ7OPVM6o3BgT9BNlM6OA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--elver.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=dD+gyUJi; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--elver.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dD+gyUJi" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-486fa07f2bbso28860865e9.2 for ; Mon, 11 May 2026 13:18:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778530680; x=1779135480; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=j2a0GzlUre0cQo5MmedKBieEh3coSeRT2BQuTVbwA6E=; b=dD+gyUJiY9hpORtKhgHyIgs5cMrryIYcZ9L+LvLKvqRnGsLOuV/O/Y+jP0V74RNC/M T4DKlRUo6vrtFREyjyG12SHYNGHO/SFStGkl3n3v5Dm95nWA+++qdIFuZGDYnLNafkLZ YpPat7v4PDLr5JKFLTKOSVntZ8nW9G0F7vTlxjjdPKVkvmcxdD2xQuVMUusUsvk0bL5b gIYBnx2H8Eeuu3daULKezQPNn6OZ/vpNYzAwtx21dp2EscAEAGVdSxgFYt+UDEEeMQM+ w7qUtgZDF8SlpmFGi28wdysrBnBglQJASUoE3IXOXRCYC0HSFYbtO7W+E8s54YieZ/Gb WyRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778530680; x=1779135480; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=j2a0GzlUre0cQo5MmedKBieEh3coSeRT2BQuTVbwA6E=; b=JT6+YY9II5lG2GMRKuoJyExH/VJTuL7Wu/0OJQWG7ZeGN0pFVPF8I4AbTE999qP5AJ SoeSQJQ43+lWwTBK9/G4Lx5F/ogv0eAYWeqpm3wXo4pfASc237D0aO+E1rclgTGhCPZa 8FT671eM2b8vy6D8JTZGVCU6wM3xTx1QNHra2aifItDlS90lipuBroQ+F3FWIeJdwGT7 T4fAPVtDpIq4L77m1gThtSinIG27IFOjhP0zoXT+wAmxdmMz+hQp8q8P0w+2wcUINzMK 7Qy6L3vhtX579Ng9hg12pXFnBVE4kh/N75MY1TNPoYm9E35+Qwzl9Dm2sT1DUgPN4Zq3 OElw== X-Forwarded-Encrypted: i=1; AFNElJ8HzyITTiWZ50Z9bvZwSLEuCdtSDTSRczVE9S2qHrOj/cdWSBHx528CWgXXTggrtEQHwbe/GMd9hOTMDV0=@vger.kernel.org X-Gm-Message-State: AOJu0Yxvb0oQFcgGgAdvxKt7UOJZ1SFeKi2yX3ZWaLry3aGH19lAQ2mq UedMINp5pFnnSgYdlT7zvLgAD5mTpcfCKnTsklGwJgenKLt8eARuaiVOx3NusEIJR04OrUXe3hk I8A== X-Received: from wmco8.prod.google.com ([2002:a05:600c:a308:b0:485:4f4a:bd84]) (user=elver job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1d19:b0:48e:5990:9698 with SMTP id 5b1f17b1804b1-48e8fe84846mr707415e9.24.1778530680153; Mon, 11 May 2026 13:18:00 -0700 (PDT) Date: Mon, 11 May 2026 22:16:59 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.54.0.563.g4f69b47b94-goog Message-ID: <20260511201711.3249121-2-elver@google.com> Subject: [PATCH] arm64: Implement _THIS_IP_ using inline asm From: Marco Elver To: elver@google.com, Catalin Marinas , Will Deacon Cc: Thomas Huth , Nathan Chancellor , Kees Cook , Vlastimil Babka , Harry Yoo , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com Content-Type: text/plain; charset="UTF-8" Both GCC [1] and Clang [2] consider the generic version of _THIS_IP_ to be broken: #define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; }) In particular, the address of a label is only expected to be used with a computed goto. While the generic version more or less works today, it is known to be brittle and may break with current and future optimizations. For example, Clang -O2 always returns 1 when this function is inlined: static inline unsigned long get_ip(void) { return ({ __label__ __here; __here: (unsigned long)&&__here; }); } Fix it by overriding _THIS_IP_ in (which is included by ) using an architecture-specific inline asm version. Additionally, avoiding taking the address of a label prevents compilers from emitting spurious indirect branch targets (e.g. ENDBR or BTI) under control-flow integrity schemes. Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120071 [1] Link: https://github.com/llvm/llvm-project/issues/138272 [2] Signed-off-by: Marco Elver --- arch/arm64/include/asm/linkage.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/include/asm/linkage.h b/arch/arm64/include/asm/linkage.h index 40bd17add539..73eabc82a6bb 100644 --- a/arch/arm64/include/asm/linkage.h +++ b/arch/arm64/include/asm/linkage.h @@ -43,4 +43,6 @@ SYM_TYPED_START(name, SYM_L_GLOBAL, SYM_A_ALIGN) \ bti c ; +#define _THIS_IP_ ({ unsigned long __ip; asm volatile("adr %0, ." : "=r" (__ip)); __ip; }) + #endif -- 2.54.0.563.g4f69b47b94-goog