From: Stuart Anderson <anderson@netsweng.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] RFC: [7/11] EFAULT patch
Date: Tue, 18 Sep 2007 21:25:02 -0400 (EDT) [thread overview]
Message-ID: <Pine.LNX.4.64.0709182123530.20150@trantor.stuart.netsweng.com> (raw)
[-- Attachment #1: Type: TEXT/PLAIN, Size: 399 bytes --]
This part updates do_fcntl() to use the new kernel-like APIs.
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 7 of 11 --]
[-- Type: TEXT/PLAIN, Size: 5750 bytes --]
Index: qemu/linux-user/syscall.c
===================================================================
--- qemu.orig/linux-user/syscall.c 2007-09-17 01:02:17.000000000 -0400
+++ qemu/linux-user/syscall.c 2007-09-17 01:06:30.000000000 -0400
@@ -2242,73 +2242,69 @@
static long do_fcntl(int fd, int cmd, target_ulong arg)
{
struct flock fl;
- struct target_flock *target_fl;
+ struct target_flock *target_fl = (struct target_flock *)arg;
struct flock64 fl64;
- struct target_flock64 *target_fl64;
+ struct target_flock64 *target_fl64 = (struct target_flock64 *)arg;
long ret;
switch(cmd) {
case TARGET_F_GETLK:
- lock_user_struct(target_fl, arg, 1);
- fl.l_type = tswap16(target_fl->l_type);
- fl.l_whence = tswap16(target_fl->l_whence);
- fl.l_start = tswapl(target_fl->l_start);
- fl.l_len = tswapl(target_fl->l_len);
- fl.l_pid = tswapl(target_fl->l_pid);
- unlock_user_struct(target_fl, arg, 0);
+ if( !access_ok(VERIFY_READ,target_fl,sizeof(struct target_flock)) ) return -EFAULT;
+ __get_user(fl.l_type, &target_fl->l_type);
+ __get_user(fl.l_whence, &target_fl->l_whence);
+ __get_user(fl.l_start, &target_fl->l_start);
+ __get_user(fl.l_len, &target_fl->l_len);
+ __get_user(fl.l_pid, &target_fl->l_pid);
ret = fcntl(fd, cmd, &fl);
if (ret == 0) {
- lock_user_struct(target_fl, arg, 0);
- target_fl->l_type = tswap16(fl.l_type);
- target_fl->l_whence = tswap16(fl.l_whence);
- target_fl->l_start = tswapl(fl.l_start);
- target_fl->l_len = tswapl(fl.l_len);
- target_fl->l_pid = tswapl(fl.l_pid);
- unlock_user_struct(target_fl, arg, 1);
+ if( !access_ok(VERIFY_WRITE,target_fl,sizeof(struct target_flock)) ) return -EFAULT;
+ __put_user(fl.l_type, &target_fl->l_type);
+ __put_user(fl.l_whence, &target_fl->l_whence);
+ __put_user(fl.l_start, &target_fl->l_start);
+ __put_user(fl.l_len, &target_fl->l_len);
+ __put_user(fl.l_pid, &target_fl->l_pid);
}
break;
case TARGET_F_SETLK:
case TARGET_F_SETLKW:
- lock_user_struct(target_fl, arg, 1);
- fl.l_type = tswap16(target_fl->l_type);
- fl.l_whence = tswap16(target_fl->l_whence);
- fl.l_start = tswapl(target_fl->l_start);
- fl.l_len = tswapl(target_fl->l_len);
- fl.l_pid = tswapl(target_fl->l_pid);
- unlock_user_struct(target_fl, arg, 0);
+ if( !access_ok(VERIFY_READ,target_fl,sizeof(struct target_flock)) ) return -EFAULT;
+ __get_user(fl.l_type, &target_fl->l_type);
+ __get_user(fl.l_whence, &target_fl->l_whence);
+ __get_user(fl.l_start, &target_fl->l_start);
+ __get_user(fl.l_len, &target_fl->l_len);
ret = fcntl(fd, cmd, &fl);
break;
case TARGET_F_GETLK64:
- lock_user_struct(target_fl64, arg, 1);
- fl64.l_type = tswap16(target_fl64->l_type) >> 1;
- fl64.l_whence = tswap16(target_fl64->l_whence);
- fl64.l_start = tswapl(target_fl64->l_start);
- fl64.l_len = tswapl(target_fl64->l_len);
- fl64.l_pid = tswap16(target_fl64->l_pid);
- unlock_user_struct(target_fl64, arg, 0);
+ if( !access_ok(VERIFY_READ,target_fl64,sizeof(struct target_flock64)) ) return -EFAULT;
+ __get_user(fl64.l_type, &target_fl64->l_type);
+ fl64.l_type >>= 1;
+ __get_user(fl64.l_whence, &target_fl64->l_whence);
+ __get_user(fl64.l_start, &target_fl64->l_start);
+ __get_user(fl64.l_len, &target_fl64->l_len);
+ __get_user(fl64.l_pid, &target_fl64->l_pid);
ret = fcntl(fd, cmd >> 1, &fl64);
if (ret == 0) {
- lock_user_struct(target_fl64, arg, 0);
- target_fl64->l_type = tswap16(fl64.l_type) >> 1;
- target_fl64->l_whence = tswap16(fl64.l_whence);
- target_fl64->l_start = tswapl(fl64.l_start);
- target_fl64->l_len = tswapl(fl64.l_len);
- target_fl64->l_pid = tswapl(fl64.l_pid);
- unlock_user_struct(target_fl64, arg, 1);
+ if( !access_ok(VERIFY_WRITE,target_fl64,sizeof(struct target_flock64)) ) return -EFAULT;
+ __put_user(fl64.l_type, &target_fl64->l_type);
+ target_fl64->l_type >>= 1;
+ __put_user(fl64.l_whence, &target_fl64->l_whence);
+ __put_user(fl64.l_start, &target_fl64->l_start);
+ __put_user(fl64.l_len, &target_fl64->l_len);
+ __put_user(fl64.l_pid, &target_fl64->l_pid);
}
- break;
+ break;
case TARGET_F_SETLK64:
case TARGET_F_SETLKW64:
- lock_user_struct(target_fl64, arg, 1);
- fl64.l_type = tswap16(target_fl64->l_type) >> 1;
- fl64.l_whence = tswap16(target_fl64->l_whence);
- fl64.l_start = tswapl(target_fl64->l_start);
- fl64.l_len = tswapl(target_fl64->l_len);
- fl64.l_pid = tswap16(target_fl64->l_pid);
- unlock_user_struct(target_fl64, arg, 0);
- ret = fcntl(fd, cmd >> 1, &fl64);
+ if( !access_ok(VERIFY_READ,target_fl64,sizeof(struct target_flock64)) ) return -EFAULT;
+ __get_user(fl64.l_type, &target_fl64->l_type);
+ fl64.l_type >>= 1;
+ __get_user(fl64.l_whence, &target_fl64->l_whence);
+ __get_user(fl64.l_start, &target_fl64->l_start);
+ __get_user(fl64.l_len, &target_fl64->l_len);
+ __get_user(fl64.l_pid, &target_fl64->l_pid);
+ ret = fcntl(fd, cmd >> 1, &fl64);
break;
case F_GETFL:
reply other threads:[~2007-09-19 1:25 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.0709182123530.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).