mirror of https://gitee.com/openkylin/qemu.git
fix access_ok() to allow to run LTP on AARCH64,
fix SIOCGSTAMP with 5.2 kernel headers, fix structure target_ucontext for MIPS -----BEGIN PGP SIGNATURE----- iQJGBAABCAAwFiEEzS913cjjpNwuT1Fz8ww4vT8vvjwFAl0xecASHGxhdXJlbnRA dml2aWVyLmV1AAoJEPMMOL0/L748oyIQAK8KEW9GRKcp2Zh6KuT5kyjmnE8X33aJ r6Y9jsU1rPac10hvwemxDBPitlwhFKYvDIZFerYK91FzQNb2Tcs7arIUWv9hnKAk axVwrKrV58L0KwT87OhVexSSk8hcTrJh35TCevdBxAjO+oTMiLctJkXKNtGdY/kA Qk2cJo5WsYRUouwcSlO2Z0XAWYAj3a2phiQ6j8T45iHaNUllErF9Zyg7jPSAV/P6 QO9zxqHCl93QaBiARtRrweH3icm+9560yIzWyZljjfPNer/eRw43cAo1ymm6SIGS lf5okWeaUKWaMmm8GnBq6uy9ZCkxcKrRSTEzDAOGdD2IExwzUZbsLTZ2OUSj9Mj+ C56uPzqlVOj2tF44bGsU6JEc5GpuBlkEA+F1GnjxJ3LAhQWjJlOcl5bZGXXsZngq 0dcnRjp2nHf1QhhxdV5gts2mDL8pRGjAV2nKmwbTokQC7dZLAsj/U1LXQ+9i5WUb OEXqFHAuuitmIsNFDuu1cIPFQBmuxUQ3YyUHeDzaU4T/gTJFrdLO4uMq3QiU+5lj QIhCSba8Sy1YExnD8gpxDUlGOxtHSb+aGVtyIjOL+DcrQzzS6141jBDJF0zyo4vd G60wXD99fkc8iuzbjSBVG7+JqGCXM/QINsQGOxRe27X6HicJRki2OLS6mtJHsPuV Xjn576coyNsQ =Jfbz -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-4.1-pull-request' into staging fix access_ok() to allow to run LTP on AARCH64, fix SIOCGSTAMP with 5.2 kernel headers, fix structure target_ucontext for MIPS # gpg: Signature made Fri 19 Jul 2019 09:05:20 BST # gpg: using RSA key CD2F75DDC8E3A4DC2E4F5173F30C38BD3F2FBE3C # gpg: issuer "laurent@vivier.eu" # gpg: Good signature from "Laurent Vivier <lvivier@redhat.com>" [full] # gpg: aka "Laurent Vivier <laurent@vivier.eu>" [full] # gpg: aka "Laurent Vivier (Red Hat) <lvivier@redhat.com>" [full] # Primary key fingerprint: CD2F 75DD C8E3 A4DC 2E4F 5173 F30C 38BD 3F2F BE3C * remotes/vivier2/tags/linux-user-for-4.1-pull-request: linux-user: fix to handle variably sized SIOCGSTAMP with new kernels linux-user: check valid address in access_ok() linux-user: Fix structure target_ucontext for MIPS Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
0274f45bde
|
@ -62,7 +62,11 @@ typedef uint64_t abi_ptr;
|
|||
/* All direct uses of g2h and h2g need to go away for usermode softmmu. */
|
||||
#define g2h(x) ((void *)((unsigned long)(abi_ptr)(x) + guest_base))
|
||||
|
||||
#if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS
|
||||
#define guest_addr_valid(x) (1)
|
||||
#else
|
||||
#define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX)
|
||||
#endif
|
||||
#define h2g_valid(x) guest_addr_valid((unsigned long)(x) - guest_base)
|
||||
|
||||
static inline int guest_range_valid(unsigned long start, unsigned long len)
|
||||
|
|
|
@ -222,8 +222,25 @@
|
|||
IOCTL(SIOCGIWNAME, IOC_W | IOC_R, MK_PTR(MK_STRUCT(STRUCT_char_ifreq)))
|
||||
IOCTL(SIOCSPGRP, IOC_W, MK_PTR(TYPE_INT)) /* pid_t */
|
||||
IOCTL(SIOCGPGRP, IOC_R, MK_PTR(TYPE_INT)) /* pid_t */
|
||||
IOCTL(SIOCGSTAMP, IOC_R, MK_PTR(MK_STRUCT(STRUCT_timeval)))
|
||||
IOCTL(SIOCGSTAMPNS, IOC_R, MK_PTR(MK_STRUCT(STRUCT_timespec)))
|
||||
|
||||
/*
|
||||
* We can't use IOCTL_SPECIAL() because it will set
|
||||
* host_cmd to XXX_OLD and XXX_NEW and these macros
|
||||
* are not defined with kernel prior to 5.2.
|
||||
* We must set host_cmd to the same value as in target_cmd
|
||||
* otherwise the consistency check in syscall_init()
|
||||
* will trigger an error.
|
||||
* host_cmd is ignored by the do_ioctl_XXX() helpers.
|
||||
* FIXME: create a macro to define this kind of entry
|
||||
*/
|
||||
{ TARGET_SIOCGSTAMP_OLD, TARGET_SIOCGSTAMP_OLD,
|
||||
"SIOCGSTAMP_OLD", IOC_R, do_ioctl_SIOCGSTAMP },
|
||||
{ TARGET_SIOCGSTAMPNS_OLD, TARGET_SIOCGSTAMPNS_OLD,
|
||||
"SIOCGSTAMPNS_OLD", IOC_R, do_ioctl_SIOCGSTAMPNS },
|
||||
{ TARGET_SIOCGSTAMP_NEW, TARGET_SIOCGSTAMP_NEW,
|
||||
"SIOCGSTAMP_NEW", IOC_R, do_ioctl_SIOCGSTAMP },
|
||||
{ TARGET_SIOCGSTAMPNS_NEW, TARGET_SIOCGSTAMPNS_NEW,
|
||||
"SIOCGSTAMPNS_NEW", IOC_R, do_ioctl_SIOCGSTAMPNS },
|
||||
|
||||
IOCTL(RNDGETENTCNT, IOC_R, MK_PTR(TYPE_INT))
|
||||
IOCTL(RNDADDTOENTCNT, IOC_W, MK_PTR(TYPE_INT))
|
||||
|
|
|
@ -71,10 +71,9 @@ struct sigframe {
|
|||
};
|
||||
|
||||
struct target_ucontext {
|
||||
target_ulong tuc_flags;
|
||||
target_ulong tuc_link;
|
||||
abi_ulong tuc_flags;
|
||||
abi_ulong tuc_link;
|
||||
target_stack_t tuc_stack;
|
||||
target_ulong pad0;
|
||||
struct target_sigcontext tuc_mcontext;
|
||||
target_sigset_t tuc_sigmask;
|
||||
};
|
||||
|
|
|
@ -456,7 +456,9 @@ extern unsigned long guest_stack_size;
|
|||
|
||||
static inline int access_ok(int type, abi_ulong addr, abi_ulong size)
|
||||
{
|
||||
return page_check_range((target_ulong)addr, size,
|
||||
return guest_addr_valid(addr) &&
|
||||
(size == 0 || guest_addr_valid(addr + size - 1)) &&
|
||||
page_check_range((target_ulong)addr, size,
|
||||
(type == VERIFY_READ) ? PAGE_READ : (PAGE_READ | PAGE_WRITE)) == 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include <sched.h>
|
||||
#include <sys/timex.h>
|
||||
#include <sys/socket.h>
|
||||
#include <linux/sockios.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/uio.h>
|
||||
#include <poll.h>
|
||||
|
@ -1126,8 +1127,9 @@ static inline abi_long copy_from_user_timeval(struct timeval *tv,
|
|||
{
|
||||
struct target_timeval *target_tv;
|
||||
|
||||
if (!lock_user_struct(VERIFY_READ, target_tv, target_tv_addr, 1))
|
||||
if (!lock_user_struct(VERIFY_READ, target_tv, target_tv_addr, 1)) {
|
||||
return -TARGET_EFAULT;
|
||||
}
|
||||
|
||||
__get_user(tv->tv_sec, &target_tv->tv_sec);
|
||||
__get_user(tv->tv_usec, &target_tv->tv_usec);
|
||||
|
@ -1142,8 +1144,9 @@ static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr,
|
|||
{
|
||||
struct target_timeval *target_tv;
|
||||
|
||||
if (!lock_user_struct(VERIFY_WRITE, target_tv, target_tv_addr, 0))
|
||||
if (!lock_user_struct(VERIFY_WRITE, target_tv, target_tv_addr, 0)) {
|
||||
return -TARGET_EFAULT;
|
||||
}
|
||||
|
||||
__put_user(tv->tv_sec, &target_tv->tv_sec);
|
||||
__put_user(tv->tv_usec, &target_tv->tv_usec);
|
||||
|
@ -1153,6 +1156,65 @@ static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static inline abi_long copy_to_user_timeval64(abi_ulong target_tv_addr,
|
||||
const struct timeval *tv)
|
||||
{
|
||||
struct target__kernel_sock_timeval *target_tv;
|
||||
|
||||
if (!lock_user_struct(VERIFY_WRITE, target_tv, target_tv_addr, 0)) {
|
||||
return -TARGET_EFAULT;
|
||||
}
|
||||
|
||||
__put_user(tv->tv_sec, &target_tv->tv_sec);
|
||||
__put_user(tv->tv_usec, &target_tv->tv_usec);
|
||||
|
||||
unlock_user_struct(target_tv, target_tv_addr, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline abi_long target_to_host_timespec(struct timespec *host_ts,
|
||||
abi_ulong target_addr)
|
||||
{
|
||||
struct target_timespec *target_ts;
|
||||
|
||||
if (!lock_user_struct(VERIFY_READ, target_ts, target_addr, 1)) {
|
||||
return -TARGET_EFAULT;
|
||||
}
|
||||
__get_user(host_ts->tv_sec, &target_ts->tv_sec);
|
||||
__get_user(host_ts->tv_nsec, &target_ts->tv_nsec);
|
||||
unlock_user_struct(target_ts, target_addr, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline abi_long host_to_target_timespec(abi_ulong target_addr,
|
||||
struct timespec *host_ts)
|
||||
{
|
||||
struct target_timespec *target_ts;
|
||||
|
||||
if (!lock_user_struct(VERIFY_WRITE, target_ts, target_addr, 0)) {
|
||||
return -TARGET_EFAULT;
|
||||
}
|
||||
__put_user(host_ts->tv_sec, &target_ts->tv_sec);
|
||||
__put_user(host_ts->tv_nsec, &target_ts->tv_nsec);
|
||||
unlock_user_struct(target_ts, target_addr, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline abi_long host_to_target_timespec64(abi_ulong target_addr,
|
||||
struct timespec *host_ts)
|
||||
{
|
||||
struct target__kernel_timespec *target_ts;
|
||||
|
||||
if (!lock_user_struct(VERIFY_WRITE, target_ts, target_addr, 0)) {
|
||||
return -TARGET_EFAULT;
|
||||
}
|
||||
__put_user(host_ts->tv_sec, &target_ts->tv_sec);
|
||||
__put_user(host_ts->tv_nsec, &target_ts->tv_nsec);
|
||||
unlock_user_struct(target_ts, target_addr, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline abi_long copy_from_user_timezone(struct timezone *tz,
|
||||
abi_ulong target_tz_addr)
|
||||
{
|
||||
|
@ -4899,6 +4961,54 @@ static abi_long do_ioctl_kdsigaccept(const IOCTLEntry *ie, uint8_t *buf_temp,
|
|||
return get_errno(safe_ioctl(fd, ie->host_cmd, sig));
|
||||
}
|
||||
|
||||
static abi_long do_ioctl_SIOCGSTAMP(const IOCTLEntry *ie, uint8_t *buf_temp,
|
||||
int fd, int cmd, abi_long arg)
|
||||
{
|
||||
struct timeval tv;
|
||||
abi_long ret;
|
||||
|
||||
ret = get_errno(safe_ioctl(fd, SIOCGSTAMP, &tv));
|
||||
if (is_error(ret)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (cmd == (int)TARGET_SIOCGSTAMP_OLD) {
|
||||
if (copy_to_user_timeval(arg, &tv)) {
|
||||
return -TARGET_EFAULT;
|
||||
}
|
||||
} else {
|
||||
if (copy_to_user_timeval64(arg, &tv)) {
|
||||
return -TARGET_EFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static abi_long do_ioctl_SIOCGSTAMPNS(const IOCTLEntry *ie, uint8_t *buf_temp,
|
||||
int fd, int cmd, abi_long arg)
|
||||
{
|
||||
struct timespec ts;
|
||||
abi_long ret;
|
||||
|
||||
ret = get_errno(safe_ioctl(fd, SIOCGSTAMPNS, &ts));
|
||||
if (is_error(ret)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (cmd == (int)TARGET_SIOCGSTAMPNS_OLD) {
|
||||
if (host_to_target_timespec(arg, &ts)) {
|
||||
return -TARGET_EFAULT;
|
||||
}
|
||||
} else{
|
||||
if (host_to_target_timespec64(arg, &ts)) {
|
||||
return -TARGET_EFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef TIOCGPTPEER
|
||||
static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp,
|
||||
int fd, int cmd, abi_long arg)
|
||||
|
@ -6271,32 +6381,6 @@ static inline abi_long target_ftruncate64(void *cpu_env, abi_long arg1,
|
|||
}
|
||||
#endif
|
||||
|
||||
static inline abi_long target_to_host_timespec(struct timespec *host_ts,
|
||||
abi_ulong target_addr)
|
||||
{
|
||||
struct target_timespec *target_ts;
|
||||
|
||||
if (!lock_user_struct(VERIFY_READ, target_ts, target_addr, 1))
|
||||
return -TARGET_EFAULT;
|
||||
__get_user(host_ts->tv_sec, &target_ts->tv_sec);
|
||||
__get_user(host_ts->tv_nsec, &target_ts->tv_nsec);
|
||||
unlock_user_struct(target_ts, target_addr, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline abi_long host_to_target_timespec(abi_ulong target_addr,
|
||||
struct timespec *host_ts)
|
||||
{
|
||||
struct target_timespec *target_ts;
|
||||
|
||||
if (!lock_user_struct(VERIFY_WRITE, target_ts, target_addr, 0))
|
||||
return -TARGET_EFAULT;
|
||||
__put_user(host_ts->tv_sec, &target_ts->tv_sec);
|
||||
__put_user(host_ts->tv_nsec, &target_ts->tv_nsec);
|
||||
unlock_user_struct(target_ts, target_addr, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline abi_long target_to_host_itimerspec(struct itimerspec *host_itspec,
|
||||
abi_ulong target_addr)
|
||||
{
|
||||
|
|
|
@ -209,16 +209,34 @@ struct target_linger {
|
|||
abi_int l_linger; /* How long to linger for */
|
||||
};
|
||||
|
||||
#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
|
||||
struct target_timeval {
|
||||
abi_long tv_sec;
|
||||
abi_int tv_usec;
|
||||
};
|
||||
#define target__kernel_sock_timeval target_timeval
|
||||
#else
|
||||
struct target_timeval {
|
||||
abi_long tv_sec;
|
||||
abi_long tv_usec;
|
||||
};
|
||||
|
||||
struct target__kernel_sock_timeval {
|
||||
abi_llong tv_sec;
|
||||
abi_llong tv_usec;
|
||||
};
|
||||
#endif
|
||||
|
||||
struct target_timespec {
|
||||
abi_long tv_sec;
|
||||
abi_long tv_nsec;
|
||||
};
|
||||
|
||||
struct target__kernel_timespec {
|
||||
abi_llong tv_sec;
|
||||
abi_llong tv_nsec;
|
||||
};
|
||||
|
||||
struct target_timezone {
|
||||
abi_int tz_minuteswest;
|
||||
abi_int tz_dsttime;
|
||||
|
@ -749,8 +767,16 @@ struct target_pollfd {
|
|||
#define TARGET_SIOCGPGRP 0x8904
|
||||
#endif
|
||||
|
||||
#define TARGET_SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
|
||||
#define TARGET_SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
|
||||
#if defined(TARGET_SH4)
|
||||
#define TARGET_SIOCGSTAMP_OLD TARGET_IOR('s', 100, struct target_timeval)
|
||||
#define TARGET_SIOCGSTAMPNS_OLD TARGET_IOR('s', 101, struct target_timespec)
|
||||
#else
|
||||
#define TARGET_SIOCGSTAMP_OLD 0x8906
|
||||
#define TARGET_SIOCGSTAMPNS_OLD 0x8907
|
||||
#endif
|
||||
|
||||
#define TARGET_SIOCGSTAMP_NEW TARGET_IOR(0x89, 0x06, abi_llong[2])
|
||||
#define TARGET_SIOCGSTAMPNS_NEW TARGET_IOR(0x89, 0x07, abi_llong[2])
|
||||
|
||||
/* Networking ioctls */
|
||||
#define TARGET_SIOCADDRT 0x890B /* add routing table entry */
|
||||
|
|
|
@ -14,12 +14,6 @@ STRUCT(serial_icounter_struct,
|
|||
STRUCT(sockaddr,
|
||||
TYPE_SHORT, MK_ARRAY(TYPE_CHAR, 14))
|
||||
|
||||
STRUCT(timeval,
|
||||
MK_ARRAY(TYPE_LONG, 2))
|
||||
|
||||
STRUCT(timespec,
|
||||
MK_ARRAY(TYPE_LONG, 2))
|
||||
|
||||
STRUCT(rtentry,
|
||||
TYPE_ULONG, MK_STRUCT(STRUCT_sockaddr), MK_STRUCT(STRUCT_sockaddr), MK_STRUCT(STRUCT_sockaddr),
|
||||
TYPE_SHORT, TYPE_SHORT, TYPE_ULONG, TYPE_PTRVOID, TYPE_SHORT, TYPE_PTRVOID,
|
||||
|
|
Loading…
Reference in New Issue