From nobody Sun May 24 20:33:33 2026 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 046FE3C553B for ; Thu, 21 May 2026 12:29:37 +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=1779366579; cv=none; b=ckSWGLdWZpN1kDBddDRZDIEYL6EbX5VB63SrnRCUKdegBbrtLE3Y9z39t4uC3E9CIiNlRpRXXCPmlZkfk3sODZyAVZ8mKL5o24o256u1+LdRvElQ1wElRYxyBBKnJNSZEARwPqc0eSfpN/z0PcwvebuAadjO3Do74QSs9ieDU8I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779366579; c=relaxed/simple; bh=vmWopgj7bL5+85LywT7L5N8brTKCSO0wPs2otELly70=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=Dc8FH+viHLX8+7WBVDdvXHAMT2W5DNjxWYVQA/js1LVj7WVQXoW+z0cw2QIi8f8/jA7Vh4yltmuARIg+wDFTqy5bxu/fiTlGn7Vvx3qttbDDRaYtEc5bZaEUIEHuyFHtFX4RZFKfNXzLVRNS7Ik663oe8e5j4aIyaIMQU+aW0Z4= 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=I/pjHFn1; 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="I/pjHFn1" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-48fdacff6d2so45303915e9.2 for ; Thu, 21 May 2026 05:29:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779366576; x=1779971376; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=n0j1uWN8BZS95igofi0P3e6YMyYCAFIv8OXyIcUdmd8=; b=I/pjHFn1udQopljv9VNogpm911gx+ZTMxyMU0KmECdiFonpcpMX+eLttNcRH0Isv72 Jlpd3PrpW1ZAyualMbFVxwbFMr1esq+XWSeAwvKFFXlblnUjaEOq9c5tzLydHh7/cXju 2AHSnKCcggt26Mbka1LqYC0xYXxNew/VC3T9sMRjTUNareaynondRhLZDUtj1KPST2+i D6+C9nfjd/twnf5wUUFva9EghSYvVBDHKLDwaXI196ldn3+KBzPYLC/abt4+BboOJIJ5 W9jEBjLzjdbyjvgrMG+F6i9G+qV2Ke/fwV9ebao2lst5hDZ90Z5O6fcc+OYq+3ukR2Sl ExvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779366576; x=1779971376; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=n0j1uWN8BZS95igofi0P3e6YMyYCAFIv8OXyIcUdmd8=; b=qV4WvUM9rd2l5mxwPdxW4AMESs5WVKIV0LOSQIlJtlJ+xJzbKuwI8z1VsNn3WExxSQ /M1LUFeLkfl4OmxSNOO8CqjRAYp7jHLVgcfK1cYaI/r7egWXeAY6wAJcJOZbAtJu7q46 mhVpPnRUYn2gZnpHAdHy4AdU+Q3haIyaVpoTmol5En+5M1BT88NQ1rDMjYgEMP6DXitr 2FUyaZ1uY9qSNeEG+9qDnnehwEPp7IfTbLbT8rhJX52zXhm82fygftYsUvR0hKd87hu0 7vJrSynNh3mKOaYF530t4Pkub3I8LN6pZ/0opdY8IBQ9BDIRWHSWYMv65P+cvs6O9zF0 ZN/g== X-Forwarded-Encrypted: i=1; AFNElJ9pgaP3ouFjl+pzDuIdDkNFCjoP+WpfHHplChw9ErZ77FSj47REjOd4XVkT+HSvi8oBGqCk/58yWg6YvYA=@vger.kernel.org X-Gm-Message-State: AOJu0YxvAql4hFjD2fmLttK4iY5B66GURT9kITj4++Q54A10gnUyavze Dcs6nr1uQXu0HOpmyNS4QBQgqCppHaevi8YwCfrUKsL9m7wZzVd3zePLY9Awz+rGJBFvfnMU+Yf zYw== X-Received: from wmbjd23.prod.google.com ([2002:a05:600c:68d7:b0:48a:6a1b:6c3b]) (user=elver job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:8591:b0:48e:706b:53e3 with SMTP id 5b1f17b1804b1-49036048603mr28389255e9.1.1779366576213; Thu, 21 May 2026 05:29:36 -0700 (PDT) Date: Thu, 21 May 2026 14:29:16 +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.746.g67dd491aae-goog Message-ID: <20260521122918.144163-2-elver@google.com> Subject: [PATCH] arm: Implement _THIS_IP_ using inline asm From: Marco Elver To: elver@google.com, Russell King Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com Content-Transfer-Encoding: quoted-printable 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=3D120071 [1] Link: https://github.com/llvm/llvm-project/issues/138272 [2] Signed-off-by: Marco Elver --- arch/arm/include/asm/linkage.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm/include/asm/linkage.h b/arch/arm/include/asm/linkage.h index c4670694ada7..416e6a242dc4 100644 --- a/arch/arm/include/asm/linkage.h +++ b/arch/arm/include/asm/linkage.h @@ -9,4 +9,6 @@ .type name, %function; \ END(name) =20 +#define _THIS_IP_ ({ unsigned long __ip; asm volatile("1: adr %0, 1b" : "= =3Dr" (__ip)); __ip; }) + #endif --=20 2.54.0.746.g67dd491aae-goog