Commit da5a8794 authored by Patrick McHardy's avatar Patrick McHardy Committed by David S. Miller

[PKT_SCHED]: Resolve race condition with module unload in qdisc_create()

This patch resolves the race condition with module unload
in qdisc_create by moving try_module_get up to the first
qdisc_lookup_ops call.
Signed-off-by: default avatarPatrick McHardy <kaber@trash.net>
Signed-off-by: default avatarDavid S. Miller <davem@redhat.com>
parent ff1880aa
...@@ -407,6 +407,9 @@ qdisc_create(struct net_device *dev, u32 handle, struct rtattr **tca, int *errp) ...@@ -407,6 +407,9 @@ qdisc_create(struct net_device *dev, u32 handle, struct rtattr **tca, int *errp)
err = -EINVAL; err = -EINVAL;
if (ops == NULL) if (ops == NULL)
goto err_out; goto err_out;
err = -EBUSY;
if (!try_module_get(ops->owner))
goto err_out;
/* ensure that the Qdisc and the private data are 32-byte aligned */ /* ensure that the Qdisc and the private data are 32-byte aligned */
size = ((sizeof(*sch) + QDISC_ALIGN_CONST) & ~QDISC_ALIGN_CONST); size = ((sizeof(*sch) + QDISC_ALIGN_CONST) & ~QDISC_ALIGN_CONST);
...@@ -415,18 +418,12 @@ qdisc_create(struct net_device *dev, u32 handle, struct rtattr **tca, int *errp) ...@@ -415,18 +418,12 @@ qdisc_create(struct net_device *dev, u32 handle, struct rtattr **tca, int *errp)
p = kmalloc(size, GFP_KERNEL); p = kmalloc(size, GFP_KERNEL);
err = -ENOBUFS; err = -ENOBUFS;
if (!p) if (!p)
goto err_out; goto err_out2;
memset(p, 0, size); memset(p, 0, size);
sch = (struct Qdisc *)(((unsigned long)p + QDISC_ALIGN_CONST) sch = (struct Qdisc *)(((unsigned long)p + QDISC_ALIGN_CONST)
& ~QDISC_ALIGN_CONST); & ~QDISC_ALIGN_CONST);
sch->padded = (char *)sch - (char *)p; sch->padded = (char *)sch - (char *)p;
/* Grrr... Resolve race condition with module unload */
err = -EINVAL;
if (ops != qdisc_lookup_ops(kind))
goto err_out;
INIT_LIST_HEAD(&sch->list); INIT_LIST_HEAD(&sch->list);
skb_queue_head_init(&sch->q); skb_queue_head_init(&sch->q);
...@@ -444,7 +441,7 @@ qdisc_create(struct net_device *dev, u32 handle, struct rtattr **tca, int *errp) ...@@ -444,7 +441,7 @@ qdisc_create(struct net_device *dev, u32 handle, struct rtattr **tca, int *errp)
handle = qdisc_alloc_handle(dev); handle = qdisc_alloc_handle(dev);
err = -ENOMEM; err = -ENOMEM;
if (handle == 0) if (handle == 0)
goto err_out; goto err_out2;
} }
if (handle == TC_H_INGRESS) if (handle == TC_H_INGRESS)
...@@ -452,10 +449,6 @@ qdisc_create(struct net_device *dev, u32 handle, struct rtattr **tca, int *errp) ...@@ -452,10 +449,6 @@ qdisc_create(struct net_device *dev, u32 handle, struct rtattr **tca, int *errp)
else else
sch->handle = handle; sch->handle = handle;
err = -EBUSY;
if (!try_module_get(ops->owner))
goto err_out;
/* enqueue is accessed locklessly - make sure it's visible /* enqueue is accessed locklessly - make sure it's visible
* before we set a netdevice's qdisc pointer to sch */ * before we set a netdevice's qdisc pointer to sch */
smp_wmb(); smp_wmb();
...@@ -471,8 +464,8 @@ qdisc_create(struct net_device *dev, u32 handle, struct rtattr **tca, int *errp) ...@@ -471,8 +464,8 @@ qdisc_create(struct net_device *dev, u32 handle, struct rtattr **tca, int *errp)
#endif #endif
return sch; return sch;
} }
err_out2:
module_put(ops->owner); module_put(ops->owner);
err_out: err_out:
*errp = err; *errp = err;
if (p) if (p)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment