Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Alan Maguire <alan.maguire@oracle.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Sasha Levin <sashal@kernel.org>,
	eddyz87@gmail.com, ast@kernel.org, daniel@iogearbox.net,
	bpf@vger.kernel.org
Subject: [PATCH AUTOSEL 6.14 020/108] libbpf/btf: Fix string handling to support multi-split BTF
Date: Tue,  3 Jun 2025 20:54:03 -0400	[thread overview]
Message-ID: <20250604005531.4178547-20-sashal@kernel.org> (raw)
In-Reply-To: <20250604005531.4178547-1-sashal@kernel.org>

From: Alan Maguire <alan.maguire@oracle.com>

[ Upstream commit 4e29128a9acec2a622734844bedee013e2901bdf ]

libbpf handling of split BTF has been written largely with the
assumption that multiple splits are possible, i.e. split BTF on top of
split BTF on top of base BTF.  One area where this does not quite work
is string handling in split BTF; the start string offset should be the
base BTF string section length + the base BTF string offset.  This
worked in the past because for a single split BTF with base the start
string offset was always 0.

Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250519165935.261614-2-alan.maguire@oracle.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

**YES** This commit should be backported to stable kernel trees. Here's
my detailed analysis: ## Bug Analysis This commit fixes a critical bug
in libbpf's BTF string offset calculation for multi-level split BTF
scenarios. The specific code change on line 998: ```c // Before (buggy):
btf->start_str_off = base_btf->hdr->str_len; // After (correct):
btf->start_str_off = base_btf->hdr->str_len + base_btf->start_str_off;
``` ## Technical Impact **Scenario:** Multi-level split BTF chain (e.g.,
vmlinux BTF → module1 BTF → module2 BTF) **The Bug:** The incorrect
calculation failed to accumulate string offsets across the full BTF
chain. For example: - vmlinux BTF: `start_str_off = 0`, `str_len = 1000`
- module1 BTF: `start_str_off = 1000`, `str_len = 500` - module2 BTF:
`start_str_off = 500` ❌ (should be 1500!) **Consequences:** 1. **Data
Corruption**: String lookups (`btf__str_by_offset()`) return wrong
strings 2. **Potential Crashes**: Incorrect memory access when offset
calculations go wrong 3. **Silent Failures**: Wrong type/field names
returned without obvious errors ## Real-World Impact This affects
several important use cases: 1. **Kernel Module Loading**: Modules with
nested BTF dependencies 2. **BPF Program Loading**: Programs using
complex split BTF 3. **Debugging Tools**: bpftool operations on kernel
modules showing incorrect information 4. **BPF Verification**: Kernel
verifier potentially seeing wrong type names ## Backport Justification
**1. Important Bug Fix**: This fixes existing broken functionality, not
a new feature. The commit message clearly states it's fixing string
handling that "does not quite work." **2. High Impact**: Can cause data
corruption and crashes in real-world scenarios where kernel modules use
multi-level split BTF. **3. Low Risk**: The fix is minimal and surgical
- just correcting a mathematical calculation. The risk of regression is
very low. **4. Existing Functionality**: Multi-level split BTF is
supposed to work (evidenced by the correct implementation in
`btf_new_empty()` and existing test coverage), but this bug broke it.
**5. Real-world Usage**: Kernel modules commonly use split BTF,
especially in distributions with many out-of-tree modules. **6. Test
Coverage**: There are existing BPF selftests that validate multi-level
split BTF scenarios. ## Stable Tree Suitability This meets all stable
tree criteria: - ✅ Fixes important bug affecting users - ✅ Small,
contained change - ✅ No architectural changes - ✅ Minimal regression
risk - ✅ Fixes critical subsystem (BTF/BPF) The similar historical
commits were marked "NO" because they were adding new features (split
BTF support itself) rather than fixing bugs in existing functionality.
This commit is fundamentally different - it's a correctness fix for
functionality that was supposed to work but didn't.

 tools/lib/bpf/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 560b519f820e2..a39894a7be054 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -996,7 +996,7 @@ static struct btf *btf_new_empty(struct btf *base_btf)
 	if (base_btf) {
 		btf->base_btf = base_btf;
 		btf->start_id = btf__type_cnt(base_btf);
-		btf->start_str_off = base_btf->hdr->str_len;
+		btf->start_str_off = base_btf->hdr->str_len + base_btf->start_str_off;
 		btf->swapped_endian = base_btf->swapped_endian;
 	}
 
-- 
2.39.5


  parent reply	other threads:[~2025-06-04  0:56 UTC|newest]

