From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796069910; b=n+ZmSkRBHA0IFEc4cYF9uFMaGD8n6ZVgQEF5pUXVNNJXbjKdInwxj0tyiIfaXioo2dFt xSyTfZDPy2OFHmXZqT/ZqxM+DTfX7ivGQGjud39LT1agST6B7YaqHn4ku9Pya+1DWRiLU ROMzm56OIoLeGA8A7TdNfhLnjwdgJoxnPweLcK2mK+2RSC2+lfZXOh1EihY+SDD9ou+Qz xoUndbyCsWEmp603UACM87tZn8OHYCrUrmETwQ8d44HWOdD/3X1oatodvIcufRoOCvYcd 3STv5KJErnBhAYoB5zC3nMCgFRWH2l2rDuUn7lhcns5OA2dBomSfKJ18MrpcvBOid7g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796069910; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:Date:From:To:Cc:Subject: Message-ID:References:MIME-Version:Content-Type:Content-Disposition: In-Reply-To:X-Scanned-By; bh=ERV7W/+RGKi34VqyqqXt9v0koWcyx4Td6OgxwAJpt0E=; b=BxpOWk+j8UPQ9htMLc2r6eRrymDq2ihdcVSf2qmzIWPg3KsZcIBMCjx4AxOdKJ/kjoYv kTm1huoLJtc19FKFYR+yrKaV34m12rmKr8OXnScO50+Z//1+iQoMy0PFZcnD9v8lZ266I p8c5ubRU3p+WJsQYoMKYAXQHWwH1ZXLK4Qt2G6IEUT8ltZTDIaQxe9uLtMh7Z+el0vtJ4 o7xkJBHpiYx3bOb4d/DDLboORxeD1teyPECd62QNlAgpOKOQdS0sgUlqnQIrtBS1GoIxP Tr+cUO2tU5I1Z25tnkrhb0WW8BIyjosOJuX82QXMGJduPeseBnejHdcGlU/cB4XH6kA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OYBAJZDo; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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.subspace.kernel.org (Postfix) with ESMTPS id F2F69606A32C for ; Mon, 30 Nov 2026 20:18:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F2F69606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OYBAJZDo DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796069909; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ERV7W/+RGKi34VqyqqXt9v0koWcyx4Td6OgxwAJpt0E=; b=OYBAJZDohA56jo/ae6A46t1CAxwFAq4tOYusUXFSR4x5mHNHDYDZo2Gn3vVrzhQQZbV6/P z1HN1M0okhDPeSJxAzyr3rR2UzmJPnnSchtKCGdzOzLXnx07NRpBEF+O3vVtpHeirGRlKF K7rZCk5il7Vci7d3qB8hm5G1WiW5JXY= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-207-f3wChEiwMwWknzSKq0raRQ-1; Mon, 30 Nov 2026 20:18:25 +0000 X-MC-Unique: f3wChEiwMwWknzSKq0raRQ-1 X-Mimecast-MFC-AGG-ID: f3wChEiwMwWknzSKq0raRQ_1796069904 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BC87218004D2; Mon, 30 Nov 2026 20:18:23 +0000 (UTC) Received: from redhat.com (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C6B5B1955F71; Mon, 30 Nov 2026 20:18:21 +0000 (UTC) Date: Mon, 30 Nov 2026 15:18:18 -0500 From: Joe Lawrence To: binoy@vt.edu Cc: Josh Poimboeuf , Peter Zijlstra , Song Liu , linux-kernel@vger.kernel.org, live-patching@vger.kernel.org Subject: Re: [PATCH] objtool/klp: Copy constant pool entries for local labels Message-ID: References: <20261127-objtool-klp-cst-v1-1-dc19b08c8676@vt.edu> X-Mailing-List: live-patching@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=us-ascii Content-Disposition: inline In-Reply-To: <20261127-objtool-klp-cst-v1-1-dc19b08c8676@vt.edu> X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 On Fri, Nov 27, 2026 at 08:26:09PM -0500, Binoy Ravindran via B4 Relay wrote: > 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 > Signed-off-by: Binoy Ravindran > --- > A small problem in __clone_symbol(): a .LC label in a .rodata.cst* > pool has no size, so its constant is never copied into the livepatch > module, and the patched function reads whatever bytes follow. Details > and the three affected modules are in the patch. > > Tested on v7.4-rc2 (x86-64, GCC 12): with the fix, the three modules > hold the compiler's constants, and three unaffected modules are > unchanged. The patch applies to tip objtool/core and to mainline. Hi Binoy, This fix looks reasonable to me: Acked-by: Joe Lawrence Can you take a look at tools/objtool/Documentation/{klp-write-tests.txt,klp-test-design.txt} (or point your AI agent there) and incorporate a test case into the objtool tests? This patch looks like a good test candidate, and since the the section is idential with the only difference between gcc and clang being the zero-size .L* label name (.LC0 vs .LCPI0_0), a single test in generic/ with that asserts on the .rodata.cst* section (rather than the label name) should cover both compilers when CI runs the matrix. Thanks! -- Joe > --- > 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; > > --- > base-commit: b99a5337da3c847db216476d645b69acd714c3ba > change-id: 20261127-objtool-klp-cst-53a24047f0e9 > > Best regards, > -- > Binoy Ravindran > > >