Message ID | 20191202114117.1264-2-pdurrant@amazon.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | allow xen-blkback to be cleanly unloaded | expand |
On 02.12.2019 12:41, Paul Durrant wrote: > 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> with ... > --- a/drivers/xen/xenbus/xenbus_probe.c > +++ b/drivers/xen/xenbus/xenbus_probe.c > @@ -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); ... perhaps the full stop dropped here and ... > + err = -ESRCH; > + goto fail; > + } ... (definitely) indentation here changed to use a tab. Jan
On 02.12.19 12:41, Paul Durrant wrote: > 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> Pushed to xen/tip.git for-linus-5.5b Juergen
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c index 5b471889d723..4461f4583476 100644 --- a/drivers/xen/xenbus/xenbus_probe.c +++ b/drivers/xen/xenbus/xenbus_probe.c @@ -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) { @@ -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); @@ -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);
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> --- Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: Juergen Gross <jgross@suse.com> Cc: Stefano Stabellini <sstabellini@kernel.org> v2: - New in v2 v3: - Use try_module_get() rather than __module)get() and handle failure - Not added Juergen's R-b because of the change --- drivers/xen/xenbus/xenbus_probe.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)