Commit 196748a2 authored by Paul Durrant's avatar Paul Durrant Committed by Juergen Gross

xen/xenbus: reference count registered modules

To prevent a PV driver module being removed whilst attached to its other
end, and hence xenbus calling into potentially invalid text, take a
reference on the module before calling the probe() method (dropping it if
unsuccessful) and drop the reference after returning from the remove()
method.
Suggested-by: default avatarJan Beulich <jbeulich@suse.com>
Signed-off-by: default avatarPaul Durrant <pdurrant@amazon.com>
Reviewed-by: default avatarJan Beulich <jbeulich@suse.com>
Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
parent b3f7931f
...@@ -232,9 +232,16 @@ int xenbus_dev_probe(struct device *_dev) ...@@ -232,9 +232,16 @@ int xenbus_dev_probe(struct device *_dev)
return err; return err;
} }
if (!try_module_get(drv->driver.owner)) {
dev_warn(&dev->dev, "failed to acquire module reference on '%s'\n",
drv->driver.name);
err = -ESRCH;
goto fail;
}
err = drv->probe(dev, id); err = drv->probe(dev, id);
if (err) if (err)
goto fail; goto fail_put;
err = watch_otherend(dev); err = watch_otherend(dev);
if (err) { if (err) {
...@@ -244,6 +251,8 @@ int xenbus_dev_probe(struct device *_dev) ...@@ -244,6 +251,8 @@ int xenbus_dev_probe(struct device *_dev)
} }
return 0; return 0;
fail_put:
module_put(drv->driver.owner);
fail: fail:
xenbus_dev_error(dev, err, "xenbus_dev_probe on %s", dev->nodename); xenbus_dev_error(dev, err, "xenbus_dev_probe on %s", dev->nodename);
xenbus_switch_state(dev, XenbusStateClosed); xenbus_switch_state(dev, XenbusStateClosed);
...@@ -263,6 +272,8 @@ int xenbus_dev_remove(struct device *_dev) ...@@ -263,6 +272,8 @@ int xenbus_dev_remove(struct device *_dev)
if (drv->remove) if (drv->remove)
drv->remove(dev); drv->remove(dev);
module_put(drv->driver.owner);
free_otherend_details(dev); free_otherend_details(dev);
xenbus_switch_state(dev, XenbusStateClosed); xenbus_switch_state(dev, XenbusStateClosed);
......
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