Thread overview: 108+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-04  0:53 [PATCH AUTOSEL 6.14 001/108] net: macb: Check return value of dma_set_mask_and_coherent() Sasha Levin
2025-06-04  0:53 ` [PATCH AUTOSEL 6.14 002/108] net: lan743x: Modify the EEPROM and OTP size for PCI1xxxx devices Sasha Levin
2025-06-04  0:53 ` [PATCH AUTOSEL 6.14 003/108] tipc: use kfree_sensitive() for aead cleanup Sasha Levin
2025-06-04  0:53 ` [PATCH AUTOSEL 6.14 004/108] f2fs: use vmalloc instead of kvmalloc in .init_{,de}compress_ctx Sasha Levin
2025-06-04  0:53 ` [PATCH AUTOSEL 6.14 005/108] bpf: Check rcu_read_lock_trace_held() in bpf_map_lookup_percpu_elem() Sasha Levin
2025-06-04  0:53 ` [PATCH AUTOSEL 6.14 006/108] Bluetooth: btusb: Add new VID/PID 13d3/3584 for MT7922 Sasha Levin
2025-06-04  0:53 ` [PATCH AUTOSEL 6.14 007/108] i2c: designware: Invoke runtime suspend on quick slave re-registration Sasha Levin
2025-06-04  0:53 ` [PATCH AUTOSEL 6.14 008/108] wifi: mt76: mt7996: drop fragments with multicast or broadcast RA Sasha Levin
2025-06-04  0:53 ` [PATCH AUTOSEL 6.14 009/108] emulex/benet: correct command version selection in be_cmd_get_stats() Sasha Levin
2025-06-04  0:53 ` [PATCH AUTOSEL 6.14 010/108] Bluetooth: btusb: Add new VID/PID 13d3/3630 for MT7925 Sasha Levin
2025-06-04  0:53 ` [PATCH AUTOSEL 6.14 011/108] Bluetooth: btusb: Add RTL8851BE device 0x0bda:0xb850 Sasha Levin
2025-06-04  0:53 ` [PATCH AUTOSEL 6.14 012/108] Bluetooth: ISO: Fix not using SID from adv report Sasha Levin
2025-06-04  0:53 ` [PATCH AUTOSEL 6.14 013/108] Bluetooth: btmrvl_sdio: Fix wakeup source leaks on device unbind Sasha Levin
2025-06-04  0:53 ` [PATCH AUTOSEL 6.14 014/108] Bluetooth: btmtksdio: " Sasha Levin
2025-06-04  0:53 ` [PATCH AUTOSEL 6.14 015/108] wifi: mt76: mt76x2: Add support for LiteOn WN4516R,WN4519R Sasha Levin
2025-06-04  0:53 ` [PATCH AUTOSEL 6.14 016/108] wifi: mt76: mt7921: add 160 MHz AP for mt7922 device Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 017/108] wifi: mt76: mt7925: introduce thermal protection Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 018/108] wifi: mac80211: validate SCAN_FLAG_AP in scan request during MLO Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 019/108] sctp: Do not wake readers in __sctp_write_space() Sasha Levin
2025-06-04  0:54 ` Sasha Levin [this message]
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 021/108] cpufreq: scmi: Skip SCMI devices that aren't used by the CPUs Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 022/108] i2c: tegra: check msg length in SMBUS block read Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 023/108] i2c: npcm: Add clock toggle recovery Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 024/108] clk: qcom: gcc-x1e80100: Set FORCE MEM CORE for UFS clocks Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 025/108] clk: qcom: gcc: Set FORCE_MEM_CORE_ON for gcc_ufs_axi_clk for 8650/8750 Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 026/108] net: dlink: add synchronization for stats update Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 027/108] wifi: ath12k: fix macro definition HAL_RX_MSDU_PKT_LENGTH_GET Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 028/108] wifi: ath12k: fix a possible dead lock caused by ab->base_lock Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 029/108] wifi: ath11k: Fix QMI memory reuse logic Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 030/108] iommu/amd: Allow matching ACPI HID devices without matching UIDs Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 031/108] wifi: rtw89: leave idle mode when setting WEP encryption for AP mode Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 032/108] tcp: always seek for minimal rtt in tcp_rcv_rtt_update() Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 033/108] tcp: remove zero TCP TS samples for autotuning Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 034/108] tcp: fix initial tp->rcvq_space.space value for passive TS enabled flows Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 035/108] tcp: add receive queue awareness in tcp_rcv_space_adjust() Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 036/108] x86/sgx: Prevent attempts to reclaim poisoned pages Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 037/108] ipv4/route: Use this_cpu_inc() for stats on PREEMPT_RT Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 038/108] net: page_pool: Don't recycle into cache " Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 039/108] xfrm: validate assignment of maximal possible SEQ number Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 040/108] openvswitch: Stricter validation for the userspace action Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 041/108] net: atlantic: generate software timestamp just before the doorbell Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 042/108] pinctrl: armada-37xx: propagate error from armada_37xx_pmx_set_by_name() Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 043/108] pinctrl: armada-37xx: propagate error from armada_37xx_gpio_get_direction() Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 044/108] bpf: Pass the same orig_call value to trampoline functions Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 045/108] net: stmmac: generate software timestamp just before the doorbell Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 046/108] pinctrl: armada-37xx: propagate error from armada_37xx_pmx_gpio_set_direction() Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 047/108] libbpf: Check bpf_map_skeleton link for NULL Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 048/108] pinctrl: armada-37xx: propagate error from armada_37xx_gpio_get() Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 049/108] net/mlx5: HWS, fix counting of rules in the matcher Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 050/108] net: mlx4: add SOF_TIMESTAMPING_TX_SOFTWARE flag when getting ts info Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 051/108] net: vertexcom: mse102x: Return code for mse102x_rx_pkt_spi Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 052/108] wifi: rtw88: rtw8822bu VID/PID for BUFFALO WI-U2-866DM Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 053/108] wireless: purelifi: plfxlc: fix memory leak in plfxlc_usb_wreq_asyn() Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 054/108] wifi: mac80211: do not offer a mesh path if forwarding is disabled Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 055/108] bpftool: Fix cgroup command to only show cgroup bpf programs Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 056/108] clk: rockchip: rk3036: mark ddrphy as critical Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 057/108] hid-asus: check ROG Ally MCU version and warn Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 058/108] rtla: Define __NR_sched_setattr for LoongArch Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 059/108] wifi: iwlwifi: mvm: fix beacon CCK flag Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 060/108] wifi: iwlwifi: dvm: pair transport op-mode enter/leave Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 061/108] bpf: Add bpf_rbtree_{root,left,right} kfunc Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 062/108] f2fs: fix to bail out in get_new_segment() Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 063/108] netfilter: nft_set_pipapo: clamp maximum map bucket size to INT_MAX Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 064/108] libbpf: Add identical pointer detection to btf_dedup_is_equiv() Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 065/108] scsi: lpfc: Fix lpfc_check_sli_ndlp() handling for GEN_REQUEST64 commands Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 066/108] scsi: smartpqi: Add new PCI IDs Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 067/108] iommu/amd: Ensure GA log notifier callbacks finish running before module unload Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 068/108] wifi: iwlwifi: pcie: make sure to lock rxq->read Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 069/108] wifi: rtw89: 8922a: fix TX fail with wrong VCO setting Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 070/108] wifi: mac80211_hwsim: Prevent tsf from setting if beacon is disabled Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 071/108] netdevsim: Mark NAPI ID on skb in nsim_rcv Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 072/108] net/mlx5: HWS, Fix IP version decision Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 073/108] bpf: Use proper type to calculate bpf_raw_tp_null_args.mask index Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 074/108] wifi: mac80211: VLAN traffic in multicast path Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 075/108] Revert "mac80211: Dynamically set CoDel parameters per station" Sasha Levin
2025-06-04  0:54 ` [PATCH AUTOSEL 6.14 076/108] wifi: iwlwifi: Add missing MODULE_FIRMWARE for Qu-c0-jf-b0 Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 077/108] net: bridge: mcast: update multicast contex when vlan state is changed Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 078/108] net: bridge: mcast: re-implement br_multicast_{enable, disable}_port functions Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 079/108] vxlan: Do not treat dst cache initialization errors as fatal Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 080/108] bnxt_en: Remove unused field "ref_count" in struct bnxt_ulp Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 081/108] vxlan: Add RCU read-side critical sections in the Tx path Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 082/108] wifi: ath12k: correctly handle mcast packets for clients Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 083/108] wifi: ath12k: using msdu end descriptor to check for rx multicast packets Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 084/108] net: ethernet: ti: am65-cpsw: handle -EPROBE_DEFER Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 085/108] software node: Correct a OOB check in software_node_get_reference_args() Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 086/108] wifi: ath12k: make assoc link associate first Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 087/108] isofs: fix Y2038 and Y2156 issues in Rock Ridge TF entry Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 088/108] pinctrl: mcp23s08: Reset all pins to input at probe Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 089/108] wifi: ath12k: fix failed to set mhi state error during reboot with hardware grouping Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 090/108] scsi: lpfc: Use memcpy() for BIOS version Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 091/108] sock: Correct error checking condition for (assign|release)_proto_idx() Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 092/108] i40e: fix MMIO write access to an invalid page in i40e_clear_hw Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 093/108] ixgbe: Fix unreachable retry logic in combined and byte I2C write functions Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 094/108] RDMA/hns: initialize db in update_srq_db() Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 095/108] ice: fix check for existing switch rule Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 096/108] usbnet: asix AX88772: leave the carrier control to phylink Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 097/108] f2fs: fix to set atomic write status more clear Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 098/108] bpf, sockmap: Fix data lost during EAGAIN retries Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 099/108] net: ethernet: cortina: Use TOE/TSO on all TCP Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 100/108] octeontx2-pf: Add error log forcn10k_map_unmap_rq_policer() Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 101/108] wifi: ath12k: Fix incorrect rates sent to firmware Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 102/108] wifi: ath12k: Fix the enabling of REO queue lookup table feature Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 103/108] wifi: ath12k: Fix memory leak due to multiple rx_stats allocation Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 104/108] wifi: ath11k: determine PM policy based on machine model Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 105/108] wifi: ath12k: fix link valid field initialization in the monitor Rx Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 106/108] wifi: ath12k: fix incorrect CE addresses Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 107/108] wifi: ath12k: Pass correct values of center freq1 and center freq2 for 160 MHz Sasha Levin
2025-06-04  0:55 ` [PATCH AUTOSEL 6.14 108/108] net/mlx5: HWS, Harden IP version definer checks Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250604005531.4178547-20-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox