From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796071885; b=ObI5wBlhEtjjI4pmteFhc8KGrjrHlt3wXcFksRXS0g/UYuf4a05DYmMDQ4DU1LrH3q0v 80azvc0qZWK1PPc/2DDN4Iuqvu3r2Q8eTXSOgpGwrg36zTu5iU0+bPdYW2RRekPGlrtYn 2lu/aBW0Pa/ETJy9fn2yZdvtR/mMPNM6yF2lxwPahtNZKK4VqKr3vv72ogs6R2cWaeVXm uJxuOhcBY587YkPOiRsYGv4suRTdumv+lL1Ezf2M5oKOGWKzLG8rvLIDgjfS9w+/8cepM Rq/DHmEo8fwsw49/JGmWkQQRQGFsIEH7Drw7i09ogz3trHgMCqaViUbtoxMh8o2fp9A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796071885; 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=SX/zQAK1kWCaGeiNsXUP5//PrX2PxDOvmifwS0/cLws=; b=TxT2GgqpP2It3BvKsthXv2sssrPJyRaWsAg+YisqNImWELVvjaeddaJBSIsHc7Rgk1cD G/1OLkuV1qRpbH3RWAc1vUfGcaHMxX7sIlYT7g+XWcMEGZ117vgAPwMCvwVCRsLIDELnn 75g1U7oGP/xmXMXFe8S8lOzmWrnSmW4XL74ojM81jbcC8FdyLmkHg022eo3bCsg1bAXNy CsmGX0EpKZP3uc/pCyflWJk7PKtMDdsoGgO/aGTgkMO5lGwO+0XfOpMAJwtPPOcBipxEk x0YZt+jKBbSbBuBz+QXvVS6OrE3UPkzWzJrevNGnsI8CXQrwNMd/rahDY5r7RzFdqng== 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=MuUAUd7V; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 95176606A329 for ; Mon, 30 Nov 2026 20:51:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 95176606A329 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=MuUAUd7V DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796071883; 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=SX/zQAK1kWCaGeiNsXUP5//PrX2PxDOvmifwS0/cLws=; b=MuUAUd7Vkhx7+Hb5ChXkDxetLYWVYWf0SROvfrqieHXLUzuYrqLxtPUquFlwiprVKofR8K WkzE0zuK83c+eUWZpsL48px/wDQcFPQdVu1d3vmb/YwakO9C04rsuNZHzanlDvlmD+H1Fe TRcF15iUL7zTVSzKcoeSIqZjyBBjdvU= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-588-Kl4a1CQgPICZOToGwigL5g-1; Mon, 30 Nov 2026 20:51:19 +0000 X-MC-Unique: Kl4a1CQgPICZOToGwigL5g-1 X-Mimecast-MFC-AGG-ID: Kl4a1CQgPICZOToGwigL5g_1796071878 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D68F51955F08; Mon, 30 Nov 2026 20:51:17 +0000 (UTC) Received: from redhat.com (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7A5CE18004F5; Mon, 30 Nov 2026 20:51:16 +0000 (UTC) Date: Mon, 30 Nov 2026 15:51:14 -0500 From: Joe Lawrence To: Seke Kazuru Cc: live-patching@vger.kernel.org, jpoimboe@kernel.org, mbenes@suse.cz, "pmladek@suse.com" , "song@kernel.org" , peterz@infradead.org, bpf@vger.kernel.org Subject: Re: objtool/klp: ___bpf_prog_run jumptable is correlated to the original, fix never runs Message-ID: References: X-Mailing-List: bpf@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: X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 On Sat, Nov 28, 2026 at 08:51:14AM +0200, Seke Kazuru wrote: > Hello, > > A livepatch module built by klp-build for a fix to ___bpf_prog_run() > loads, reports "patching complete", and lists ___bpf_prog_run as > patched, but the fixed instruction handlers never run. The replaced > function dispatches through vmlinux's copy of its static jumptable, > whose entries point into the original function body. > > Setup: Linux 6.19, x86_64, gcc 13, a config without BPF JIT (so every > program runs in the interpreter), klp-build from the same tree: > > ./scripts/livepatch/klp-build -T --no-replace -o lp.ko fix.patch > > The fix is c77b30bd1dcb ("bpf: Fix undefined behavior in interpreter > sdiv/smod for INT_MIN"), which changes the signed DIV and MOD handlers > inside ___bpf_prog_run(). Those handlers are reached only through the > computed-goto table: > > static const void * const jumptable[256] = { ... &&label ... }; > > klp diff refers every static local of a changed function to the > original kernel's copy unless is_uncorrelated_static_local() exempts its > name. "jumptable" is not on that list (6.19, and still not in > 7.4-rc4). The module's ___bpf_prog_run therefore carries a relocation > to .klp.sym.vmlinux.jumptable.12 (R_X86_64_32S at +0x40), and every > dispatch lands in the original handlers. > > Test, under KVM: a small helper module runs a three-instruction > program through the interpreter (r0 = S32_MIN; r0 s/= 2 as ALU32 DIV K > with off 1; exit) and prints r0. Unfixed code returns 0x40000000, > fixed code 0xc0000000. > > boot 1, klp-build module as built: > before load: 0x40000000 (6 of 6 runs) > after load, enabled=1, transition=0, "patching complete", > /sys/kernel/livepatch//vmlinux/___bpf_prog_run,1 present: > 0x40000000 (6 of 6 runs) > > boot 2, same command and same fix, with "jumptable." added to the > list in is_uncorrelated_static_local(): > before load: 0x40000000 (6 of 6) > after load: 0xc0000000 (6 of 6) > > The build prints no warning, and every kernel signal reports success. > Any klp-build fix to ___bpf_prog_run has this effect on kernels that run > the interpreter, that is without CONFIG_BPF_JIT_ALWAYS_ON when the JIT > is off or unavailable. > > Two possible fixes: > > 1. Add "jumptable" to is_uncorrelated_static_local(). This is the change > tested in boot 2. It covers this function only. > > 2. More generally, do not correlate a static local whose relocations > point into the changed function's own text (label addresses). Such a > table describes the code, not shared state, so it has to follow the > new function. This would also cover any other computed-goto table. > > I can send the helper module, the program, the kernel config and the > two klp-build logs. I am glad to test a patch on the same setup. > > This came up in a study of live-patch module fidelity. Of 70 klp-build > modules built from real stable fixes on 6.19, this is the only one in > which a changed function's new code does not run. > > Thank you for your time. Hi Seke, Thanks for the detailed report. On the fixes: option 2 seems preferable. Option 1 (adding "jumptable" to the list) may work but sounds fragile, it only catches tables spelled "jumptable", right? On the other hand, keying on "a static local whose relocations point into the changed function's own text" would be compiler/name-agnostic I believe. Before settling on a fix, could you turn this repro into a regression test for the objtool klp suite? It'd be fix-independent (any correct fix makes it pass) and would guard this going forward. See tools/objtool/Documentation/{klp-write-tests.txt,klp-test-design.txt} and tools/objtool/tests/generic/test-switch-rodata.sh, which covers a similar Clang switch-table test. A computed-goto test, run under both gcc and clang, should reproduce it. In my experience, AI agents can usually create a reasonable test from the docs and a report like your own. Thanks, -- Joe