All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-core] rtdm_safe_copy_from_user...
@ 2006-05-19  9:42 Wolfgang Grandegger
  2006-05-19 12:17 ` Jan Kiszka
  0 siblings, 1 reply; 2+ messages in thread
From: Wolfgang Grandegger @ 2006-05-19  9:42 UTC (permalink / raw)
  To: xenomai-core

[-- Attachment #1: Type: text/plain, Size: 395 bytes --]

Hello,

I propose to add the following commonly used RTDM inline functions to
rtdm_driver.h:

    static inline int rtdm_safe_copy_from_user()
    static inline int rtdm_safe_copy_to_user()

The attached patch also fixes a bug in rtdm_strncpy_from_user(). I think
__xn_access_ok() returns a non-zero value if the access is safe. Has it
ever worked? I don't care about the real name.

Wolfgang.


[-- Attachment #2: rtdm-safe-copy-user.patch --]
[-- Type: text/x-patch, Size: 1397 bytes --]

+ diff -u xenomai/include/rtdm/rtdm_driver.h.ORIG xenomai/include/rtdm/rtdm_driver.h
--- xenomai/include/rtdm/rtdm_driver.h.ORIG	2006-04-23 09:40:39.000000000 +0200
+++ xenomai/include/rtdm/rtdm_driver.h	2006-05-19 10:38:20.654561392 +0200
@@ -1047,12 +1047,30 @@
     return __xn_copy_to_user(user_info, dst, src, size);
 }
 
+static inline int rtdm_safe_copy_from_user(rtdm_user_info_t *user_info,
+					   void *dst, const void __user *src,
+					   size_t size)
+{
+    if (unlikely(!__xn_access_ok(user_info, VERIFY_READ, src, 1)))
+        return -EFAULT;
+    return __xn_copy_from_user(user_info, dst, src, size);
+}
+
+static inline int rtdm_safe_copy_to_user(rtdm_user_info_t *user_info,
+					 void __user *dst, const void *src,
+					 size_t size)
+{
+    if (unlikely(!__xn_access_ok(user_info, VERIFY_WRITE, src, 1)))
+        return -EFAULT;
+    return __xn_copy_to_user(user_info, dst, src, size);
+}
+
 static inline int rtdm_strncpy_from_user(rtdm_user_info_t *user_info,
                                          char *dst,
                                          const char __user *src,
                                          size_t count)
 {
-    if (unlikely(__xn_access_ok(user_info, VERIFY_READ, src, 1)))
+    if (unlikely(!__xn_access_ok(user_info, VERIFY_READ, src, 1)))
         return -EFAULT;
     return __xn_strncpy_from_user(user_info, dst, src, count);
 }


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Xenomai-core] rtdm_safe_copy_from_user...
  2006-05-19  9:42 [Xenomai-core] rtdm_safe_copy_from_user Wolfgang Grandegger
@ 2006-05-19 12:17 ` Jan Kiszka
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Kiszka @ 2006-05-19 12:17 UTC (permalink / raw)
  To: Wolfgang Grandegger; +Cc: xenomai-core

[-- Attachment #1: Type: text/plain, Size: 917 bytes --]

Wolfgang Grandegger wrote:
> Hello,
> 
> I propose to add the following commonly used RTDM inline functions to
> rtdm_driver.h:
> 
>    static inline int rtdm_safe_copy_from_user()
>    static inline int rtdm_safe_copy_to_user()

Yep, likely a convenient shortcut. Just a minor correction: the full
size should be checked, not just a single-byte range.

Those new services together with updated doc will go into trunk after
release 2.2. There are currently several RTDM extensions pending, so I
prefer to merge the whole packet and increment the revision number only
once.

> 
> The attached patch also fixes a bug in rtdm_strncpy_from_user(). I think
> __xn_access_ok() returns a non-zero value if the access is safe. Has it
> ever worked? I don't care about the real name.

Oops, obviously wrong and obviously yet unused. I fixed this in 2.1.x
and trunk.

Thanks for the patches!

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-05-19 12:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-19  9:42 [Xenomai-core] rtdm_safe_copy_from_user Wolfgang Grandegger
2006-05-19 12:17 ` Jan Kiszka

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.