summaryrefslogtreecommitdiff
path: root/lib/strncpy_from_user.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/strncpy_from_user.c')
-rw-r--r--lib/strncpy_from_user.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
index 734df060a5d2..9c7b353aacb7 100644
--- a/lib/strncpy_from_user.c
+++ b/lib/strncpy_from_user.c
@@ -15,6 +15,8 @@
(((long) dst | (long) src) & (sizeof(long) - 1))
#endif
+#define CHECK_ALIGN(v, a) ((((unsigned long)(v)) & ((a) - 1)) == 0)
+
/*
* Do a strncpy, return length of string without final '\0'.
* 'count' is the user-supplied count (return 'count' if we
@@ -37,6 +39,21 @@ static inline long do_strncpy_from_user(char *dst, const char __user *src,
if (IS_UNALIGNED(src, dst))
goto byte_at_a_time;
+ /* Copy a byte at a time until we align to 8 bytes */
+ while (max && (!CHECK_ALIGN(src + res, 8))) {
+ char c;
+ int ret;
+
+ ret = __get_user(c, src + res);
+ if (ret)
+ return -EFAULT;
+ dst[res] = c;
+ if (!c)
+ return res;
+ res++;
+ max--;
+ }
+
while (max >= sizeof(unsigned long)) {
unsigned long c, data;