net: hsr: prevent NULL pointer dereference in hsr_proxy_announce()
Subsystems (3)
PATCH 1/1 net: hsr: prevent NULL pointer dereference in hsr_proxy_announce()
In the function hsr_proxy_annouance() added in the previous commit 5f703ce5c981 ("net: hsr: Send supervisory frames to HSR network with ProxyNodeTable data"), the return value of the hsr_port_get_hsr() function is not checked to be a NULL pointer, which causes a NULL pointer dereference.
To solve this, we need to add code to check whether the return value of hsr_port_get_hsr() is NULL.
--- net/hsr/hsr_device.c | 4 ++++ 1 file changed, 4 insertions(+)
net/hsr/hsr_device.c +4 -0
@@ -427,6 +427,9 @@ static void hsr_proxy_announce(struct timer_list *t)* of SAN nodes stored in ProxyNodeTable. */ interlink =hsr_port_get_hsr (hsr,HSR_PT_INTERLINK ); +if (!interlink) + goto done; +list_for_each_entry_rcu (node, &hsr->proxy_node_db, mac_list) {if (hsr_addr_is_redbox (hsr, node->macaddress_A))continue ;
@@ -441,6 +444,7 @@ static void hsr_proxy_announce(struct timer_list *t)mod_timer (&hsr->announce_proxy_timer, jiffies + interval); } +done:rcu_read_unlock (); }
--
Quoted 6 lines · Jeongjun Park
In the function
hsr_proxy_annouance()added in the previous commit5f703ce5c981("net: hsr: Send supervisory frames to HSR network with ProxyNodeTable data"), the return value of thehsr_port_get_hsr()function is not checked to be a NULL pointer, which causes a NULL pointer dereference.
Quoted 6 lines
To solve this, we need to add code to check whether the return value of
hsr_port_get_hsr()is NULL.Reported-by [email protected]Fixes 5f703ce5c981 ("net: hsr: Send supervisory frames to HSR network with ProxyNodeTable data")Signed-off-by Jeongjun Park <[email protected]>
Thanks,
I agree with your analysis; that the cited commit introduced this problem; and that this is an appropriate solution.
Hi Jeongjun,
Quoted 5 lines
In the function
hsr_proxy_annouance()added in the previous commit5f703ce5c981("net: hsr: Send supervisory frames to HSR network with ProxyNodeTable data"), the return value of thehsr_port_get_hsr()function is not checked to be a NULL pointer, which causes a NULL pointer dereference.
Thank you for your patch.
The code in hsr_proxy_announcement() is _only_ executed (the timer is configured to trigger this function) when hsr->redbox is set, which means that somebody has called earlier iproute2 command:
ip link add name hsr1 type hsr slave1 lan4 slave2 lan5 interlink lan3 supervision 45 version 1
Quoted 27 lines
To solve this, we need to add code to check whether the return value of
hsr_port_get_hsr()is NULL.Reported-by [email protected]Fixes 5f703ce5c981 ("net: hsr: Send supervisory frames to HSRnetwork with ProxyNodeTable data") Signed-off-by: Jeongjun Park <[email protected]> ---
net/hsr/hsr_device.c | 4 ++++ 1 file changed, 4 insertions(+)net/hsr/hsr_device.c +3
-0@@ -427,6 +427,9 @@ static void hsr_proxy_announce(struct timer_list*t) * of SAN nodes stored in ProxyNodeTable. */ interlink =hsr_port_get_hsr (hsr,HSR_PT_INTERLINK ); +if (!interlink) + goto done; +list_for_each_entry_rcu (node, &hsr->proxy_node_db, mac_list) {if (hsr_addr_is_redbox (hsr, node->macaddress_A))net/hsr/hsr_device.c +0
-0continue ;
net/hsr/hsr_device.c static void hsr_proxy_announce(struct timer_list
Quoted 8 lines
net/hsr/hsr_device.c +1
-1@@ -441,6 +444,7 @@ static void hsr_proxy_announce(struct timer_list *t) mod_timer(&hsr->announce_proxy_timer, jiffies + interval); } +done:rcu_read_unlock (); } --
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: [email protected]
Jakub Kicinski
maintainerQuoted 6 lines · On Mon, 9 Sep 2024 10:58:22 +0200 Lukasz Majewski wrote:
Quoted 5 lines
In the function
hsr_proxy_annouance()added in the previous commit5f703ce5c981("net: hsr: Send supervisory frames to HSR network with ProxyNodeTable data"), the return value of thehsr_port_get_hsr()function is not checked to be a NULL pointer, which causes a NULL pointer dereference.
Quoted 8 lines
Thank you for your patch.
The code in
hsr_proxy_announcement()is _only_ executed (the timer is configured to trigger this function) whenhsr->redboxis set, which means that somebody has called earlier iproute2 command:ip link add name hsr1 type hsr slave1 lan4 slave2 lan5 interlink lan3 supervision 45 version 1
Are you trying to say the patch is correct or incorrect? The structs have no refcounting - should the timers be deleted with _sync() inside hsr_check_announce()?
Lukasz Majewski
Acked-byHi Jakub,
Quoted 9 lines · On Mon, 9 Sep 2024 10:58:22 +0200 Lukasz Majewski wrote:
Quoted 8 lines
Quoted 5 lines
In the function
hsr_proxy_annouance()added in the previous commit5f703ce5c981("net: hsr: Send supervisory frames to HSR network with ProxyNodeTable data"), the return value of thehsr_port_get_hsr()function is not checked to be a NULL pointer, which causes a NULL pointer dereference.Thank you for your patch.
Quoted 8 lines
Quoted 6 lines
The code in
hsr_proxy_announcement()is _only_ executed (the timer is configured to trigger this function) whenhsr->redboxis set, which means that somebody has called earlier iproute2 command:ip link add name hsr1 type hsr slave1 lan4 slave2 lan5 interlink lan3 supervision 45 version 1
Are you trying to say the patch is correct or incorrect?
I'm just trying to explain that this code (i.e. hsr_proxy_announcement()) shall NOT be trigger if the interlink port is not configured.
Nonetheless the patch is correct - as it was pointed out that the return value is not checked.
Quoted 2 lines
The structs have no refcounting - should the timers be deleted with
_sync()insidehsr_check_announce()?
The timers don't need to be conditionally enabled (and removed) as we discussed it previously (as they only do useful work when they are configured and almost take no resources when declared during the driver probe).
Anyway:
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: [email protected]
Simon Horman
reviewer+ Edward Adam Davis, syzbot+c229849f5b6c82eba3c2
Quoted 30 lines · Lukasz Majewski
Hi Jakub,
Quoted 9 lines · On Mon, 9 Sep 2024 10:58:22 +0200 Lukasz Majewski wrote:
Quoted 8 lines
Quoted 5 lines
In the function
hsr_proxy_annouance()added in the previous commit5f703ce5c981("net: hsr: Send supervisory frames to HSR network with ProxyNodeTable data"), the return value of thehsr_port_get_hsr()function is not checked to be a NULL pointer, which causes a NULL pointer dereference.Thank you for your patch.
Quoted 8 lines
Quoted 6 lines
The code in
hsr_proxy_announcement()is _only_ executed (the timer is configured to trigger this function) whenhsr->redboxis set, which means that somebody has called earlier iproute2 command:ip link add name hsr1 type hsr slave1 lan4 slave2 lan5 interlink lan3 supervision 45 version 1
Are you trying to say the patch is correct or incorrect?
I'm just trying to explain that this code (i.e.
hsr_proxy_announcement()) shall NOT be trigger if the interlink port is not configured.Nonetheless the patch is correct - as it was pointed out that the return value is not checked.
Quoted 2 lines
The structs have no refcounting - should the timers be deleted with
_sync()insidehsr_check_announce()?
Quoted 8 lines
The timers don't need to be conditionally enabled (and removed) as we discussed it previously (as they only do useful work when they are configured and almost take no resources when declared during the driver probe).
Anyway:
Acked-by Lukasz Majewski <[email protected]>
Thanks,
Like Jakub I was a little confused about the intent of your previous comment, but it is clear now.
It seems that along the way the patch got marked as rejected, presumably on the basis of earlier discussion in this thread. But that seems inappropriate now, so let me see if this will bring it back under consideration.
pw-bot: under-review
For reference, the same change was also submitted as:
- [PATCH net] net: hsr: Fix null-ptr-deref in hsr_proxy_announce
https://lore.kernel.org/all/[email protected]/
I will attempt to somehow mark that as a duplicate in patchwork.
It also seems that there are duplicate syzbot reports for this problem [1][2] I will also attempt to mark [2] as a duplicate of [1].
[1] https://syzkaller.appspot.com/bug?extid=02a42d9b1bd395cbcab4
[2] https://syzkaller.appspot.com/bug?extid=c229849f5b6c82eba3c2
Jakub Kicinski
maintainerQuoted 7 lines · On Wed, 11 Sep 2024 10:00:07 +0200 Lukasz Majewski wrote:
Quoted 2 lines
The structs have no refcounting - should the timers be deleted with
_sync()insidehsr_check_announce()?The timers don't need to be conditionally enabled (and removed) as we discussed it previously (as they only do useful work when they are configured and almost take no resources when declared during the driver probe).
My concern is admittedly quite theoretical, and perhaps completely impossible given current RCU implementation. But what I was saying is that timer may be running, and interrupted by a very long running interrupt, say on CPU 0. Then, say, we unregister and free hsr_dev on CPU 1. When CPU 0 resumes running the timer code it will UAF on hsr_dev. Again, probably completely theoretical.
Quoted 3 lines
Anyway:
Acked-by Lukasz Majewski <[email protected]>
Thanks!
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 Sun, 8 Sep 2024 04:03:41 +0900 you wrote:
In the function
hsr_proxy_annouance()added in the previous commit5f703ce5c981("net: hsr: Send supervisory frames to HSR network with ProxyNodeTable data"), the return value of thehsr_port_get_hsr()function is not checked to be a NULL pointer, which causes a NULL pointer dereference.To solve this, we need to add code to check whether the return value of
hsr_port_get_hsr()is NULL.[...]
Here is the summary with links:
- [net] net: hsr: prevent NULL pointer dereference in hsr_proxy_announce()
https://git.kernel.org/netdev/net/c/a7789fd4caaf
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html