dpll: fix NULL deref in dpll_device_ops() during teardown race
Subsystems (3)
PATCH v2 1/1 dpll: fix NULL deref in dpll_device_ops() during teardown race
When the last owner of a dpll device unregisters while a foreign driver still holds a pin on it via dpll_pin_on_pin_register(), the dpll object stays alive with an empty registration list. A pin notification queued before the unregister (e.g. ice reacting to zl3073x_i2c removal) then walks pin->dpll_refs into dpll_device_ops(), which trips the WARN_ON and dereferences the missing registration. dpll_lock cannot help because the notification work was queued before the unregistering driver took the lock.
Treat the empty registration list as a legitimate transient state. Make dpll_priv() and dpll_device_ops() return NULL in that case and make every pin netlink path that resolves a device from a pin skip such dplls. dpll_cmd_pin_get_one() picks a ref with a live registration and returns -ENODEV when there is none, the pin dumpit skips such a pin instead of aborting the dump, dpll_msg_add_pin_dplls() and the frequency, esync, reference sync and phase adjust set paths skip dead refs, and dpll_pin_parent_device_set() validates the parent with dpll_device_get_by_id(). dpll_pin_register() is the last caller that dereferenced the device ops without a check, so move its frequency monitor validation under dpll_lock and tolerate a missing registration there as well.
The empty registration list is equivalent to a cleared DPLL_REGISTERED mark, both transitions happen under dpll_lock in dpll_device_register() and dpll_device_unregister(). A pin notification for a pin whose dplls are all gone is now dropped with -ENODEV instead of crashing, all callers in the core ignore that return value.
WARNING: drivers/dpll/dpll_core.c:1092 at dpll_device_ops+0x24/0x40, CPU#83: kworker/u576:3/23471 Modules linked in: ... ice ... zl3073x_i2c(-) ... zl3073x ... Workqueue: ice_dpll_wq ice_dpll_pin_notify_work [ice] RIP: 0010:dpll_device_ops+0x24/0x40 Call Trace: <TASK> dpll_cmd_pin_get_one+0x336/0x520 dpll_pin_event_send+0x82/0x140 dpll_pin_on_pin_unregister+0xbb/0x160 ice_dpll_pin_notify_work+0x1bc/0x1f0 [ice] process_one_work+0x19e/0x370 worker_thread+0x1a6/0x310 kthread+0xe4/0x120 ret_from_fork+0x1a1/0x270 ret_from_fork_asm+0x1a/0x30 </TASK> ---[ end trace 0000000000000000 ]--- BUG: kernel NULL pointer dereference, address: 0000000000000010 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page
---
v2:
- guard every path that resolves a device from a pin, not only the first ref in dpll_cmd_pin_get_one(); skip half-dead refs in dpll_msg_add_pin_dplls() and the set paths, select a live representative ref and turn the pin dumpit -ENODEV into a per pin skip (Jakub)
- validate the parent device in dpll_pin_parent_device_set() via dpll_device_get_by_id()
- guard the frequency monitor validation in dpll_pin_register() and perform it under dpll_lock, it was the only remaining unchecked dereference of the device ops
- drop patch 2/2, superseded by commit 32239d600236 ("dpll: fix stale iteration in dpll_pin_on_pin_unregister()")
v1: https://lore.kernel.org/all/[email protected]/
--- drivers/dpll/dpll_core.c | 24 +++++++++------ drivers/dpll/dpll_netlink.c | 59 ++++++++++++++++++++++++++++++++----- 2 files changed, 67 insertions(+), 16 deletions(-)
drivers/dpll/dpll_core.c +15 -9
@@ -876,19 +876,25 @@ int dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin, const struct dpll_pin_ops *ops, void *priv) { + const struct dpll_device_ops *dev_ops;int ret;if (WARN_ON (!ops) ||WARN_ON (!ops->state_on_dpll_get) ||WARN_ON (!ops->direction_get) || -WARN_ON (ops->measured_freq_get && - (!dpll_device_ops (dpll)->freq_monitor_get || - !dpll_device_ops (dpll)->freq_monitor_set)) ||WARN_ON (ops->supported_ffo && !ops->ffo_get))return -EINVAL ;mutex_lock (&dpll_lock); + dev_ops =dpll_device_ops (dpll); +if (WARN_ON (ops->measured_freq_get && + (!dev_ops || !dev_ops->freq_monitor_get || + !dev_ops->freq_monitor_set))) { + ret = -EINVAL ; + goto out_unlock; + } +/* * For pins identified via firmware (pin->fwnode), allow registration * even if the pin's (module, clock_id) differs from the target DPLL.
@@ -1081,12 +1087,8 @@ EXPORT_SYMBOL_GPL(dpll_pin_ref_sync_pair_add);static struct dpll_device_registration *dpll_device_registration_first (struct dpll_device *dpll) { -struct dpll_device_registration *reg; - - reg =list_first_entry_or_null ((struct list_head *)&dpll->registration_list, - struct dpll_device_registration, list); -WARN_ON (!reg); -return reg; +return list_first_entry_or_null ((struct list_head *)&dpll->registration_list, + struct dpll_device_registration, list); }void *dpll_priv (struct dpll_device *dpll)
@@ -1094,6 +1096,8 @@ void *dpll_priv(struct dpll_device *dpll)struct dpll_device_registration *reg; reg =dpll_device_registration_first (dpll); +if (!reg) +return NULL ;return reg->priv; }
@@ -1102,6 +1106,8 @@ const struct dpll_device_ops *dpll_device_ops(struct dpll_device *dpll)struct dpll_device_registration *reg; reg =dpll_device_registration_first (dpll); +if (!reg) +return NULL ;return reg->ops; }
drivers/dpll/dpll_netlink.c +52 -7
180 lines not on this page · raw message
Signature · 1 line
2.54.0
Quoted 67 lines · Petr Oros
When the last owner of a dpll device unregisters while a foreign driver still holds a pin on it via
dpll_pin_on_pin_register(), the dpll object stays alive with an empty registration list. A pin notification queued before the unregister (e.g. ice reacting tozl3073x_i2cremoval) then walkspin->dpll_refsintodpll_device_ops(), which trips theWARN_ONand dereferences the missing registration.dpll_lockcannot help because the notification work was queued before the unregistering driver took the lock.Treat the empty registration list as a legitimate transient state. Make
dpll_priv()anddpll_device_ops()return NULL in that case and make every pin netlink path that resolves a device from a pin skip such dplls.dpll_cmd_pin_get_one()picks a ref with a live registration and returns-ENODEVwhen there is none, the pin dumpit skips such a pin instead of aborting the dump,dpll_msg_add_pin_dplls()and the frequency, esync, reference sync and phase adjust set paths skip dead refs, anddpll_pin_parent_device_set()validates the parent withdpll_device_get_by_id().dpll_pin_register()is the last caller that dereferenced the device ops without a check, so move its frequency monitor validation underdpll_lockand tolerate a missing registration there as well.The empty registration list is equivalent to a cleared
DPLL_REGISTEREDmark, both transitions happen underdpll_lockindpll_device_register()anddpll_device_unregister(). A pin notification for a pin whose dplls are all gone is now dropped with-ENODEVinstead of crashing, all callers in the core ignore that return value.WARNING: drivers/dpll/dpll_core.c:1092 at dpll_device_ops+0x24/0x40, CPU#83: kworker/u576:3/23471 Modules linked in: ... ice ... zl3073x_i2c(-) ... zl3073x ... Workqueue: ice_dpll_wq ice_dpll_pin_notify_work [ice] RIP: 0010:dpll_device_ops+0x24/0x40 Call Trace: <TASK> dpll_cmd_pin_get_one+0x336/0x520 dpll_pin_event_send+0x82/0x140 dpll_pin_on_pin_unregister+0xbb/0x160 ice_dpll_pin_notify_work+0x1bc/0x1f0 [ice] process_one_work+0x19e/0x370 worker_thread+0x1a6/0x310 kthread+0xe4/0x120 ret_from_fork+0x1a1/0x270 ret_from_fork_asm+0x1a/0x30 </TASK> ---[ end trace 0000000000000000 ]--- BUG: kernel NULL pointer dereference, address: 0000000000000010 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present pageFixes 9431063ad323 ("dpll: core: Add DPLL framework base functions")Signed-off-by Petr Oros <[email protected]>---
v2:
- guard every path that resolves a device from a pin, not only the first ref indpll_cmd_pin_get_one(); skip half-dead refs indpll_msg_add_pin_dplls()and the set paths, select a live representative ref and turn the pin dumpit-ENODEVinto a per pin skip (Jakub)
- validate the parent device indpll_pin_parent_device_set()viadpll_device_get_by_id()
- guard the frequency monitor validation indpll_pin_register()and perform it underdpll_lock, it was the only remaining unchecked dereference of the device ops
- drop patch 2/2, superseded by commit32239d600236("dpll: fix stale iteration indpll_pin_on_pin_unregister()")
Quoted 5 lines
v1: https://lore.kernel.org/all/[email protected]/
--- drivers/dpll/dpll_core.c | 24 +++++++++------ drivers/dpll/dpll_netlink.c | 59 ++++++++++++++++++++++++++++++++----- 2 files changed, 67 insertions(+), 16 deletions(-)
Tested on both branches net and net-next (after adjustment).
Quoted 67 lines · Petr Oros
When the last owner of a dpll device unregisters while a foreign driver still holds a pin on it via
dpll_pin_on_pin_register(), the dpll object stays alive with an empty registration list. A pin notification queued before the unregister (e.g. ice reacting tozl3073x_i2cremoval) then walkspin->dpll_refsintodpll_device_ops(), which trips theWARN_ONand dereferences the missing registration.dpll_lockcannot help because the notification work was queued before the unregistering driver took the lock.Treat the empty registration list as a legitimate transient state. Make
dpll_priv()anddpll_device_ops()return NULL in that case and make every pin netlink path that resolves a device from a pin skip such dplls.dpll_cmd_pin_get_one()picks a ref with a live registration and returns-ENODEVwhen there is none, the pin dumpit skips such a pin instead of aborting the dump,dpll_msg_add_pin_dplls()and the frequency, esync, reference sync and phase adjust set paths skip dead refs, anddpll_pin_parent_device_set()validates the parent withdpll_device_get_by_id().dpll_pin_register()is the last caller that dereferenced the device ops without a check, so move its frequency monitor validation underdpll_lockand tolerate a missing registration there as well.The empty registration list is equivalent to a cleared
DPLL_REGISTEREDmark, both transitions happen underdpll_lockindpll_device_register()anddpll_device_unregister(). A pin notification for a pin whose dplls are all gone is now dropped with-ENODEVinstead of crashing, all callers in the core ignore that return value.WARNING: drivers/dpll/dpll_core.c:1092 at dpll_device_ops+0x24/0x40, CPU#83: kworker/u576:3/23471 Modules linked in: ... ice ... zl3073x_i2c(-) ... zl3073x ... Workqueue: ice_dpll_wq ice_dpll_pin_notify_work [ice] RIP: 0010:dpll_device_ops+0x24/0x40 Call Trace: <TASK> dpll_cmd_pin_get_one+0x336/0x520 dpll_pin_event_send+0x82/0x140 dpll_pin_on_pin_unregister+0xbb/0x160 ice_dpll_pin_notify_work+0x1bc/0x1f0 [ice] process_one_work+0x19e/0x370 worker_thread+0x1a6/0x310 kthread+0xe4/0x120 ret_from_fork+0x1a1/0x270 ret_from_fork_asm+0x1a/0x30 </TASK> ---[ end trace 0000000000000000 ]--- BUG: kernel NULL pointer dereference, address: 0000000000000010 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present pageFixes 9431063ad323 ("dpll: core: Add DPLL framework base functions")Signed-off-by Petr Oros <[email protected]>---
v2:
- guard every path that resolves a device from a pin, not only the first ref indpll_cmd_pin_get_one(); skip half-dead refs indpll_msg_add_pin_dplls()and the set paths, select a live representative ref and turn the pin dumpit-ENODEVinto a per pin skip (Jakub)
- validate the parent device indpll_pin_parent_device_set()viadpll_device_get_by_id()
- guard the frequency monitor validation indpll_pin_register()and perform it underdpll_lock, it was the only remaining unchecked dereference of the device ops
- drop patch 2/2, superseded by commit32239d600236("dpll: fix stale iteration indpll_pin_on_pin_unregister()")
Quoted 6 lines
v1: https://lore.kernel.org/all/[email protected]/
--- drivers/dpll/dpll_core.c | 24 +++++++++------ drivers/dpll/dpll_netlink.c | 59 ++++++++++++++++++++++++++++++++----- 2 files changed, 67 insertions(+), 16 deletions(-)
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Thu, 13 Aug 2026 16:08:17 +0200 you wrote:
When the last owner of a dpll device unregisters while a foreign driver still holds a pin on it via
dpll_pin_on_pin_register(), the dpll object stays alive with an empty registration list. A pin notification queued before the unregister (e.g. ice reacting tozl3073x_i2cremoval) then walkspin->dpll_refsintodpll_device_ops(), which trips theWARN_ONand dereferences the missing registration.dpll_lockcannot help because the notification work was queued before the unregistering driver took the lock.[...]
Here is the summary with links:
- [net,v2] dpll: fix NULL deref in dpll_device_ops() during teardown race
https://git.kernel.org/netdev/net/c/33f016b23a21
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Hi Petr,
Quoted 22 lines · Petr Oros
When the last owner of a dpll device unregisters while a foreign driver still holds a pin on it via
dpll_pin_on_pin_register(), the dpll object stays alive with an empty registration list. A pin notification queued before the unregister (e.g. ice reacting tozl3073x_i2cremoval) then walkspin->dpll_refsintodpll_device_ops(), which trips theWARN_ONand dereferences the missing registration.dpll_lockcannot help because the notification work was queued before the unregistering driver took the lock.Treat the empty registration list as a legitimate transient state. Make
dpll_priv()anddpll_device_ops()return NULL in that case and make every pin netlink path that resolves a device from a pin skip such dplls.dpll_cmd_pin_get_one()picks a ref with a live registration and returns-ENODEVwhen there is none, the pin dumpit skips such a pin instead of aborting the dump,dpll_msg_add_pin_dplls()and the frequency, esync, reference sync and phase adjust set paths skip dead refs, anddpll_pin_parent_device_set()validates the parent withdpll_device_get_by_id().dpll_pin_register()is the last caller that dereferenced the device ops without a check, so move its frequency monitor validation underdpll_lockand tolerate a missing registration there as well.
Quoted 5 lines
The empty registration list is equivalent to a cleared
DPLL_REGISTEREDmark, both transitions happen underdpll_lockindpll_device_register()anddpll_device_unregister(). A pin notification for a pin whose dplls are all gone is now dropped with-ENODEVinstead of crashing, all callers in the core ignore that return value.
Thank you for the patch. When merging net into net-next, it looks like it creates a lot of conflicts, mainly with commit 84e85c325e5e ("dpll:
use pin owner's dpll ref for pin-level attribute setting").
Because the logic seems quite different now, do you mind providing instructions on how to resolve these conflicts, please? A 3-way patch and/or rerere artifacts could also help.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.