From: Stuart Anderson <anderson@netsweng.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] RFC: [8/11] EFAULT patch
Date: Tue, 18 Sep 2007 21:27:19 -0400 (EDT) [thread overview]
Message-ID: <Pine.LNX.4.64.0709182125280.20150@trantor.stuart.netsweng.com> (raw)
[-- Attachment #1: Type: TEXT/PLAIN, Size: 458 bytes --]
This part updates the functions that read and write struct timespec, and
adjusts the places in do_syscall() that use it.
Stuart
Stuart R. Anderson anderson@netsweng.com
Network & Software Engineering http://www.netsweng.com/
1024D/37A79149: 0791 D3B8 9A4C 2CDC A31F
BD03 0A62 E534 37A7 9149
[-- Attachment #2: efault patch 8 of 11 --]
[-- Type: TEXT/PLAIN, Size: 3440 bytes --]
Index: qemu/linux-user/syscall.c
===================================================================
--- qemu.orig/linux-user/syscall.c 2007-09-16 15:56:47.000000000 -0400
+++ qemu/linux-user/syscall.c 2007-09-16 15:56:49.000000000 -0400
@@ -2436,26 +2436,24 @@
}
#endif
-static inline void target_to_host_timespec(struct timespec *host_ts,
- target_ulong target_addr)
+static inline long copy_from_user_timespec(struct timespec *host_ts,
+ struct target_timespec *target_ts)
{
- struct target_timespec *target_ts;
-
- lock_user_struct(target_ts, target_addr, 1);
+ if( copy_from_user(host_ts,target_ts,sizeof(*target_ts)) ) return -1;
host_ts->tv_sec = tswapl(target_ts->tv_sec);
host_ts->tv_nsec = tswapl(target_ts->tv_nsec);
- unlock_user_struct(target_ts, target_addr, 0);
+
+ return 0;
}
-static inline void host_to_target_timespec(target_ulong target_addr,
+static inline long copy_to_user_timespec(struct target_timespec *target_ts,
struct timespec *host_ts)
{
- struct target_timespec *target_ts;
-
- lock_user_struct(target_ts, target_addr, 0);
+ if( copy_to_user(target_ts, host_ts, sizeof(*target_ts)) ) return -1;
target_ts->tv_sec = tswapl(host_ts->tv_sec);
target_ts->tv_nsec = tswapl(host_ts->tv_nsec);
- unlock_user_struct(target_ts, target_addr, 1);
+
+ return 0;
}
long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
@@ -3102,7 +3100,7 @@
unlock_user(p, arg1, 0);
if (arg3) {
puts = &uts;
- target_to_host_timespec(puts, arg3);
+ copy_from_user_timespec(puts, (struct target_timespec *)arg3);
} else {
puts = NULL;
}
@@ -3997,17 +3995,17 @@
struct timespec ts;
ret = get_errno(sched_rr_get_interval(arg1, &ts));
if (!is_error(ret)) {
- host_to_target_timespec(arg2, &ts);
+ if( copy_to_user_timespec((struct target_timespec *)arg2, &ts) ) return -EFAULT;
}
}
break;
case TARGET_NR_nanosleep:
{
struct timespec req, rem;
- target_to_host_timespec(&req, arg1);
+ if( copy_from_user_timespec(&req, (struct target_timespec *)arg1) ) return -EFAULT;
ret = get_errno(nanosleep(&req, &rem));
if (is_error(ret) && arg2) {
- host_to_target_timespec(arg2, &rem);
+ if( copy_to_user_timespec((struct target_timespec *)arg2, &rem) ) return -EFAULT;
}
}
break;
@@ -4615,7 +4613,7 @@
struct timespec ts;
ret = get_errno(clock_gettime(arg1, &ts));
if (!is_error(ret)) {
- host_to_target_timespec(arg2, &ts);
+ if( copy_to_user_timespec((struct target_timespec *)arg2, &ts) ) return -EFAULT;
}
break;
}
@@ -4626,7 +4624,7 @@
struct timespec ts;
ret = get_errno(clock_getres(arg1, &ts));
if (!is_error(ret)) {
- host_to_target_timespec(arg2, &ts);
+ if( copy_to_user_timespec((struct target_timespec *)arg2, &ts) ) return -EFAULT;
}
break;
}
reply other threads:[~2007-09-19 1:29 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.64.0709182125280.20150@trantor.stuart.netsweng.com \
--to=anderson@netsweng.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).