Re: [Xenomai-core] [git pull] RTDM: Fix potential NULL pointer dereference

2010-03-31 Thread Jan Kiszka
Gilles Chanteperdrix wrote:
 Jan Kiszka wrote:
 Gilles Chanteperdrix wrote:
 Jan Kiszka wrote:
 The following changes since commit 
 6b3e8f2e5c69397814cb2f4029cdfbaff16e113e:
   Gilles Chanteperdrix (1):
 doc: regenerate

 are available in the git repository at:

   git://git.xenomai.org/xenomai-jki.git for-upstream

 Unfortunately too late for 2.5.2, fortunately only relevant if something
 else went wrong in create_instance (ENOMEM or application error).

 Wolfgang Mauerer (1):
   RTDM: Fix potential NULL pointer dereference

  ksrc/skins/rtdm/core.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

 Was not there any plan to remove this code and have a more posix
 compliant close? I thought this had been merged?
 Yes. But that requires more work than it would have been appropriate for
 2.5.2.
 
 Ok, but could we have it for 2.5.3?
 

Will see what I can do (no budget for this, so no promise).

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux

___
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core


Re: [Xenomai-core] [git pull] RTDM: Fix potential NULL pointer dereference

2010-03-31 Thread Jan Kiszka
Gilles Chanteperdrix wrote:
 Jan Kiszka wrote:
 Gilles Chanteperdrix wrote:
 Jan Kiszka wrote:
 Gilles Chanteperdrix wrote:
 Jan Kiszka wrote:
 Gilles Chanteperdrix wrote:
 Jan Kiszka wrote:
 The following changes since commit 
 6b3e8f2e5c69397814cb2f4029cdfbaff16e113e:
   Gilles Chanteperdrix (1):
 doc: regenerate

 are available in the git repository at:

   git://git.xenomai.org/xenomai-jki.git for-upstream

 Unfortunately too late for 2.5.2, fortunately only relevant if 
 something
 else went wrong in create_instance (ENOMEM or application error).

 Wolfgang Mauerer (1):
   RTDM: Fix potential NULL pointer dereference

  ksrc/skins/rtdm/core.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

 Was not there any plan to remove this code and have a more posix
 compliant close? I thought this had been merged?
 Yes. But that requires more work than it would have been appropriate for
 2.5.2.
 Ok, but could we have it for 2.5.3?

 Will see what I can do (no budget for this, so no promise).
 The patches are floating around for some time (I was in CC of the mail
 Philippe sent you about this some time ago), I guess some testing is
 needed, this is why you need some time? Could we help with this testing?

 Then I totally lost track of this. What series are you referring to?
 
 A (private) mail entitled Re: RTDM close() refactoring from Philippe,
 with in fact, a unique patch.
 

Ah, now I found it. That discussion ended last September with a Don't
bother yet by Philippe as he said you pointed out some remaining issues
/wrt POSIX compliance. So I stopped bothering.

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux

___
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core


Re: [Xenomai-core] [git pull] RTDM: Fix potential NULL pointer dereference

2010-03-31 Thread Gilles Chanteperdrix
Jan Kiszka wrote:
 Gilles Chanteperdrix wrote:
 Jan Kiszka wrote:
 Gilles Chanteperdrix wrote:
 Jan Kiszka wrote:
 Gilles Chanteperdrix wrote:
 Jan Kiszka wrote:
 Gilles Chanteperdrix wrote:
 Jan Kiszka wrote:
 The following changes since commit 
 6b3e8f2e5c69397814cb2f4029cdfbaff16e113e:
   Gilles Chanteperdrix (1):
 doc: regenerate

 are available in the git repository at:

   git://git.xenomai.org/xenomai-jki.git for-upstream

 Unfortunately too late for 2.5.2, fortunately only relevant if 
 something
 else went wrong in create_instance (ENOMEM or application error).

 Wolfgang Mauerer (1):
   RTDM: Fix potential NULL pointer dereference

  ksrc/skins/rtdm/core.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

 Was not there any plan to remove this code and have a more posix
 compliant close? I thought this had been merged?
 Yes. But that requires more work than it would have been appropriate for
 2.5.2.
 Ok, but could we have it for 2.5.3?

 Will see what I can do (no budget for this, so no promise).
 The patches are floating around for some time (I was in CC of the mail
 Philippe sent you about this some time ago), I guess some testing is
 needed, this is why you need some time? Could we help with this testing?

 Then I totally lost track of this. What series are you referring to?
 A (private) mail entitled Re: RTDM close() refactoring from Philippe,
 with in fact, a unique patch.

 
 Ah, now I found it. That discussion ended last September with a Don't
 bother yet by Philippe as he said you pointed out some remaining issues
 /wrt POSIX compliance. So I stopped bothering.

There was a reply here it is, with a fixed version. Inlined here.

diff --git a/include/asm-generic/wrappers.h b/include/asm-generic/wrappers.h
index 18af70b..71abc5a 100644
--- a/include/asm-generic/wrappers.h
+++ b/include/asm-generic/wrappers.h
@@ -536,4 +536,9 @@ static inline void wrap_proc_dir_entry_owner(struct 
proc_dir_entry *entry)
 #endif /* LINUX_VERSION_CODE  KERNEL_VERSION(2,6,30) */
 #endif /* CONFIG_PROC_FS */
 
+#ifndef list_first_entry
+#define list_first_entry(ptr, type, member) \
+   list_entry((ptr)-next, type, member)
+#endif
+
 #endif /* _XENO_ASM_GENERIC_WRAPPERS_H */
