From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796082663; b=B+CAYpzXBvgI3i3aNU/1wHRrPlV/iVyweS1eXnHbRNrdSv5rHXCgDN5wVcEURLc/Z/6G Wh/ww0ktizj4AqrsApioVOTtMOgLK/Ph3/f3Yv/DoeulxcZ2kU9XFqYiUR90li05FV7FW a0wC7zaFbIXnd9CxcEMmo+WLLyUKod0lr3Kv4ifVG8UVhmzApc//DyVu8Uvax6P98bsTP oBQybA6lVkNy35Qsj2hlkChKurs4wl88Qqdmp3vdpUMfYVk9Ooq+9YL9547ouSCKszQxk zkrdvyf9eK1Su0aodQr+KSu0fPPtz7w/RtZp4opqQxYILQR5QWiSme0mJwS19HtmIGg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796082663; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=+f8pr4uQGq3dcDrtDuuAW1w6tZ9W9RxQzwQri0Su+Jw=; b=NGzaJQG9WQozACXcRGeV829JpPFEiu21NPvWTCvM7ceIFdJC+69T5F3qLYCfXcFhvMFJ hjFNJoHWKHtfdrkqJ0ue5g+7gvfCFy6VOdk4fJxs7Pt3r+RkVpVRxfdJDJNEpHh2bnWpS 5zJftU5sFpXSBXRoEqQGTKdWHeP4mOwVLF4vB+aNKT27XsAM4a4gmTvej/SGpGDf9lho/ 8CrNk6YMXdIhDHMckIW1SK/+STBFtIcr4v72n3t2Qa/OpCZUuPQUlSWlQC8iDy/BZOElB y0fCQAoaRGY8seKrEVjEt44hqnXsfNXCBbgBTrVklaEbhSbsa3Ck8sUo405/OpqZc3g== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=beIEIeEd; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D0B7606A31A; Mon, 30 Nov 2026 23:51:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=beIEIeEd Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796082662; b=JCxUWJ+a68ancTzbu2XR7WgqmTuOGSBxOw26yYlW6df8PLcBiGhwDZb8q7b0VarRG83/ cljda/cRZL0ag/9P1gbbbMqdmXePg3L1bKBKwvjvRrqO7uuvWCMazyWi6pED4HDYUC7FG t1D9lpRdh/Ww6BnOIIwUpBBW+oqJEtNTodG/VNSfcHPKs+gexSntfdEjDKVrKwHnZLGpb WICngbWfHG4dGIYDoxdWIxzmY9hOC5s2OnpAf7VukTKET/oxViriQUBgxMKFDKbrJ5Ve4 fxMbezgi4InYr6+vNclIj3f3dWS8voit1FBOaBjK90mCyRy3/Ww865hWpYwyKGIaaFQ== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796082662; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=+f8pr4uQGq3dcDrtDuuAW1w6tZ9W9RxQzwQri0Su+Jw=; b=p4CeYllla97Ks4kGH9MhGR70PwWwMxAIg0iaeGdOIBYm2F5ARn33o9Qxqehfpk/w1Eon 53ffOV7p8i+DnfOdjhTq+V1bBCU+yS6ClGIU7+Z8mTIqOKH3h72Lnd6UmboBTyhjHRL4T J9ZsltpL7nGpGDOogm/TLS8m/6+Qfk1AlPwOMG1Su+SdMu/P+s1RWVfCaNdNNlisMmOaY hI68Y0+T0mrBrpKNCd2wBv9+OWP/V/Xu5YZ5kMqPRaAvHV4O6PZnRD4IaUkb37mRiTa2M Jc7ncSBynm1xC9zcF//LGRwUOr1x24aKI3kh8afCk/9HkD42+9yQVUsusZSqloA4riw== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id B24051F00896; Mon, 30 Nov 2026 23:50:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796082662; bh=+f8pr4uQGq3dcDrtDuuAW1w6tZ9W9RxQzwQri0Su+Jw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=beIEIeEd9bFGcnRkec2+OAJ6fZo5Bvaz4kNJGSsUCTnhQ1DZirfLLUImJZC7L5hot k2V4oy6yRG8kKofuqt0HEDlriz2B9VeY2vfSR1YcxIIRhbSmwl9miNG5eotr8z0Tui ks6IJ1BgCvK4dQF83xpivCI64dhYhcZr/xYgTfZX5Yg0LcfSRp5B6weyEAIvVPZy8F pzuBA4dBRxW+cWfMkVvOUrmqQSsdyxjW+c6qaHHl5xqfDQnOI8wv3fF6sZTpBkxUI/ OuMrIg55WKlO6DIRs0AxR/9m1OTu3tpyGbzG0GGS93fUq00RyNuKcL0+qemNnkeH34 Jl2B/mlmzM2Qg== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 3B44D4EAF5; Mon, 30 Nov 2026 23:50:50 +0000 (UTC) From: Binoy Ravindran via B4 Relay Date: Mon, 30 Nov 2026 18:50:37 -0500 Subject: [PATCH v2 1/2] objtool/klp: Copy constant pool entries for local labels X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261130-objtool-klp-cst-v2-1-2718c17fca37@vt.edu> References: <20261130-objtool-klp-cst-v2-0-2718c17fca37@vt.edu> In-Reply-To: <20261130-objtool-klp-cst-v2-0-2718c17fca37@vt.edu> To: Josh Poimboeuf , Peter Zijlstra , Song Liu , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt Cc: Joe Lawrence , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Binoy Ravindran X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796082649; l=3269; i=binoy@vt.edu; s=20261123; h=from:subject:message-id; bh=NXJkMKiLXytuM16Obruonf8Dl79wkV58pGqZ0Gv4FP8=; b=PwXTQBOFhRvhZrd+OSWPLdfS2jbNC5KYQlAkzDdAEo1ppiXMV6gJclbILstJvWd98uHt2O+Yx e74nyDbM37oCpkryNGxzKE0WxALsq2vL/N/RQbSLDJpYcG+U3ZHZwdi X-Developer-Key: i=binoy@vt.edu; a=ed25519; pk=4cNdKPHP0InmhK/9bb7Tm2ZMUXUvLGfw1pmVt5b98fA= X-Endpoint-Received: by B4 Relay for binoy@vt.edu/20261123 with auth_id=1622 X-Original-From: Binoy Ravindran Reply-To: binoy@vt.edu Content-Transfer-Encoding: 7bit From: Binoy Ravindran The compiler refers to a constant in a .rodata.cst* pool through a local label such as .LC32. The label has no size. Since commit 51e1dfce24c8 ("objtool/klp: Don't correlate .rodata.cst* constant pool objects"), klp-diff clones such a label together with its data. But __clone_symbol() copies data only for a symbol with a nonzero length or for a section symbol. For a .LC label it copies nothing and places the label at the current end of the output section. The patched function then reads whatever ends up at that place when the module is linked. Building livepatches with klp-build for recent fixes on v7.4-rc2 (x86-64, GCC 12), three of 54 modules read the wrong 2-byte constant: fib_table_insert() .LC32 expected 0x0000, reads 0x6e00 ieee80211_rx_mgmt_beacon() .LC68 expected 0x0000, reads 0x6e00 cfg80211_inform_bss_data() .LC9 expected 0x1000, reads 0x0000 In each case the bytes come from the end of an unrelated string in the module's .rodata. The modules load and patch without any warning. We confirmed this in a running kernel: with the first module loaded, the patched fib_table_insert() loads 0x6e00. A label in a SHF_MERGE constant pool names one entry of sh_entsize bytes. Copy that entry when the label has no size. With this change, all three modules hold the compiler's constants. Fixes: 51e1dfce24c8 ("objtool/klp: Don't correlate .rodata.cst* constant pool objects") Assisted-by: Claude:claude-opus-5-5 Acked-by: Joe Lawrence Signed-off-by: Binoy Ravindran --- tools/objtool/klp-diff.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 95d0d86666d7..f8a638b29a26 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -923,6 +923,7 @@ static struct symbol *__clone_symbol(struct elf *elf, struct symbol *patched_sym if (data_too && !is_undef_sym(patched_sym)) { struct section *patched_sec = patched_sym->sec; + size_t len = patched_sym->len; out_sec = find_section_by_name(elf, patched_sec->name); if (!out_sec) { @@ -946,7 +947,17 @@ static struct symbol *__clone_symbol(struct elf *elf, struct symbol *patched_sym if (!is_sec_sym(patched_sym)) offset = ALIGN(sec_size(out_sec), out_sec->sh.sh_addralign); - if (patched_sym->len || is_sec_sym(patched_sym)) { + /* + * A local label in a constant pool (.rodata.cst*) has no size, + * but it names one entry of sh_entsize bytes. Copy that entry, + * or the label ends up pointing at whatever data follows it. + */ + if (!len && !is_sec_sym(patched_sym) && + (patched_sec->sh.sh_flags & SHF_MERGE) && + !is_string_sec(patched_sec) && patched_sec->sh.sh_entsize) + len = patched_sec->sh.sh_entsize; + + if (len || is_sec_sym(patched_sym)) { void *data = NULL; size_t size; @@ -957,7 +968,7 @@ static struct symbol *__clone_symbol(struct elf *elf, struct symbol *patched_sym if (is_sec_sym(patched_sym)) size = sec_size(patched_sym->sec); else - size = patched_sym->len; + size = len; if (!elf_add_data(elf, out_sec, data, size)) return NULL; -- 2.39.5