Skip to content

Commit

Permalink
xen/xenbus: reference count registered modules
Browse files Browse the repository at this point in the history
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: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Paul Durrant <pdurrant@amazon.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
  • Loading branch information
Paul Durrant authored and Juergen Gross committed Dec 4, 2019
1 parent b3f7931 commit 196748a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion drivers/xen/xenbus/xenbus_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,16 @@ int xenbus_dev_probe(struct device *_dev)
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);
if (err)
goto fail;
goto fail_put;

err = watch_otherend(dev);
if (err) {
Expand All @@ -244,6 +251,8 @@ int xenbus_dev_probe(struct device *_dev)
}

return 0;
fail_put:
module_put(drv->driver.owner);
fail:
xenbus_dev_error(dev, err, "xenbus_dev_probe on %s", dev->nodename);
xenbus_switch_state(dev, XenbusStateClosed);
Expand All @@ -263,6 +272,8 @@ int xenbus_dev_remove(struct device *_dev)
if (drv->remove)
drv->remove(dev);

module_put(drv->driver.owner);

free_otherend_details(dev);

xenbus_switch_state(dev, XenbusStateClosed);
Expand Down

0 comments on commit 196748a

Please sign in to comment.