From: Thomas Weißschuh thomas.weissschuh@linutronix.de
[ Upstream commit 66ceb45b7d7e9673254116eefe5b6d3a44eba267 ]
In the past %pK was preferable to %p as it would not leak raw pointer values into the kernel log. Since commit ad67b74d2469 ("printk: hash addresses printed with %p") the regular %p has been improved to avoid this issue. Furthermore, restricted pointers ("%pK") were never meant to be used through printk(). They can still unintentionally leak raw pointers or acquire sleeping locks in atomic contexts.
Switch to the regular pointer formatting which is safer and easier to reason about. There are still a few users of %pK left, but these use it through seq_file, for which its usage is safe.
Signed-off-by: Thomas Weißschuh thomas.weissschuh@linutronix.de Acked-by: Przemek Kitszel przemyslaw.kitszel@intel.com Reviewed-by: Aleksandr Loktionov aleksandr.loktionov@intel.com Reviewed-by: Simon Horman horms@kernel.org Reviewed-by: Paul Menzel pmenzel@molgen.mpg.de Reviewed-by: Jacob Keller jacob.e.keller@intel.com Link: https://patch.msgid.link/20250811-restricted-pointers-net-v5-1-2e2fdc7d3f2c@... Signed-off-by: Jakub Kicinski kuba@kernel.org Signed-off-by: Sasha Levin sashal@kernel.org ---
LLM Generated explanations, may be completely bogus:
YES
- What changes: The patch replaces %pK with %p in a single debug printk and several tracepoint TP_printk format strings: - drivers/net/ethernet/intel/ice/ice_main.c:9112 - drivers/net/ethernet/intel/ice/ice_trace.h:133, 161, 185, 208, 231
- Why it matters: - %p hashing is safe since v4.15: Commit ad67b74d2469 (“printk: hash addresses printed with %p”) ensures %p prints hashed addresses by default, avoiding raw pointer leaks. - See lib/vsprintf.c:837-848 for the %p default hashing path. - %pK is problematic in printk/tracepoints: - In IRQ/softirq/NMI when kptr_restrict==1 (a common distro hardening default), %pK deliberately refuses to operate and emits “pK-error” instead of a pointer, degrading trace readability and consistency in hot paths like TX/RX cleanups. - See lib/vsprintf.c:850 (kptr_restrict) and lib/vsprintf.c:864-871 (IRQ/softirq/NMI path to “pK-error”). - The restricted-pointer policy was never intended for printk/tracepoints; using %pK can also involve capability/cred checks that are inappropriate in atomic contexts. - ice tracepoints are often hit from NAPI/IRQ context. The current %pK usage in: - ice_trace.h:133, 161, 185, 208, 231 (ring/desc/buf/skb pointers) can produce “pK-error” under kptr_restrict==1 instead of hashed values, while %p provides consistent, safe hashed output. - The dev_dbg change in drivers/net/ethernet/intel/ice/ice_main.c:9112 similarly aligns with the policy of avoiding %pK in printk; %p remains non-leaky (hashed).
- Risk assessment: - Minimal and contained: only format strings change; no functional logic, state, or ABI changes to tracepoint fields (the field layout defined by __field/__string is unchanged; only TP_printk’s human- readable text changes). - No cross-subsystem dependencies or architectural impact. - Improves safety/observability without adding new features.
- Precedent in stable: Multiple similar “Don’t use %pK through printk” patches have already been accepted into stable trees, citing the same rationale: - bpf: b2131336289fa - timer_list: 3fb9ee05ec15f - spi loopback-test: e0bdc3d17b388 Each includes a Sasha Levin Signed-off-by indicating stable backporting.
- Stable policy fit: - Fixes a real issue for users who rely on trace readability under hardened kptr_restrict settings and removes a misuse of %pK in printk/tracepoints. - Small, self-contained, low regression risk, no new features, confined to a driver.
- Compatibility note: All maintained LTS series (>= v4.19) already include %p hashing from v4.15, so this change is safe across active stable kernels.
Conclusion: Backporting this patch improves correctness and safety of diagnostic output in the ice driver with negligible risk and clear precedent.
drivers/net/ethernet/intel/ice/ice_main.c | 2 +- drivers/net/ethernet/intel/ice/ice_trace.h | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c index 77781277aa8e4..92b95d92d5992 100644 --- a/drivers/net/ethernet/intel/ice/ice_main.c +++ b/drivers/net/ethernet/intel/ice/ice_main.c @@ -9125,7 +9125,7 @@ static int ice_create_q_channels(struct ice_vsi *vsi) list_add_tail(&ch->list, &vsi->ch_list); vsi->tc_map_vsi[i] = ch->ch_vsi; dev_dbg(ice_pf_to_dev(pf), - "successfully created channel: VSI %pK\n", ch->ch_vsi); + "successfully created channel: VSI %p\n", ch->ch_vsi); } return 0;
diff --git a/drivers/net/ethernet/intel/ice/ice_trace.h b/drivers/net/ethernet/intel/ice/ice_trace.h index 07aab6e130cd5..4f35ef8d6b299 100644 --- a/drivers/net/ethernet/intel/ice/ice_trace.h +++ b/drivers/net/ethernet/intel/ice/ice_trace.h @@ -130,7 +130,7 @@ DECLARE_EVENT_CLASS(ice_tx_template, __entry->buf = buf; __assign_str(devname);),
- TP_printk("netdev: %s ring: %pK desc: %pK buf %pK", __get_str(devname), + TP_printk("netdev: %s ring: %p desc: %p buf %p", __get_str(devname), __entry->ring, __entry->desc, __entry->buf) );
@@ -158,7 +158,7 @@ DECLARE_EVENT_CLASS(ice_rx_template, __entry->desc = desc; __assign_str(devname);),
- TP_printk("netdev: %s ring: %pK desc: %pK", __get_str(devname), + TP_printk("netdev: %s ring: %p desc: %p", __get_str(devname), __entry->ring, __entry->desc) ); DEFINE_EVENT(ice_rx_template, ice_clean_rx_irq, @@ -182,7 +182,7 @@ DECLARE_EVENT_CLASS(ice_rx_indicate_template, __entry->skb = skb; __assign_str(devname);),
- TP_printk("netdev: %s ring: %pK desc: %pK skb %pK", __get_str(devname), + TP_printk("netdev: %s ring: %p desc: %p skb %p", __get_str(devname), __entry->ring, __entry->desc, __entry->skb) );
@@ -205,7 +205,7 @@ DECLARE_EVENT_CLASS(ice_xmit_template, __entry->skb = skb; __assign_str(devname);),
- TP_printk("netdev: %s skb: %pK ring: %pK", __get_str(devname), + TP_printk("netdev: %s skb: %p ring: %p", __get_str(devname), __entry->skb, __entry->ring) );
@@ -228,7 +228,7 @@ DECLARE_EVENT_CLASS(ice_tx_tstamp_template, TP_fast_assign(__entry->skb = skb; __entry->idx = idx;),
- TP_printk("skb %pK idx %d", + TP_printk("skb %p idx %d", __entry->skb, __entry->idx) ); #define DEFINE_TX_TSTAMP_OP_EVENT(name) \