1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c
index 8abb1dd..c2c3a65 100644
--- a/bsd-user/elfload.c
+++ b/bsd-user/elfload.c
@@ -798,6 +798,7 @@ static abi_ulong setup_arg_pages(abi_ulong p, struct bsd_binprm *bprm,
p -= roundup(execpath_len, sizeof(abi_ulong));
/* XXX - check return value of memcpy_to_target() */
memcpy_to_target(p, execpath, execpath_len);
+ strlcpy(target_proc_pathname, execpath, execpath_len);
}
/* Add canary for SSP. */
diff --git a/bsd-user/main.c b/bsd-user/main.c
index bb614de..b6aaa7e 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -62,6 +62,7 @@ unsigned long x86_stack_size = 512 * 1024;
static void save_proc_pathname(void);
char qemu_proc_pathname[PATH_MAX];
+char target_proc_pathname[PATH_MAX];
#ifdef __FreeBSD__
static void
diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index 110b54e..d51f50c 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -224,6 +224,7 @@ void mmap_fork_end(int child);
/* main.c */
extern unsigned long x86_stack_size;
extern char qemu_proc_pathname[];
+extern char target_proc_pathname[];
/* user access */
diff --git a/bsd-user/syscall.c b/bsd-user/syscall.c
index 74b5c86..636083a 100644
--- a/bsd-user/syscall.c
+++ b/bsd-user/syscall.c
@@ -485,8 +485,6 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, abi_ulong ol
abi_ulong oldlen = 0;
int32_t *snamep = g_malloc(sizeof(int32_t) * namelen), *p, *q, i;
uint32_t kind = 0;
- abi_ulong argv, argv0;
- char *fullpath = NULL;
if (oldlenp)
if (get_user_ual(oldlen, oldlenp))
@@ -533,30 +531,14 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, abi_ulong ol
case KERN_PROC:
switch(snamep[2]) {
case KERN_PROC_PATHNAME:
- if (get_user_ual(argv, TARGET_PS_STRINGS)) {
- ret = -TARGET_EFAULT;
- goto out;
- }
- if (get_user_ual(argv0, argv)) {
- ret = -TARGET_EFAULT;
- goto out;
- }
-
- fullpath = realpath(g2h(argv0), NULL);
- if (NULL == fullpath)
- fullpath = (char *)g2h(argv0);
- holdlen = strlen(fullpath) + 1;
+ holdlen = strlen(target_proc_pathname) + 1;
if (holdp) {
if (oldlen < holdlen) {
ret = -TARGET_EINVAL;
goto out;
}
- if (!access_ok(VERIFY_WRITE, argv0,
- holdlen)) {
- ret = -TARGET_EFAULT;
- goto out;
- }
- strlcpy(holdp, fullpath, oldlen);
+ strlcpy(holdp, target_proc_pathname,
+ oldlen);
}
ret = 0;
goto out;
@@ -597,8 +579,6 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, abi_ulong ol
#endif
out:
- if (fullpath)
- free(fullpath);
if (oldlenp)
put_user_ual(holdlen, oldlenp);
unlock_user(hnamep, namep, 0);
|