mirror of
https://github.com/FEX-Emu/linux.git
synced 2025-02-14 00:13:53 +00:00
sparc: Increase portability of strncpy_from_user() implementation.
Hide details of maximum user address calculation in a new asm/uaccess.h interface named user_addr_max(). Provide little-endian implementation in find_zero(), which should work but can probably be improved. Abstrace alignment check behind IS_UNALIGNED() macro. Kill double-semicolon, noticed by David Howells. Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
4efcac3a24
commit
35c9646062
@ -6,6 +6,9 @@
|
|||||||
#include <asm/uaccess_32.h>
|
#include <asm/uaccess_32.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define user_addr_max() \
|
||||||
|
(segment_eq(get_fs(), USER_DS) ? STACK_TOP : ~0UL)
|
||||||
|
|
||||||
extern long strncpy_from_user(char *dest, const char __user *src, long count);
|
extern long strncpy_from_user(char *dest, const char __user *src, long count);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
#include <linux/errno.h>
|
#include <linux/errno.h>
|
||||||
#include <linux/bug.h>
|
#include <linux/bug.h>
|
||||||
|
|
||||||
|
#include <asm/byteorder.h>
|
||||||
|
|
||||||
void copy_from_user_overflow(void)
|
void copy_from_user_overflow(void)
|
||||||
{
|
{
|
||||||
WARN(1, "Buffer overflow detected!\n");
|
WARN(1, "Buffer overflow detected!\n");
|
||||||
@ -14,6 +16,8 @@ EXPORT_SYMBOL(copy_from_user_overflow);
|
|||||||
static inline long find_zero(unsigned long mask)
|
static inline long find_zero(unsigned long mask)
|
||||||
{
|
{
|
||||||
long byte = 0;
|
long byte = 0;
|
||||||
|
|
||||||
|
#ifdef __BIG_ENDIAN
|
||||||
#ifdef CONFIG_64BIT
|
#ifdef CONFIG_64BIT
|
||||||
if (mask >> 32)
|
if (mask >> 32)
|
||||||
mask >>= 32;
|
mask >>= 32;
|
||||||
@ -25,7 +29,27 @@ static inline long find_zero(unsigned long mask)
|
|||||||
else
|
else
|
||||||
byte += 2;
|
byte += 2;
|
||||||
return (mask >> 8) ? byte : byte + 1;
|
return (mask >> 8) ? byte : byte + 1;
|
||||||
|
#else
|
||||||
|
#ifdef CONFIG_64BIT
|
||||||
|
if (!((unsigned int) mask)) {
|
||||||
|
mask >>= 32;
|
||||||
|
byte = 4;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
if (!(mask & 0xffff)) {
|
||||||
|
mask >>= 16;
|
||||||
|
byte += 2;
|
||||||
|
}
|
||||||
|
return (mask & 0xff) ? byte : byte + 1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
|
||||||
|
#define IS_UNALIGNED(src, dst) 0
|
||||||
|
#else
|
||||||
|
#define IS_UNALIGNED(src, dst) \
|
||||||
|
(((long) dst | (long) src) & (sizeof(long) - 1))
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do a strncpy, return length of string without final '\0'.
|
* Do a strncpy, return length of string without final '\0'.
|
||||||
@ -46,7 +70,7 @@ static inline long do_strncpy_from_user(char *dst, const char __user *src, long
|
|||||||
if (max > count)
|
if (max > count)
|
||||||
max = count;
|
max = count;
|
||||||
|
|
||||||
if (((long) dst | (long) src) & (sizeof(long) - 1))
|
if (IS_UNALIGNED(src, dst))
|
||||||
goto byte_at_a_time;
|
goto byte_at_a_time;
|
||||||
|
|
||||||
while (max >= sizeof(unsigned long)) {
|
while (max >= sizeof(unsigned long)) {
|
||||||
@ -59,7 +83,7 @@ static inline long do_strncpy_from_user(char *dst, const char __user *src, long
|
|||||||
v = (c + high_bits) & ~rhs;
|
v = (c + high_bits) & ~rhs;
|
||||||
*(unsigned long *)(dst+res) = c;
|
*(unsigned long *)(dst+res) = c;
|
||||||
if (v) {
|
if (v) {
|
||||||
v = (c & low_bits) + low_bits;;
|
v = (c & low_bits) + low_bits;
|
||||||
v = ~(v | rhs);
|
v = ~(v | rhs);
|
||||||
return res + find_zero(v);
|
return res + find_zero(v);
|
||||||
}
|
}
|
||||||
@ -119,9 +143,7 @@ long strncpy_from_user(char *dst, const char __user *src, long count)
|
|||||||
if (unlikely(count <= 0))
|
if (unlikely(count <= 0))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
max_addr = ~0UL;
|
max_addr = user_addr_max();
|
||||||
if (likely(segment_eq(get_fs(), USER_DS)))
|
|
||||||
max_addr = STACK_TOP;
|
|
||||||
src_addr = (unsigned long)src;
|
src_addr = (unsigned long)src;
|
||||||
if (likely(src_addr < max_addr)) {
|
if (likely(src_addr < max_addr)) {
|
||||||
unsigned long max = max_addr - src_addr;
|
unsigned long max = max_addr - src_addr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user