libertas: potential race condition
Subsystems (3)
Hi!
There is a potential race condition in drivers/net/wireless/libertas/libertas.ko.
In the function lbs_hard_start_xmit(..), line 159, a socket buffer is written to priv->current_skb with a spin_lock protection.
In the function lbs_mac_event_disconnected(..), lines 50-51, the field current_skb is cleaned. There is no protection used. The corresponding handlers are activated at the same time in lbs_start_card(..) and then may be executed simultaneously. Note, there are two structures lbs_netdev_ops and mesh_netdev_ops, which have the target handler lbs_hard_start_xmit. Is it a real race or I have missed something?
Signature · 4 lines
Pavel Andrianov Linux Verification Center, ISPRAS web: http://linuxtesting.org e-mail: [email protected]
Quoted 17 lines · Pavel Andrianov
Hi!
There is a potential race condition in
drivers/net/wireless/libertas/libertas.ko.
In the functionlbs_hard_start_xmit(..), line 159, a socket buffer is
written topriv->current_skbwith aspin_lockprotection. In the functionlbs_mac_event_disconnected(..), lines 50-51, the fieldcurrent_skbis cleaned. There is no protection used. The corresponding
handlers are activated at the same time inlbs_start_card(..)and then
may be executed simultaneously. Note, there are two structureslbs_netdev_opsandmesh_netdev_ops, which have the target handlerlbs_hard_start_xmit.
Is it a real race or I have missed something?
Yeah, it looks like it should be grabbing priv->driver_lock before clearing priv->currenttxskb in lbs_mac_event_disconnected(). Care to submit a patch after testing? Do you have any of that hardware?
Dan
07.06.2016 18:39, Dan Williams пишет:
Quoted 18 lines · Pavel Andrianov
Quoted 17 lines
Hi!
There is a potential race condition in
drivers/net/wireless/libertas/libertas.ko.
In the functionlbs_hard_start_xmit(..), line 159, a socket buffer is
written topriv->current_skbwith aspin_lockprotection. In the functionlbs_mac_event_disconnected(..), lines 50-51, the fieldcurrent_skbis cleaned. There is no protection used. The corresponding
handlers are activated at the same time inlbs_start_card(..)and then
may be executed simultaneously. Note, there are two structureslbs_netdev_opsandmesh_netdev_ops, which have the target handlerlbs_hard_start_xmit.
Is it a real race or I have missed something?
Quoted 5 lines
Yeah, it looks like it should be grabbing
priv->driver_lockbefore clearingpriv->currenttxskbinlbs_mac_event_disconnected(). Care to submit a patch after testing? Do you have any of that hardware?Dan
I have no that hardware and I have some doubts about the simple fix, you've suggested. For instance, in lbs_hard_start_xmit the lock is acquired twice and the priv->tx_pending_len can be modified also by lbs_mac_event_disconnected (even if spin_lock will be added to lbs_mac_event_disconnected). Moreover, the function lbs_send_tx_feedback also cleaned priv->currenttxskb, but it happens also without any protection. Thus, the fix has to be more complicated, and I have no ideas about it.
Signature · 9 lines
Pavel Andrianov Linux Verification Center, ISPRAS web: http://linuxtesting.org e-mail: [email protected] -- To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 19 lines · Dan Williams
Quoted 17 lines · Pavel Andrianov
Hi!
There is a potential race condition in
drivers/net/wireless/libertas/libertas.ko.
In the functionlbs_hard_start_xmit(..), line 159, a socket buffer is
written topriv->current_skbwith aspin_lockprotection. In the functionlbs_mac_event_disconnected(..), lines 50-51, the fieldcurrent_skbis cleaned. There is no protection used. The corresponding
handlers are activated at the same time inlbs_start_card(..)and then
may be executed simultaneously. Note, there are two structureslbs_netdev_opsandmesh_netdev_ops, which have the target handlerlbs_hard_start_xmit.
Is it a real race or I have missed something?
Quoted 3 lines
Yeah, it looks like it should be grabbing
priv->driver_lockbefore clearingpriv->currenttxskbin lbs_mac_event_disconnected(). Care to submit a patch after testing? Do you have any of that hardware?
I've hardware, with serial console.
Can test any patch, on USB (8388) or SDIO (8686).
Signature · 2 lines
James Cameron http://quozl.netrek.org/
08.06.2016 02:51, James Cameron пишет:
Quoted 19 lines · Dan Williams
Quoted 18 lines · Pavel Andrianov
Quoted 17 lines
Hi!
There is a potential race condition in
drivers/net/wireless/libertas/libertas.ko.
In the functionlbs_hard_start_xmit(..), line 159, a socket buffer is
written topriv->current_skbwith aspin_lockprotection. In the functionlbs_mac_event_disconnected(..), lines 50-51, the fieldcurrent_skbis cleaned. There is no protection used. The corresponding
handlers are activated at the same time inlbs_start_card(..)and then
may be executed simultaneously. Note, there are two structureslbs_netdev_opsandmesh_netdev_ops, which have the target handlerlbs_hard_start_xmit.
Is it a real race or I have missed something?
Quoted 7 lines
Quoted 3 lines
Yeah, it looks like it should be grabbing
priv->driver_lockbefore clearingpriv->currenttxskbinlbs_mac_event_disconnected(). Care to submit a patch after testing? Do you have any of that hardware?I've hardware, with serial console.
Can test any patch, on USB (8388) or SDIO (8686).
Hi!
I've prepare the patch for this issue. Could you test it?
Thank you.
Signature · 4 lines
Pavel Andrianov Linux Verification Center, ISPRAS web: http://linuxtesting.org e-mail: [email protected]
Quoted 1 line
From
b1a9e157ccdf8650da93844fd2dbdb6fca509b59Mon Sep 17 00:00:00 2001
From: Pavel <[email protected]>
Date: Tue, 14 Jun 2016 16:59:00 +0400
Subject: [PATCH] libertas: Add spinlock to avoid race condition
lbs_mac_event_disconnected may free priv->currenttxskb while lbs_hard_start_xmit accesses to it.
The patch adds a spinlock for mutual exclusion.
--- drivers/net/wireless/marvell/libertas/cmdresp.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/wireless/marvell/libertas/cmdresp.c +4 -0
@@ -27,6 +27,8 @@void lbs_mac_event_disconnected (struct lbs_private *priv,bool locally_generated) { +unsigned long flags; +if (priv->connect_status !=LBS_CONNECTED )return ;
@@ -46,9 +48,11 @@ void lbs_mac_event_disconnected(struct lbs_private *priv,netif_carrier_off (priv->dev);/* Free Tx and Rx packets */ +spin_lock_irqsave (&priv->driver_lock, flags);kfree_skb (priv->currenttxskb); priv->currenttxskb =NULL ; priv->tx_pending_len =0 ; +spin_unlock_irqrestore (&priv->driver_lock, flags); priv->connect_status =LBS_DISCONNECTED ;
Signature · 1 line
1.7.11.7
James Cameron
Tested-byQuoted 25 lines · Pavel Andrianov
08.06.2016 02:51, James Cameron пишет:
Quoted 24 lines · Dan Williams
Quoted 18 lines · Pavel Andrianov
Quoted 17 lines
Hi!
There is a potential race condition in
drivers/net/wireless/libertas/libertas.ko.
In the functionlbs_hard_start_xmit(..), line 159, a socket buffer is
written topriv->current_skbwith aspin_lockprotection. In the functionlbs_mac_event_disconnected(..), lines 50-51, the fieldcurrent_skbis cleaned. There is no protection used. The corresponding
handlers are activated at the same time inlbs_start_card(..)and then
may be executed simultaneously. Note, there are two structureslbs_netdev_opsandmesh_netdev_ops, which have the target handlerlbs_hard_start_xmit.
Is it a real race or I have missed something?Quoted 3 lines
Yeah, it looks like it should be grabbing
priv->driver_lockbefore clearingpriv->currenttxskbinlbs_mac_event_disconnected(). Care to submit a patch after testing? Do you have any of that hardware?I've hardware, with serial console.
Quoted 7 lines
Quoted 2 lines
Can test any patch, on USB (8388) or SDIO (8686).
Hi!
I've prepare the patch for this issue. Could you test it?
Thank you.
Tested on OLPC XO-1 (usb8388) and XO-1.5 (sd8686) with v4.7-rc3.
Confirmed that lbs_mac_event_disconnected is being called on the station when hostapd on access point is given SIGHUP.
Longer duration test was;
- SSH to station and run "top -d 0.2",
- send SIGHUP every six seconds, for 300 cycles,
You may add my;
Signature · 2 lines
James Cameron http://quozl.netrek.org/