Module: xenomai-jki
Branch: for-upstream
Commit: 971da8dcbe823f96f04a79bc448fabcef605f845
URL:    
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=971da8dcbe823f96f04a79bc448fabcef605f845

Author: Jan Kiszka <jan.kis...@siemens.com>
Date:   Fri Aug 20 14:42:07 2010 +0200

RTDM: Plug race between proc_read_dev_info and device deregistration

As the device references passed to proc_read_dev_info may become invalid
while we dereference it, we need to acquire nrt_dev_lock and check the
pointer against our list of registered devices.

Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>

---

 ksrc/skins/rtdm/proc.c |   27 ++++++++++++++++++++++++---
 1 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/ksrc/skins/rtdm/proc.c b/ksrc/skins/rtdm/proc.c
index df01b3f..8106ef6 100644
--- a/ksrc/skins/rtdm/proc.c
+++ b/ksrc/skins/rtdm/proc.c
@@ -298,12 +298,32 @@ static struct xnvfile_regular allfd_vfile = {
 
 static int devinfo_vfile_show(struct xnvfile_regular_iterator *it, void *data)
 {
-       struct rtdm_device *device = xnvfile_priv(it->vfile);
+       struct rtdm_device *device;
+       int i;
+
+       if (down_interruptible(&nrt_dev_lock))
+               return -ERESTARTSYS;
 
        /*
-        * Accessing the device during unregister (remove_proc_entry) might be
-        * racy, but no official workaround is known yet.
+        * As the device may have disappeared while the handler was called,
+        * first match the pointer against registered devices.
         */
+       for (i = 0; i < devname_hashtab_size; i++)
+               list_for_each_entry(device, &rtdm_named_devices[i],
+                                   reserved.entry)
+                       if (device == xnvfile_priv(it->vfile))
+                               goto found;
+
+       for (i = 0; i < protocol_hashtab_size; i++)
+               list_for_each_entry(device, &rtdm_protocol_devices[i],
+                                   reserved.entry)
+                       if (device == xnvfile_priv(it->vfile))
+                               goto found;
+
+       up(&nrt_dev_lock);
+       return -ENODEV;
+
+found:
        xnvfile_printf(it, "driver:\t\t%s\nversion:\t%d.%d.%d\n",
                       device->driver_name,
                       RTDM_DRIVER_MAJOR_VER(device->driver_version),
@@ -327,6 +347,7 @@ static int devinfo_vfile_show(struct 
xnvfile_regular_iterator *it, void *data)
        xnvfile_printf(it, "lock count:\t%d\n",
                       atomic_read(&device->reserved.refcount));
 
+       up(&nrt_dev_lock);
        return 0;
 }
 


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to