From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794881223; b=IDK4cgh3fvb0f6Z6pQDAOv/nsNjsVs/p0iSfF1ZSg4WENkILnsq5aZ093zA5H6qZ3AbQ 2e/adMVmxRx2JP23Sw/S4us8BI7zKIz/Ka+kyBqPL1m9MbM9O1Em6rN7d+q20ofPxeCDW JqV2wEB0qBoy4AmgClq8fkvmqABqsP36Cq4eD09x6SuVruYukFZhNLZrjKQVIaA2CQRAY toX6csKKfppky7L+VmxyMZhy98X15Z+2PhQALO39Zu2eKTYzL1rgNbOv8on1p80/vxrKO fOQ7EhCVKaQ8KS0Zcv1Zt9ncBhE8r7HelO4Lrjad0fbcelsouI2sP+82lEjF/SilW+Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794881223; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=F/Wol9k3USBeEqH+PNSDq/iNuPWkX6BY1YLwxrQ5T8w=; b=sMb43ZeEKrcTqpz82mUgNipoHOT/DRrgcwbSvw1qILxrNbhwIW/WSM4DMtiSfnchYE9/ rAWJCFWY6+ovq7qk8qlGWu0l1ZfSGZh7dImE/ZyjMNUMAoORh+OJ5WTY79Ske8LOis+GQ LFginFrDmgj8MV8jT8bTSNa823naY4Leu6ssI0NvKqxI8vQtCI0FqwEgeRT4GAAkrVlNp fZtAYMsUU7H3aKCXB8T+mJ0BUZ8MptPmoGM3pzMwlM0awCHX4yzw6h+gG4jaoghdom2bu MloMQT1QZdYzG6Iy302hox6JWh4ZKvSzZLLnv3mpLAKW/4f5lqA4zLA8TcqcZnEMeig== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--dylanbhatch.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=RzYFZGxP; arc=none smtp.remote-ip=209.85.216.70 Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA47A606A88C for ; Tue, 17 Nov 2026 02:07:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BA47A606A88C 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--dylanbhatch.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=RzYFZGxP Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-3b175a69ab8so2597341a91.1 for ; Mon, 16 Nov 2026 18:07:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1794881222; x=1795486022; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=F/Wol9k3USBeEqH+PNSDq/iNuPWkX6BY1YLwxrQ5T8w=; b=RzYFZGxPOzHz2EwMXmsaaN0w1T/PVCsk1CKNUkjI+L2m/ijO/JdlEUvqv0Y1eMwpen 7wQmZPz1nW6KAlaIObytdvcyDWO1RxysBoCqL7ekV0c7rooTMj5EE5TI4YK+bIW7GVom iQS7XYKNgfVSIYtAJP7RZ3REBVBtmOvRVt/y68Bd8owJN+bjJ2FxifswJWZp/CoHvUEf B5xL1GhkVKW1bCk253xSDzdJbzj/qY4NHhZxGEWRv0k/Iip2orzXWqWmN5bhzh9XBEL7 CdE+NYTEm64QAWrq9HYZ2OyyjQ5nYx2t3Xp8IR4SEGYL3m6OHP+RX1cJsr6NlBgV8hlt oJ8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794881222; x=1795486022; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=F/Wol9k3USBeEqH+PNSDq/iNuPWkX6BY1YLwxrQ5T8w=; b=Ct0ILoljPr/P/sTVhHDl5DiHYjNyVOubXVX7xASS9le4bYS5rPhl2azLjfPRYMBN5G Q5nHfWhtE948z60z/VTDzkTiKdwfjyk27raI5WhOB0cWabWf8MBD+jJ8mKRHEACdlU3F SzmbNXKn/CylDUL0QJp3VNm8FsAUiFlOxM/qkUe9VsghuBsqDReuflcrXPLMH7U1JbJc R7g7gouqEJrloBvYfW5VPZ1IbUAJgHqzEz4Ryic8dYiY25Pmag1rFajLj+vlaMLBfpo2 Qt62rs7J5/syuXi42M7tUyX+xZIJfwwA8EeoqLyDRqN3LppLOgfHW61wxG+B9Mc9hcKx RZ7g== X-Forwarded-Encrypted: i=1; AL+hErE5Oz5JNoAh6+d4tBKTmyrnkAWdb28uXiuNN9xMbc92o7b4eL4ZL5MmCsYz87a7r2XEhvs8k3D2oe4fP/Q3msng@vger.kernel.org X-Gm-Message-State: APuU4Z81G0smZjOziSup8fZW3NxzORibOq3IdyBTUTGcq/BeDuh2RUX+ UpP01mG88OLDBiCyGJT400oYV28KxLwhPIrkJX7ISAGpDd1JL42f7RforcI+Cydm6P/6HY24slt t+Oue392Et7/bhS3Rl6tq9wSYcw== X-Received: from pjbee16.prod.google.com ([2002:a17:90a:fc50:b0:3b3:863e:dcce]) (user=dylanbhatch job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4b88:b0:3ac:80de:44e8 with SMTP id 98e67ed59e1d1-3b1b0ccc955mr13158300a91.43.1794881221661; Mon, 16 Nov 2026 18:07:01 -0800 (PST) Date: Tue, 17 Nov 2026 02:06:43 +0000 In-Reply-To: <20261117020648.323464-1-dylanbhatch@google.com> X-Mailing-List: linux-toolchains@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261117020648.323464-1-dylanbhatch@google.com> X-Mailer: git-send-email 2.56.0.679.gc527c65306-goog Message-ID: <20261117020648.323464-7-dylanbhatch@google.com> Subject: [PATCH v9 06/11] arm64/sframe: Validate IP addresses From: Dylan Hatch To: Roman Gushchin , Weinan Liu , Will Deacon , Josh Poimboeuf , Indu Bhagat , Peter Zijlstra , Steven Rostedt , Catalin Marinas , Jiri Kosina , Mark Rutland , Jens Remus Cc: Dylan Hatch , Prasanna Kumar T S M , Puranjay Mohan , Song Liu , joe.lawrence@redhat.com, linux-toolchains@vger.kernel.org, linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Randy Dunlap , Mostafa Saleh , Herbert Xu , "David S . Miller" Content-Type: text/plain; charset="UTF-8" Validate the given IP and computed function start address against the known vmlinux and module text address ranges. This requires arch-specific validation for vmlinux. This is because arm64 keeps .exit.text (normally discarded) and .rodata.text, both of both of which lie outside the bounds of .text and .init.text. Note that .rodata.text contains code that is never executed by the kernel mapping, but for which the toolchain nonetheless generates sframe data, and needs to be considered valid at lookup time. Suggested-by: Jens Remus Signed-off-by: Dylan Hatch --- Changes since v8: - (sashiko) Mark is_kernel_inittext(), __is_kernel_text(), and within_module_mem_type() as __always_inline for noinstr sframe_find(). - (sashiko) Move include in sframe.c to this patch, add generic include/asm-generic/unwind_sframe.h fallback, and add unwind_sframe.h file patterns to MAINTAINERS. --- MAINTAINERS | 2 ++ arch/arm64/include/asm/sections.h | 1 + arch/arm64/include/asm/unwind_sframe.h | 32 +++++++++++++++++++ arch/arm64/kernel/vmlinux.lds.S | 2 ++ include/asm-generic/Kbuild | 1 + include/asm-generic/sections.h | 4 +-- include/asm-generic/unwind_sframe.h | 5 +++ include/linux/module.h | 6 ++-- kernel/unwind/sframe.c | 44 +++++++++++++++++++++++++- 9 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 arch/arm64/include/asm/unwind_sframe.h create mode 100644 include/asm-generic/unwind_sframe.h diff --git a/MAINTAINERS b/MAINTAINERS index 16e7ab1aea164..dd73e45218531 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -26643,6 +26643,8 @@ STACK UNWINDING M: Josh Poimboeuf M: Steven Rostedt S: Maintained +F: arch/*/include/asm/unwind_sframe.h +F: include/asm-generic/unwind_sframe.h F: include/linux/sframe.h F: include/linux/unwind*.h F: kernel/unwind/ diff --git a/arch/arm64/include/asm/sections.h b/arch/arm64/include/asm/sections.h index 51b0d594239eb..5edb4304f661e 100644 --- a/arch/arm64/include/asm/sections.h +++ b/arch/arm64/include/asm/sections.h @@ -23,6 +23,7 @@ extern char __irqentry_text_start[], __irqentry_text_end[]; extern char __mmuoff_data_start[], __mmuoff_data_end[]; extern char __entry_tramp_text_start[], __entry_tramp_text_end[]; extern char __relocate_new_kernel_start[], __relocate_new_kernel_end[]; +extern char _srodatatext[], _erodatatext[]; static inline size_t entry_tramp_text_size(void) { diff --git a/arch/arm64/include/asm/unwind_sframe.h b/arch/arm64/include/asm/unwind_sframe.h new file mode 100644 index 0000000000000..1b45d328c746f --- /dev/null +++ b/arch/arm64/include/asm/unwind_sframe.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_ARM64_UNWIND_SFRAME_H +#define _ASM_ARM64_UNWIND_SFRAME_H + +#include +#include +#include + +static __always_inline bool sframe_is_kernel_ip_valid(unsigned long ip) +{ + if (__is_kernel_text(ip) || is_kernel_inittext(ip)) + return true; + + /* .exit.text is retained in vmlinux on arm64. */ + if (ip >= (unsigned long)__exittext_begin && + ip < (unsigned long)__exittext_end) + return true; + + /* + * .rodata.text is never executed from the kernel mapping, but it still + * has sframe data. + */ + if (ip >= (unsigned long)_srodatatext && + ip < (unsigned long)_erodatatext) + return true; + + return false; +} + +#define sframe_is_kernel_ip_valid sframe_is_kernel_ip_valid + +#endif /* _ASM_ARM64_UNWIND_SFRAME_H */ diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 3cfa62249d0b4..62534cc9771a0 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -245,12 +245,14 @@ SECTIONS /* code sections that are never executed via the kernel mapping */ .rodata.text : { + _srodatatext = .; TRAMP_TEXT HIBERNATE_TEXT KEXEC_TEXT IDMAP_TEXT . = ALIGN(PAGE_SIZE); } + _erodatatext = .; idmap_pg_dir = .; . += PAGE_SIZE; diff --git a/include/asm-generic/Kbuild b/include/asm-generic/Kbuild index b7a388bef6ea0..9230bd7878ef8 100644 --- a/include/asm-generic/Kbuild +++ b/include/asm-generic/Kbuild @@ -61,6 +61,7 @@ mandatory-y += tlbflush.h mandatory-y += topology.h mandatory-y += trace_clock.h mandatory-y += uaccess.h +mandatory-y += unwind_sframe.h mandatory-y += unwind_user.h mandatory-y += vdso/clocksource.h mandatory-y += vdso/vsyscall.h diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h index 336d27011a580..c9b0cec9990c1 100644 --- a/include/asm-generic/sections.h +++ b/include/asm-generic/sections.h @@ -197,7 +197,7 @@ static inline bool is_kernel_ro_after_init(unsigned long addr) * * Returns: true if the address is located in .init.text, false otherwise. */ -static inline bool is_kernel_inittext(unsigned long addr) +static __always_inline bool is_kernel_inittext(unsigned long addr) { return addr >= (unsigned long)_sinittext && addr < (unsigned long)_einittext; @@ -212,7 +212,7 @@ static inline bool is_kernel_inittext(unsigned long addr) * Returns: true if the address is located in .text, false otherwise. * Note: an internal helper, only check the range of _stext to _etext. */ -static inline bool __is_kernel_text(unsigned long addr) +static __always_inline bool __is_kernel_text(unsigned long addr) { return addr >= (unsigned long)_stext && addr < (unsigned long)_etext; diff --git a/include/asm-generic/unwind_sframe.h b/include/asm-generic/unwind_sframe.h new file mode 100644 index 0000000000000..f71b3b0f53db9 --- /dev/null +++ b/include/asm-generic/unwind_sframe.h @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_UNWIND_SFRAME_H +#define _ASM_GENERIC_UNWIND_SFRAME_H + +#endif /* _ASM_GENERIC_UNWIND_SFRAME_H */ diff --git a/include/linux/module.h b/include/linux/module.h index 6793e9feb20a5..964f727a65ff3 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -628,9 +628,9 @@ bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr); bool is_module_percpu_address(unsigned long addr); bool is_module_text_address(unsigned long addr); -static inline bool within_module_mem_type(unsigned long addr, - const struct module *mod, - enum mod_mem_type type) +static __always_inline bool within_module_mem_type(unsigned long addr, + const struct module *mod, + enum mod_mem_type type) { unsigned long base, size; diff --git a/kernel/unwind/sframe.c b/kernel/unwind/sframe.c index 55b7838bdd485..d5c1c8148dadd 100644 --- a/kernel/unwind/sframe.c +++ b/kernel/unwind/sframe.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "sframe.h" @@ -45,6 +46,45 @@ struct sframe_fre_internal { unsigned char dw_size; }; +#ifndef sframe_is_kernel_ip_valid + +static __always_inline bool sframe_is_kernel_ip_valid(unsigned long ip) +{ + return __is_kernel_text(ip) || is_kernel_inittext(ip); +} + +#endif + +#ifdef CONFIG_MODULES + +static __always_inline bool sframe_is_sec_module_ip_valid(struct sframe_section *sec, + unsigned long ip) +{ + struct module *mod = container_of(sec, struct module, sframe_sec); + + return within_module_mem_type(ip, mod, MOD_TEXT) || + within_module_mem_type(ip, mod, MOD_INIT_TEXT); +} + +#else + +static __always_inline bool sframe_is_sec_module_ip_valid(struct sframe_section *sec, + unsigned long ip) +{ + return false; +} + +#endif + +static __always_inline bool is_sec_ip_valid(struct sframe_section *sec, + unsigned long ip) +{ + if (sec == &kernel_sfsec) + return sframe_is_kernel_ip_valid(ip); + + return sframe_is_sec_module_ip_valid(sec, ip); +} + static __always_inline unsigned char fre_type_to_size(unsigned char fre_type) { if (fre_type > 2) @@ -72,6 +112,8 @@ static __always_inline int __read_fde(struct sframe_section *sec, _fde = (struct sframe_fde_v3 *)fde_addr; func_addr = fde_addr + _fde->func_start_off; + if (!is_sec_ip_valid(sec, func_addr)) + return -EINVAL; if (check_add_overflow(sec->fres_start, _fde->fres_off, &fda_addr) || check_add_overflow(fda_addr, sizeof(struct sframe_fda_v3), &fres_addr) || @@ -455,7 +497,7 @@ noinstr int sframe_find(unsigned long ip, struct unwind_frame *frame) if (!frame) return -EINVAL; - if (__is_kernel_text(ip) || is_kernel_inittext(ip)) { + if (sframe_is_kernel_ip_valid(ip)) { if (!sframe_init) return -EINVAL; -- 2.56.0.679.gc527c65306-goog