diff --git a/include/rtdm/rtdm_driver.h b/include/rtdm/rtdm_driver.h
index ea543c1..d5f997b 100644
--- a/include/rtdm/rtdm_driver.h
+++ b/include/rtdm/rtdm_driver.h
@@ -368,6 +368,7 @@ struct rtdm_operations {
 
 struct rtdm_devctx_reserved {
void *owner;
+   struct list_head cleanup;
 };
 
 /**
@@ -549,9 +550,17 @@ static inline void rtdm_context_lock(struct 
rtdm_dev_context *context)
atomic_inc(context-close_lock_count);
 }
 
+void __rtdm_context_flush(struct rtdm_dev_context *context);
+
 static inline void rtdm_context_unlock(struct rtdm_dev_context *context)
 {
-   atomic_dec(context-close_lock_count);
+   if (atomic_dec_and_test(context-close_lock_count))
+   __rtdm_context_flush(context);
+}
+
+static inline void rtdm_context_put(struct rtdm_dev_context *context)
+{
+   rtdm_context_unlock(context);
 }
 
 /* --- clock services --- */
diff --git a/ksrc/skins/rtdm/core.c b/ksrc/skins/rtdm/core.c
index 5843842..c3ff526 100644
--- a/ksrc/skins/rtdm/core.c
+++ b/ksrc/skins/rtdm/core.c
@@ -26,7 +26,7 @@
  * @{
  */
 
-#include linux/delay.h
+#include linux/workqueue.h
 
 #include nucleus/pod.h
 #include nucleus/ppd.h
@@ -44,20 +44,25 @@ struct rtdm_fildes fildes_table[RTDM_FD_MAX] =
 static unsigned long used_fildes[FD_BITMAP_SIZE];
 int open_fildes;   /* number of used descriptors */
 
+static DECLARE_WORK_FUNC(close_callback);
+static DECLARE_WORK_NODATA(close_work, close_callback);
+static LIST_HEAD(cleanup_queue);
+
 xntbase_t *rtdm_tbase;
 EXPORT_SYMBOL(rtdm_tbase);
 
 DEFINE_XNLOCK(rt_fildes_lock);
 
 /**
- * @brief Resolve file descriptor to device context
+ * @brief Retrieve and lock a device context
  *
  * @param[in] fd File descriptor
  *
  * @return Pointer to associated device context, or NULL on error
  *
- * @note The device context has to be unlocked using rtdm_context_unlock()
- * when it is no longer referenced.
+ * @note The device context has to be unlocked using
+ * rtdm_context_put() or rtdm_context_unlock() when it is no longer
+ * referenced.
  *
  * Environments:
  *
@@ -155,7 +160,7 @@ static int create_instance(struct rtdm_device *device,
 
context-fd = fd;
context-ops = device-ops;
-   atomic_set(context-close_lock_count, 0);
+   atomic_set(context-close_lock_count, 1);
 
 #ifdef CONFIG_XENO_OPT_PERVASIVE
ppd = xnshadow_ppd_get(__rtdm_muxid);
@@ -163,24 +168,32 @@ static int create_instance(struct rtdm_device *device,
 
context-reserved.owner =
ppd ? container_of(ppd, struct rtdm_process, ppd) : NULL;
+   INIT_LIST_HEAD(context-reserved.cleanup);
 
return 0;
 }
 
-/* call with rt_fildes_lock acquired - will release it */
-static void cleanup_instance(struct rtdm_device 

Re: [Xenomai-core] [git pull] RTDM: Fix potential NULL pointer dereference

2010-03-30 Thread Jan Kiszka
Gilles Chanteperdrix wrote:
 Jan Kiszka wrote:
 The following changes since commit 6b3e8f2e5c69397814cb2f4029cdfbaff16e113e:
   Gilles Chanteperdrix (1):
 doc: regenerate

 are available in the git repository at:

   git://git.xenomai.org/xenomai-jki.git for-upstream

 Unfortunately too late for 2.5.2, fortunately only relevant if something
 else went wrong in create_instance (ENOMEM or application error).

 Wolfgang Mauerer (1):
   RTDM: Fix potential NULL pointer dereference

  ksrc/skins/rtdm/core.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

 
 Was not there any plan to remove this code and have a more posix
 compliant close? I thought this had been merged?

Yes. But that requires more work than it would have been appropriate for
2.5.2.

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux

___
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core


Re: [Xenomai-core] [git pull] RTDM: Fix potential NULL pointer dereference

2010-03-30 Thread Gilles Chanteperdrix
Jan Kiszka wrote:
 Gilles Chanteperdrix wrote:
 Jan Kiszka wrote:
 The following changes since commit 6b3e8f2e5c69397814cb2f4029cdfbaff16e113e:
   Gilles Chanteperdrix (1):
 doc: regenerate

 are available in the git repository at:

   git://git.xenomai.org/xenomai-jki.git for-upstream

 Unfortunately too late for 2.5.2, fortunately only relevant if something
 else went wrong in create_instance (ENOMEM or application error).

 Wolfgang Mauerer (1):
   RTDM: Fix potential NULL pointer dereference

  ksrc/skins/rtdm/core.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

 Was not there any plan to remove this code and have a more posix
 compliant close? I thought this had been merged?
 
 Yes. But that requires more work than it would have been appropriate for
 2.5.2.

Ok, but could we have it for 2.5.3?


-- 
Gilles.

___
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core