mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-07 02:19:54 +00:00
net: sch_generic: aviod concurrent reset and enqueue op for lockless qdisc
[ Upstream commit2fb541c862] Currently there is concurrent reset and enqueue operation for the same lockless qdisc when there is no lock to synchronize the q->enqueue() in __dev_xmit_skb() with the qdisc reset operation in qdisc_deactivate() called by dev_deactivate_queue(), which may cause out-of-bounds access for priv->ring[] in hns3 driver if user has requested a smaller queue num when __dev_xmit_skb() still enqueue a skb with a larger queue_mapping after the corresponding qdisc is reset, and call hns3_nic_net_xmit() with that skb later. Reused the existing synchronize_net() in dev_deactivate_many() to make sure skb with larger queue_mapping enqueued to old qdisc(which is saved in dev_queue->qdisc_sleeping) will always be reset when dev_reset_queue() is called. Fixes:6b3ba9146f("net: sched: allow qdiscs to handle locking") Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
fe91654256
commit
749cc0b0c7
@@ -1115,29 +1115,38 @@ static void dev_deactivate_queue(struct net_device *dev,
|
|||||||
struct netdev_queue *dev_queue,
|
struct netdev_queue *dev_queue,
|
||||||
void *_qdisc_default)
|
void *_qdisc_default)
|
||||||
{
|
{
|
||||||
struct Qdisc *qdisc_default = _qdisc_default;
|
struct Qdisc *qdisc = rtnl_dereference(dev_queue->qdisc);
|
||||||
struct Qdisc *qdisc;
|
|
||||||
|
|
||||||
qdisc = rtnl_dereference(dev_queue->qdisc);
|
|
||||||
if (qdisc) {
|
if (qdisc) {
|
||||||
bool nolock = qdisc->flags & TCQ_F_NOLOCK;
|
|
||||||
|
|
||||||
if (nolock)
|
|
||||||
spin_lock_bh(&qdisc->seqlock);
|
|
||||||
spin_lock_bh(qdisc_lock(qdisc));
|
|
||||||
|
|
||||||
if (!(qdisc->flags & TCQ_F_BUILTIN))
|
if (!(qdisc->flags & TCQ_F_BUILTIN))
|
||||||
set_bit(__QDISC_STATE_DEACTIVATED, &qdisc->state);
|
set_bit(__QDISC_STATE_DEACTIVATED, &qdisc->state);
|
||||||
|
|
||||||
rcu_assign_pointer(dev_queue->qdisc, qdisc_default);
|
|
||||||
qdisc_reset(qdisc);
|
|
||||||
|
|
||||||
spin_unlock_bh(qdisc_lock(qdisc));
|
|
||||||
if (nolock)
|
|
||||||
spin_unlock_bh(&qdisc->seqlock);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void dev_reset_queue(struct net_device *dev,
|
||||||
|
struct netdev_queue *dev_queue,
|
||||||
|
void *_unused)
|
||||||
|
{
|
||||||
|
struct Qdisc *qdisc;
|
||||||
|
bool nolock;
|
||||||
|
|
||||||
|
qdisc = dev_queue->qdisc_sleeping;
|
||||||
|
if (!qdisc)
|
||||||
|
return;
|
||||||
|
|
||||||
|
nolock = qdisc->flags & TCQ_F_NOLOCK;
|
||||||
|
|
||||||
|
if (nolock)
|
||||||
|
spin_lock_bh(&qdisc->seqlock);
|
||||||
|
spin_lock_bh(qdisc_lock(qdisc));
|
||||||
|
|
||||||
|
qdisc_reset(qdisc);
|
||||||
|
|
||||||
|
spin_unlock_bh(qdisc_lock(qdisc));
|
||||||
|
if (nolock)
|
||||||
|
spin_unlock_bh(&qdisc->seqlock);
|
||||||
|
}
|
||||||
|
|
||||||
static bool some_qdisc_is_busy(struct net_device *dev)
|
static bool some_qdisc_is_busy(struct net_device *dev)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
@@ -1196,12 +1205,20 @@ void dev_deactivate_many(struct list_head *head)
|
|||||||
dev_watchdog_down(dev);
|
dev_watchdog_down(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for outstanding qdisc-less dev_queue_xmit calls.
|
/* Wait for outstanding qdisc-less dev_queue_xmit calls or
|
||||||
|
* outstanding qdisc enqueuing calls.
|
||||||
* This is avoided if all devices are in dismantle phase :
|
* This is avoided if all devices are in dismantle phase :
|
||||||
* Caller will call synchronize_net() for us
|
* Caller will call synchronize_net() for us
|
||||||
*/
|
*/
|
||||||
synchronize_net();
|
synchronize_net();
|
||||||
|
|
||||||
|
list_for_each_entry(dev, head, close_list) {
|
||||||
|
netdev_for_each_tx_queue(dev, dev_reset_queue, NULL);
|
||||||
|
|
||||||
|
if (dev_ingress_queue(dev))
|
||||||
|
dev_reset_queue(dev, dev_ingress_queue(dev), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/* Wait for outstanding qdisc_run calls. */
|
/* Wait for outstanding qdisc_run calls. */
|
||||||
list_for_each_entry(dev, head, close_list) {
|
list_for_each_entry(dev, head, close_list) {
|
||||||
while (some_qdisc_is_busy(dev))
|
while (some_qdisc_is_busy(dev))
|
||||||
|
|||||||
Reference in New Issue
Block a user