Browse Source

Fix decoding of getgroups, getgroups32, setgroups, and setgroups32 syscalls

Convert parsers of these syscalls to the same scheme as were applied to
parsers of other uid/gid related syscalls.
That is, define two sets of parsers on architectures that support
(either directly or via multiarch) 16-bit and 32-bit gid getgroups
and setgroups syscalls simultaneously, and reuse essentially the same
code by parametrizing uid_t and names of parser functions.

* groups.c: Remove.
(sys_getgroups, sys_setgroups): Move ...
* uid.c: ... here and parametrize their names.
* Makefile.am (strace_SOURCES): Remove groups.c.
* linux/syscall.h (sys_getgroups32, sys_setgroups32): Remove.
[NEED_UID16_PARSERS] (sys_getgroups16, sys_setgroups16): New prototypes.
* linux/arm/syscallent.h: Rename sys_[gs]etgroups to sys_[gs]etgroups16,
rename sys_[gs]etgroups32 to sys_[gs]etgroups.
* linux/bfin/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/s390/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.
* tests/uid.c: Test for getgroups.
* tests/uid16.c: Likewise.
* tests/uid32.c: Test for getgroups32.
* tests/uid.awk: Test for getgroups/getgroups32 decoding.
* tests/uid.test: Trace getgroups/getgroups32 syscalls.
Dmitry V. Levin 5 years ago
parent
commit
530bed0ca8

+ 0
- 1
Makefile.am View File

@@ -41,7 +41,6 @@ strace_SOURCES =	\
41 41
 	get_robust_list.c \
42 42
 	getcpu.c	\
43 43
 	getcwd.c	\
44
-	groups.c	\
45 44
 	hostname.c	\
46 45
 	inotify.c	\
47 46
 	io.c		\

+ 0
- 237
groups.c View File

@@ -1,237 +0,0 @@
1
-#include "defs.h"
2
-
3
-#include <asm/posix_types.h>
4
-#undef GETGROUPS_T
5
-#define GETGROUPS_T __kernel_gid_t
6
-#undef GETGROUPS32_T
7
-#define GETGROUPS32_T __kernel_gid32_t
8
-
9
-int
10
-sys_setgroups(struct tcb *tcp)
11
-{
12
-	if (entering(tcp)) {
13
-		unsigned long len, size, start, cur, end, abbrev_end;
14
-		GETGROUPS_T gid;
15
-		int failed = 0;
16
-
17
-		len = tcp->u_arg[0];
18
-		tprintf("%lu, ", len);
19
-		if (len == 0) {
20
-			tprints("[]");
21
-			return 0;
22
-		}
23
-		start = tcp->u_arg[1];
24
-		if (start == 0) {
25
-			tprints("NULL");
26
-			return 0;
27
-		}
28
-		size = len * sizeof(gid);
29
-		end = start + size;
30
-		if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
31
-			tprintf("%#lx", start);
32
-			return 0;
33
-		}
34
-		if (abbrev(tcp)) {
35
-			abbrev_end = start + max_strlen * sizeof(gid);
36
-			if (abbrev_end < start)
37
-				abbrev_end = end;
38
-		} else {
39
-			abbrev_end = end;
40
-		}
41
-		tprints("[");
42
-		for (cur = start; cur < end; cur += sizeof(gid)) {
43
-			if (cur > start)
44
-				tprints(", ");
45
-			if (cur >= abbrev_end) {
46
-				tprints("...");
47
-				break;
48
-			}
49
-			if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
50
-				tprints("?");
51
-				failed = 1;
52
-				break;
53
-			}
54
-			tprintf("%lu", (unsigned long) gid);
55
-		}
56
-		tprints("]");
57
-		if (failed)
58
-			tprintf(" %#lx", tcp->u_arg[1]);
59
-	}
60
-	return 0;
61
-}
62
-
63
-int
64
-sys_getgroups(struct tcb *tcp)
65
-{
66
-	unsigned long len;
67
-
68
-	if (entering(tcp)) {
69
-		len = tcp->u_arg[0];
70
-		tprintf("%lu, ", len);
71
-	} else {
72
-		unsigned long size, start, cur, end, abbrev_end;
73
-		GETGROUPS_T gid;
74
-		int failed = 0;
75
-
76
-		len = tcp->u_rval;
77
-		if (len == 0) {
78
-			tprints("[]");
79
-			return 0;
80
-		}
81
-		start = tcp->u_arg[1];
82
-		if (start == 0) {
83
-			tprints("NULL");
84
-			return 0;
85
-		}
86
-		if (tcp->u_arg[0] == 0) {
87
-			tprintf("%#lx", start);
88
-			return 0;
89
-		}
90
-		size = len * sizeof(gid);
91
-		end = start + size;
92
-		if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
93
-		    size / sizeof(gid) != len || end < start) {
94
-			tprintf("%#lx", start);
95
-			return 0;
96
-		}
97
-		if (abbrev(tcp)) {
98
-			abbrev_end = start + max_strlen * sizeof(gid);
99
-			if (abbrev_end < start)
100
-				abbrev_end = end;
101
-		} else {
102
-			abbrev_end = end;
103
-		}
104
-		tprints("[");
105
-		for (cur = start; cur < end; cur += sizeof(gid)) {
106
-			if (cur > start)
107
-				tprints(", ");
108
-			if (cur >= abbrev_end) {
109
-				tprints("...");
110
-				break;
111
-			}
112
-			if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
113
-				tprints("?");
114
-				failed = 1;
115
-				break;
116
-			}
117
-			tprintf("%lu", (unsigned long) gid);
118
-		}
119
-		tprints("]");
120
-		if (failed)
121
-			tprintf(" %#lx", tcp->u_arg[1]);
122
-	}
123
-	return 0;
124
-}
125
-
126
-int
127
-sys_setgroups32(struct tcb *tcp)
128
-{
129
-	if (entering(tcp)) {
130
-		unsigned long len, size, start, cur, end, abbrev_end;
131
-		GETGROUPS32_T gid;
132
-		int failed = 0;
133
-
134
-		len = tcp->u_arg[0];
135
-		tprintf("%lu, ", len);
136
-		if (len == 0) {
137
-			tprints("[]");
138
-			return 0;
139
-		}
140
-		start = tcp->u_arg[1];
141
-		if (start == 0) {
142
-			tprints("NULL");
143
-			return 0;
144
-		}
145
-		size = len * sizeof(gid);
146
-		end = start + size;
147
-		if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
148
-			tprintf("%#lx", start);
149
-			return 0;
150
-		}
151
-		if (abbrev(tcp)) {
152
-			abbrev_end = start + max_strlen * sizeof(gid);
153
-			if (abbrev_end < start)
154
-				abbrev_end = end;
155
-		} else {
156
-			abbrev_end = end;
157
-		}
158
-		tprints("[");
159
-		for (cur = start; cur < end; cur += sizeof(gid)) {
160
-			if (cur > start)
161
-				tprints(", ");
162
-			if (cur >= abbrev_end) {
163
-				tprints("...");
164
-				break;
165
-			}
166
-			if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
167
-				tprints("?");
168
-				failed = 1;
169
-				break;
170
-			}
171
-			tprintf("%lu", (unsigned long) gid);
172
-		}
173
-		tprints("]");
174
-		if (failed)
175
-			tprintf(" %#lx", tcp->u_arg[1]);
176
-	}
177
-	return 0;
178
-}
179
-
180
-int
181
-sys_getgroups32(struct tcb *tcp)
182
-{
183
-	unsigned long len;
184
-
185
-	if (entering(tcp)) {
186
-		len = tcp->u_arg[0];
187
-		tprintf("%lu, ", len);
188
-	} else {
189
-		unsigned long size, start, cur, end, abbrev_end;
190
-		GETGROUPS32_T gid;
191
-		int failed = 0;
192
-
193
-		len = tcp->u_rval;
194
-		if (len == 0) {
195
-			tprints("[]");
196
-			return 0;
197
-		}
198
-		start = tcp->u_arg[1];
199
-		if (start == 0) {
200
-			tprints("NULL");
201
-			return 0;
202
-		}
203
-		size = len * sizeof(gid);
204
-		end = start + size;
205
-		if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
206
-		    size / sizeof(gid) != len || end < start) {
207
-			tprintf("%#lx", start);
208
-			return 0;
209
-		}
210
-		if (abbrev(tcp)) {
211
-			abbrev_end = start + max_strlen * sizeof(gid);
212
-			if (abbrev_end < start)
213
-				abbrev_end = end;
214
-		} else {
215
-			abbrev_end = end;
216
-		}
217
-		tprints("[");
218
-		for (cur = start; cur < end; cur += sizeof(gid)) {
219
-			if (cur > start)
220
-				tprints(", ");
221
-			if (cur >= abbrev_end) {
222
-				tprints("...");
223
-				break;
224
-			}
225
-			if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
226
-				tprints("?");
227
-				failed = 1;
228
-				break;
229
-			}
230
-			tprintf("%lu", (unsigned long) gid);
231
-		}
232
-		tprints("]");
233
-		if (failed)
234
-			tprintf(" %#lx", tcp->u_arg[1]);
235
-	}
236
-	return 0;
237
-}

+ 4
- 4
linux/arm/syscallent.h View File

@@ -106,8 +106,8 @@
106 106
 	{ 2,	0,	sys_getrusage,		"getrusage"	}, /* 77 */
107 107
 	{ 2,	0,	sys_gettimeofday,	"gettimeofday"	}, /* 78 */
108 108
 	{ 2,	0,	sys_settimeofday,	"settimeofday"	}, /* 79 */
109
-	{ 2,	0,	sys_getgroups,		"getgroups"	}, /* 80 */
110
-	{ 2,	0,	sys_setgroups,		"setgroups"	}, /* 81 */
109
+	{ 2,	0,	sys_getgroups16,	"getgroups"	}, /* 80 */
110
+	{ 2,	0,	sys_setgroups16,	"setgroups"	}, /* 81 */
111 111
 	{ 1,	TD,	sys_oldselect,		"oldselect"	}, /* 82 */
112 112
 	{ 2,	TF,	sys_symlink,		"symlink"	}, /* 83 */
113 113
 	{ 2,	TF,	sys_oldlstat,		"oldlstat"	}, /* 84 */
@@ -233,8 +233,8 @@
233 233
 	{ 0,	NF,	sys_geteuid,		"getegid32"	}, /* 202 */
234 234
 	{ 2,	0,	sys_setreuid,		"setreuid32"	}, /* 203 */
235 235
 	{ 2,	0,	sys_setregid,		"setregid32"	}, /* 204 */
236
-	{ 2,	0,	sys_getgroups32,	"getgroups32"	}, /* 205 */
237
-	{ 2,	0,	sys_setgroups32,	"setgroups32"	}, /* 206 */
236
+	{ 2,	0,	sys_getgroups,		"getgroups32"	}, /* 205 */
237
+	{ 2,	0,	sys_setgroups,		"setgroups32"	}, /* 206 */
238 238
 	{ 3,	TD,	sys_fchown,		"fchown32"	}, /* 207 */
239 239
 	{ 3,	0,	sys_setresuid,		"setresuid32"	}, /* 208 */
240 240
 	{ 3,	0,	sys_getresuid,		"getresuid32"	}, /* 209 */

+ 4
- 4
linux/bfin/syscallent.h View File

@@ -106,8 +106,8 @@
106 106
 	{ 2,	0,	sys_getrusage,		"getrusage"	}, /* 77 */
107 107
 	{ 2,	0,	sys_gettimeofday,	"gettimeofday"	}, /* 78 */
108 108
 	{ 2,	0,	sys_settimeofday,	"settimeofday"	}, /* 79 */
109
-	{ 2,	0,	sys_getgroups,		"getgroups"	}, /* 80 */
110
-	{ 2,	0,	sys_setgroups,		"setgroups"	}, /* 81 */
109
+	{ 2,	0,	sys_getgroups16,	"getgroups"	}, /* 80 */
110
+	{ 2,	0,	sys_setgroups16,	"setgroups"	}, /* 81 */
111 111
 	{ 1,	TD,	sys_oldselect,		"oldselect"	}, /* 82 */
112 112
 	{ 2,	TF,	sys_symlink,		"symlink"	}, /* 83 */
113 113
 	{ 2,	TF,	sys_oldlstat,		"oldlstat"	}, /* 84 */
@@ -231,8 +231,8 @@
231 231
 	{ 0,	NF,	sys_geteuid,		"getegid32"	}, /* 202 */
232 232
 	{ 2,	0,	sys_setreuid,		"setreuid32"	}, /* 203 */
233 233
 	{ 2,	0,	sys_setregid,		"setregid32"	}, /* 204 */
234
-	{ 2,	0,	sys_getgroups32,	"getgroups32"	}, /* 205 */
235
-	{ 2,	0,	sys_setgroups32,	"setgroups32"	}, /* 206 */
234
+	{ 2,	0,	sys_getgroups,		"getgroups32"	}, /* 205 */
235
+	{ 2,	0,	sys_setgroups,		"setgroups32"	}, /* 206 */
236 236
 	{ 3,	TD,	sys_fchown,		"fchown32"	}, /* 207 */
237 237
 	{ 3,	0,	sys_setresuid,		"setresuid32"	}, /* 208 */
238 238
 	{ 3,	0,	sys_getresuid,		"getresuid32"	}, /* 209 */

+ 4
- 4
linux/i386/syscallent.h View File

@@ -106,8 +106,8 @@
106 106
 	{ 2,	0,	sys_getrusage,		"getrusage"	}, /* 77 */
107 107
 	{ 2,	0,	sys_gettimeofday,	"gettimeofday"	}, /* 78 */
108 108
 	{ 2,	0,	sys_settimeofday,	"settimeofday"	}, /* 79 */
109
-	{ 2,	0,	sys_getgroups,		"getgroups"	}, /* 80 */
110
-	{ 2,	0,	sys_setgroups,		"setgroups"	}, /* 81 */
109
+	{ 2,	0,	sys_getgroups16,	"getgroups"	}, /* 80 */
110
+	{ 2,	0,	sys_setgroups16,	"setgroups"	}, /* 81 */
111 111
 	{ 1,	TD,	sys_oldselect,		"oldselect"	}, /* 82 */
112 112
 	{ 2,	TF,	sys_symlink,		"symlink"	}, /* 83 */
113 113
 	{ 2,	TF,	sys_oldlstat,		"oldlstat"	}, /* 84 */
@@ -233,8 +233,8 @@
233 233
 	{ 0,	NF,	sys_getegid,		"getegid32"	}, /* 202 */
234 234
 	{ 2,	0,	sys_setreuid,		"setreuid32"	}, /* 203 */
235 235
 	{ 2,	0,	sys_setregid,		"setregid32"	}, /* 204 */
236
-	{ 2,	0,	sys_getgroups32,	"getgroups32"	}, /* 205 */
237
-	{ 2,	0,	sys_setgroups32,	"setgroups32"	}, /* 206 */
236
+	{ 2,	0,	sys_getgroups,		"getgroups32"	}, /* 205 */
237
+	{ 2,	0,	sys_setgroups,		"setgroups32"	}, /* 206 */
238 238
 	{ 3,	TD,	sys_fchown,		"fchown32"	}, /* 207 */
239 239
 	{ 3,	0,	sys_setresuid,		"setresuid32"	}, /* 208 */
240 240
 	{ 3,	0,	sys_getresuid,		"getresuid32"	}, /* 209 */

+ 4
- 4
linux/m68k/syscallent.h View File

@@ -106,8 +106,8 @@
106 106
 	{ 2,	0,	sys_getrusage,		"getrusage"	}, /* 77 */
107 107
 	{ 2,	0,	sys_gettimeofday,	"gettimeofday"	}, /* 78 */
108 108
 	{ 2,	0,	sys_settimeofday,	"settimeofday"	}, /* 79 */
109
-	{ 2,	0,	sys_getgroups,		"getgroups"	}, /* 80 */
110
-	{ 2,	0,	sys_setgroups,		"setgroups"	}, /* 81 */
109
+	{ 2,	0,	sys_getgroups16,	"getgroups"	}, /* 80 */
110
+	{ 2,	0,	sys_setgroups16,	"setgroups"	}, /* 81 */
111 111
 	{ 1,	TD,	sys_oldselect,		"oldselect"	}, /* 82 */
112 112
 	{ 2,	TF,	sys_symlink,		"symlink"	}, /* 83 */
113 113
 	{ 2,	TF,	sys_oldlstat,		"oldlstat"	}, /* 84 */
@@ -231,8 +231,8 @@
231 231
 	{ 0,	NF,	sys_geteuid,		"getegid32"	}, /* 202 */
232 232
 	{ 2,	0,	sys_setreuid,		"setreuid32"	}, /* 203 */
233 233
 	{ 2,	0,	sys_setregid,		"setregid32"	}, /* 204 */
234
-	{ 2,	0,	sys_getgroups32,	"getgroups32"	}, /* 205 */
235
-	{ 2,	0,	sys_setgroups32,	"setgroups32"	}, /* 206 */
234
+	{ 2,	0,	sys_getgroups,		"getgroups32"	}, /* 205 */
235
+	{ 2,	0,	sys_setgroups,		"setgroups32"	}, /* 206 */
236 236
 	{ 3,	TD,	sys_fchown,		"fchown32"	}, /* 207 */
237 237
 	{ 3,	0,	sys_setresuid,		"setresuid32"	}, /* 208 */
238 238
 	{ 3,	0,	sys_getresuid,		"getresuid32"	}, /* 209 */

+ 4
- 4
linux/microblaze/syscallent.h View File

@@ -106,8 +106,8 @@
106 106
 	{ 2,	0,	sys_getrusage,		"getrusage"	}, /* 77 */
107 107
 	{ 2,	0,	sys_gettimeofday,	"gettimeofday"	}, /* 78 */
108 108
 	{ 2,	0,	sys_settimeofday,	"settimeofday"	}, /* 79 */
109
-	{ 2,	0,	sys_getgroups,		"getgroups"	}, /* 80 */
110
-	{ 2,	0,	sys_setgroups,		"setgroups"	}, /* 81 */
109
+	{ 2,	0,	sys_getgroups16,	"getgroups"	}, /* 80 */
110
+	{ 2,	0,	sys_setgroups16,	"setgroups"	}, /* 81 */
111 111
 	{ 1,	TD,	sys_oldselect,		"oldselect"	}, /* 82 */
112 112
 	{ 2,	TF,	sys_symlink,		"symlink"	}, /* 83 */
113 113
 	{ 2,	TF,	sys_oldlstat,		"oldlstat"	}, /* 84 */
@@ -231,8 +231,8 @@
231 231
 	{ 0,	NF,	sys_geteuid,		"getegid32"	}, /* 202 */
232 232
 	{ 2,	0,	sys_setreuid,		"setreuid32"	}, /* 203 */
233 233
 	{ 2,	0,	sys_setregid,		"setregid32"	}, /* 204 */
234
-	{ 2,	0,	sys_getgroups32,	"getgroups32"	}, /* 205 */
235
-	{ 2,	0,	sys_setgroups32,	"setgroups32"	}, /* 206 */
234
+	{ 2,	0,	sys_getgroups,		"getgroups32"	}, /* 205 */
235
+	{ 2,	0,	sys_setgroups,		"setgroups32"	}, /* 206 */
236 236
 	{ 3,	TD,	sys_fchown,		"fchown32"	}, /* 207 */
237 237
 	{ 3,	0,	sys_setresuid,		"setresuid32"	}, /* 208 */
238 238
 	{ 3,	0,	sys_getresuid,		"getresuid32"	}, /* 209 */

+ 2
- 2
linux/s390/syscallent.h View File

@@ -108,8 +108,8 @@
108 108
 	{ 2,	0,	sys_getrusage,		"getrusage"	}, /* 77 */
109 109
 	{ 2,	0,	sys_gettimeofday,	"gettimeofday"	}, /* 78 */
110 110
 	{ 2,	0,	sys_settimeofday,	"settimeofday"	}, /* 79 */
111
-	{ 2,	0,	sys_getgroups,		"getgroups"	}, /* 80 */
112
-	{ 2,	0,	sys_setgroups,		"setgroups"	}, /* 81 */
111
+	{ 2,	0,	sys_getgroups16,	"getgroups"	}, /* 80 */
112
+	{ 2,	0,	sys_setgroups16,	"setgroups"	}, /* 81 */
113 113
 	{ MA,	0,	NULL,			NULL		}, /* 82 */
114 114
 	{ 2,	TF,	sys_symlink,		"symlink"	}, /* 83 */
115 115
 	{ MA,	0,	NULL,			NULL		}, /* 84 */

+ 4
- 4
linux/sh/syscallent.h View File

@@ -108,8 +108,8 @@
108 108
 	{ 2,	0,	sys_getrusage,		"getrusage"	}, /* 77 */
109 109
 	{ 2,	0,	sys_gettimeofday,	"gettimeofday"	}, /* 78 */
110 110
 	{ 2,	0,	sys_settimeofday,	"settimeofday"	}, /* 79 */
111
-	{ 2,	0,	sys_getgroups,		"getgroups"	}, /* 80 */
112
-	{ 2,	0,	sys_setgroups,		"setgroups"	}, /* 81 */
111
+	{ 2,	0,	sys_getgroups16,	"getgroups"	}, /* 80 */
112
+	{ 2,	0,	sys_setgroups16,	"setgroups"	}, /* 81 */
113 113
 	{ 1,	TD,	sys_oldselect,		"oldselect"	}, /* 82 */
114 114
 	{ 2,	TF,	sys_symlink,		"symlink"	}, /* 83 */
115 115
 	{ 2,	TF,	sys_oldlstat,		"oldlstat"	}, /* 84 */
@@ -233,8 +233,8 @@
233 233
 	{ 0,	0,	sys_getegid,		"getegid32"	}, /* 202 */
234 234
 	{ 2,	0,	sys_setreuid,		"setreuid32"	}, /* 203 */
235 235
 	{ 2,	0,	sys_setregid,		"setregid32"	}, /* 204 */
236
-	{ 2,	0,	sys_getgroups32,	"getgroups32"	}, /* 205 */
237
-	{ 2,	0,	sys_setgroups32,	"setgroups32"	}, /* 206 */
236
+	{ 2,	0,	sys_getgroups,		"getgroups32"	}, /* 205 */
237
+	{ 2,	0,	sys_setgroups,		"setgroups32"	}, /* 206 */
238 238
 	{ 3,	0,	sys_fchown,		"fchown32"	}, /* 207 */
239 239
 	{ 3,	0,	sys_setresuid,		"setresuid32"	}, /* 208 */
240 240
 	{ 3,	0,	sys_getresuid,		"getresuid32"	}, /* 209 */

+ 4
- 4
linux/sh64/syscallent.h View File

@@ -106,8 +106,8 @@
106 106
 	{ 2,	0,	sys_getrusage,		"getrusage"	}, /* 77 */
107 107
 	{ 2,	0,	sys_gettimeofday,	"gettimeofday"	}, /* 78 */
108 108
 	{ 2,	0,	sys_settimeofday,	"settimeofday"	}, /* 79 */
109
-	{ 2,	0,	sys_getgroups,		"getgroups"	}, /* 80 */
110
-	{ 2,	0,	sys_setgroups,		"setgroups"	}, /* 81 */
109
+	{ 2,	0,	sys_getgroups16,	"getgroups"	}, /* 80 */
110
+	{ 2,	0,	sys_setgroups16,	"setgroups"	}, /* 81 */
111 111
 	{ 1,	TD,	sys_oldselect,		"oldselect"	}, /* 82 */
112 112
 	{ 2,	TF,	sys_symlink,		"symlink"	}, /* 83 */
113 113
 	{ 2,	TF,	sys_oldlstat,		"oldlstat"	}, /* 84 */
@@ -231,8 +231,8 @@
231 231
 	{ 0,	0,	sys_getegid,		"getegid32"	}, /* 202 */
232 232
 	{ 2,	0,	sys_setreuid,		"setreuid32"	}, /* 203 */
233 233
 	{ 2,	0,	sys_setregid,		"setregid32"	}, /* 204 */
234
-	{ 2,	0,	sys_getgroups32,	"getgroups32"	}, /* 205 */
235
-	{ 2,	0,	sys_setgroups32,	"setgroups32"	}, /* 206 */
234
+	{ 2,	0,	sys_getgroups,		"getgroups32"	}, /* 205 */
235
+	{ 2,	0,	sys_setgroups,		"setgroups32"	}, /* 206 */
236 236
 	{ 3,	0,	sys_fchown,		"fchown32"	}, /* 207 */
237 237
 	{ 3,	0,	sys_setresuid,		"setresuid32"	}, /* 208 */
238 238
 	{ 3,	0,	sys_getresuid,		"getresuid32"	}, /* 209 */

+ 4
- 4
linux/sparc/syscallent.h View File

@@ -77,10 +77,10 @@
77 77
 	{ 0,	0,	sys_vhangup,	"vhangup" },		/* 76 */
78 78
 	{ 3,	TF,	sys_truncate64,	"truncate64" },		/* 77 */
79 79
 	{ 3,	TM,	sys_mincore,	"mincore" },		/* 78 */
80
-	{ 2,	0,	sys_getgroups,	"getgroups" },		/* 79 */
81
-	{ 2,	0,	sys_setgroups,	"setgroups" },		/* 80 */
80
+	{ 2,	0,	sys_getgroups16,"getgroups" },		/* 79 */
81
+	{ 2,	0,	sys_setgroups16,"setgroups" },		/* 80 */
82 82
 	{ 0,	0,	sys_getpgrp,	"getpgrp" },		/* 81 */
83
-	{ 2,	0,	sys_setgroups32,"setgroups32" },	/* 82 */
83
+	{ 2,	0,	sys_setgroups,	"setgroups32" },	/* 82 */
84 84
 	{ 3,	0,	sys_setitimer,	"setitimer" },		/* 83 */
85 85
 	{ 3,	TD,	sys_ftruncate64,"ftruncate64" },	/* 84 */
86 86
 	{ 2,	TF,	sys_swapon,	"swapon" },		/* 85 */
@@ -113,7 +113,7 @@
113 113
 	{ 2,	0,	sys_setregid,	"setregid32" },		/* 112 */
114 114
 	{ 3,	TN,	sys_recvmsg,	"recvmsg" },		/* 113 */
115 115
 	{ 3,	TN,	sys_sendmsg,	"sendmsg" },		/* 114 */
116
-	{ 2,	0,	sys_getgroups32,"getgroups32" },	/* 115 */
116
+	{ 2,	0,	sys_getgroups,	"getgroups32" },	/* 115 */
117 117
 	{ 2,	0,	sys_gettimeofday,"gettimeofday" },	/* 116 */
118 118
 	{ 2,	0,	sys_getrusage,	"getrusage" },		/* 117 */
119 119
 	{ 5,	TN,	sys_getsockopt,	"getsockopt" },		/* 118 */

+ 2
- 2
linux/syscall.h View File

@@ -100,7 +100,6 @@ int sys_getdents();
100 100
 int sys_getdents64();
101 101
 int sys_getdtablesize();
102 102
 int sys_getgroups();
103
-int sys_getgroups32();
104 103
 int sys_gethostname();
105 104
 int sys_getitimer();
106 105
 int sys_getpmsg(); /* TODO: non-Linux, remove? */
@@ -237,7 +236,6 @@ int sys_set_mempolicy();
237 236
 int sys_set_thread_area();
238 237
 int sys_setfsuid();
239 238
 int sys_setgroups();
240
-int sys_setgroups32();
241 239
 int sys_sethostname();
242 240
 int sys_setitimer();
243 241
 int sys_setns();
@@ -357,9 +355,11 @@ int sys_putmsg();
357 355
 #if NEED_UID16_PARSERS
358 356
 int sys_chown16();
359 357
 int sys_fchown16();
358
+int sys_getgroups16();
360 359
 int sys_getresuid16();
361 360
 int sys_getuid16();
362 361
 int sys_setfsuid16();
362
+int sys_setgroups16();
363 363
 int sys_setresuid16();
364 364
 int sys_setreuid16();
365 365
 int sys_setuid16();

+ 14
- 0
tests/uid.awk View File

@@ -35,6 +35,20 @@ regexp == "" {
35 35
         regexp = "^chown" suffix "\\(\".\", -1, -1\\)[[:space:]]+= 0$"
36 36
         next
37 37
       case "chown":
38
+        expected = "1st getgroups"
39
+        regexp = "^getgroups" suffix "\\(0, NULL\\)[[:space:]]+= " r_uint "$"
40
+        next
41
+      case "1st getgroups":
42
+        ngroups = a[1]
43
+        switch (ngroups) {
44
+          case "0": list=""; break
45
+          case "1": list=r_uint; break
46
+          default: list=r_uint "(, " r_uint "){" (ngroups - 1) "}"
47
+        }
48
+        expected = "2nd getgroups"
49
+        regexp = "^getgroups" suffix "\\(" ngroups ", \\[" list "\\]\\)[[:space:]]+= " ngroups "$"
50
+        next
51
+      case "2nd getgroups":
38 52
         expected = "the last line"
39 53
         regexp = "^\\+\\+\\+ exited with 0 \\+\\+\\+$"
40 54
         next

+ 9
- 2
tests/uid.c View File

@@ -2,6 +2,7 @@
2 2
 # include "config.h"
3 3
 #endif
4 4
 #include <assert.h>
5
+#include <stdlib.h>
5 6
 #include <unistd.h>
6 7
 #include <sys/syscall.h>
7 8
 
@@ -13,8 +14,11 @@ main(void)
13 14
  && defined(__NR_getresuid) \
14 15
  && defined(__NR_setreuid) \
15 16
  && defined(__NR_setresuid) \
16
- && defined(__NR_chown)
17
-	uid_t r, e, s;
17
+ && defined(__NR_chown) \
18
+ && defined(__NR_getgroups)
19
+	int r, e, s;
20
+	int size;
21
+	int *list = 0;
18 22
 
19 23
 	e = syscall(__NR_getuid);
20 24
 	assert(syscall(__NR_setuid, e) == 0);
@@ -22,6 +26,9 @@ main(void)
22 26
 	assert(syscall(__NR_setreuid, -1, -1L) == 0);
23 27
 	assert(syscall(__NR_setresuid, -1, e, -1L) == 0);
24 28
 	assert(syscall(__NR_chown, ".", -1, -1L) == 0);
29
+	assert((size = syscall(__NR_getgroups, 0, list)) >= 0);
30
+	assert(list = calloc(size + 1, sizeof(*list)));
31
+	assert(syscall(__NR_getgroups, size, list) == size);
25 32
 	return 0;
26 33
 #else
27 34
 	return 77;

+ 1
- 1
tests/uid.test View File

@@ -17,7 +17,7 @@ uid="uid$s$w"
17 17
 	fi
18 18
 }
19 19
 
20
-syscalls="getuid$s,setuid$s,getresuid$s,setreuid$s,setresuid$s,chown$s"
20
+syscalls="getuid$s,setuid$s,getresuid$s,setreuid$s,setresuid$s,chown$s,getgroups$s"
21 21
 args="-e trace=$syscalls"
22 22
 $STRACE -o "$LOG" $args ./"$uid"|| {
23 23
 	cat "$LOG"

+ 10
- 1
tests/uid16.c View File

@@ -2,6 +2,7 @@
2 2
 # include "config.h"
3 3
 #endif
4 4
 #include <assert.h>
5
+#include <stdlib.h>
5 6
 #include <unistd.h>
6 7
 #include <sys/syscall.h>
7 8
 
@@ -14,6 +15,7 @@ main(void)
14 15
  && defined(__NR_setreuid) \
15 16
  && defined(__NR_setresuid) \
16 17
  && defined(__NR_chown) \
18
+ && defined(__NR_getgroups) \
17 19
  \
18 20
  && defined(__NR_getuid32) \
19 21
  && defined(__NR_setuid32) \
@@ -21,6 +23,7 @@ main(void)
21 23
  && defined(__NR_setreuid32) \
22 24
  && defined(__NR_setresuid32) \
23 25
  && defined(__NR_chown32) \
26
+ && defined(__NR_getgroups32) \
24 27
  \
25 28
  && __NR_getuid != __NR_getuid32 \
26 29
  && __NR_setuid != __NR_setuid32 \
@@ -28,8 +31,11 @@ main(void)
28 31
  && __NR_setreuid != __NR_setreuid32 \
29 32
  && __NR_setresuid != __NR_setresuid32 \
30 33
  && __NR_chown != __NR_chown32 \
34
+ && __NR_getgroups != __NR_getgroups32 \
31 35
  /**/
32
-	uid_t r, e, s;
36
+	int r, e, s;
37
+	int size;
38
+	int *list = 0;
33 39
 
34 40
 	e = syscall(__NR_getuid);
35 41
 	assert(syscall(__NR_setuid, e) == 0);
@@ -37,6 +43,9 @@ main(void)
37 43
 	assert(syscall(__NR_setreuid, -1, 0xffff) == 0);
38 44
 	assert(syscall(__NR_setresuid, -1, e, 0xffff) == 0);
39 45
 	assert(syscall(__NR_chown, ".", -1, 0xffff) == 0);
46
+	assert((size = syscall(__NR_getgroups, 0, list)) >= 0);
47
+	assert(list = calloc(size + 1, sizeof(*list)));
48
+	assert(syscall(__NR_getgroups, size, list) == size);
40 49
 	return 0;
41 50
 #else
42 51
 	return 77;

+ 9
- 2
tests/uid32.c View File

@@ -2,6 +2,7 @@
2 2
 # include "config.h"
3 3
 #endif
4 4
 #include <assert.h>
5
+#include <stdlib.h>
5 6
 #include <unistd.h>
6 7
 #include <sys/syscall.h>
7 8
 
@@ -13,8 +14,11 @@ main(void)
13 14
  && defined(__NR_getresuid32) \
14 15
  && defined(__NR_setreuid32) \
15 16
  && defined(__NR_setresuid32) \
16
- && defined(__NR_chown32)
17
-	uid_t r, e, s;
17
+ && defined(__NR_chown32) \
18
+ && defined(__NR_getgroups32)
19
+	int r, e, s;
20
+	int size;
21
+	int *list = 0;
18 22
 
19 23
 	e = syscall(__NR_getuid32);
20 24
 	assert(syscall(__NR_setuid32, e) == 0);
@@ -22,6 +26,9 @@ main(void)
22 26
 	assert(syscall(__NR_setreuid32, -1, -1L) == 0);
23 27
 	assert(syscall(__NR_setresuid32, -1, e, -1L) == 0);
24 28
 	assert(syscall(__NR_chown32, ".", -1, -1L) == 0);
29
+	assert((size = syscall(__NR_getgroups32, 0, list)) >= 0);
30
+	assert(list = calloc(size + 1, sizeof(*list)));
31
+	assert(syscall(__NR_getgroups32, size, list) == size);
25 32
 	return 0;
26 33
 #else
27 34
 	return 77;

+ 121
- 6
uid.c View File

@@ -7,15 +7,17 @@
7 7
 # define SIZEIFY_(x,size)	SIZEIFY__(x,size)
8 8
 # define SIZEIFY__(x,size)	x ## size
9 9
 
10
+# define printuid	SIZEIFY(printuid)
11
+# define sys_chown	SIZEIFY(sys_chown)
12
+# define sys_fchown	SIZEIFY(sys_fchown)
13
+# define sys_getgroups	SIZEIFY(sys_getgroups)
14
+# define sys_getresuid	SIZEIFY(sys_getresuid)
10 15
 # define sys_getuid	SIZEIFY(sys_getuid)
11 16
 # define sys_setfsuid	SIZEIFY(sys_setfsuid)
12
-# define sys_setuid	SIZEIFY(sys_setuid)
13
-# define sys_getresuid	SIZEIFY(sys_getresuid)
14
-# define sys_setreuid	SIZEIFY(sys_setreuid)
17
+# define sys_setgroups	SIZEIFY(sys_setgroups)
15 18
 # define sys_setresuid	SIZEIFY(sys_setresuid)
16
-# define sys_chown	SIZEIFY(sys_chown)
17
-# define sys_fchown	SIZEIFY(sys_fchown)
18
-# define printuid	SIZEIFY(printuid)
19
+# define sys_setreuid	SIZEIFY(sys_setreuid)
20
+# define sys_setuid	SIZEIFY(sys_setuid)
19 21
 #endif /* STRACE_UID_SIZE */
20 22
 
21 23
 #include "defs.h"
@@ -141,4 +143,117 @@ printuid(const char *text, const unsigned int uid)
141 143
 		tprintf("%s%u", text, uid);
142 144
 }
143 145
 
146
+int
147
+sys_setgroups(struct tcb *tcp)
148
+{
149
+	if (entering(tcp)) {
150
+		unsigned long len, size, start, cur, end, abbrev_end;
151
+		uid_t gid;
152
+		int failed = 0;
153
+
154
+		len = tcp->u_arg[0];
155
+		tprintf("%lu, ", len);
156
+		if (len == 0) {
157
+			tprints("[]");
158
+			return 0;
159
+		}
160
+		start = tcp->u_arg[1];
161
+		if (start == 0) {
162
+			tprints("NULL");
163
+			return 0;
164
+		}
165
+		size = len * sizeof(gid);
166
+		end = start + size;
167
+		if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
168
+			tprintf("%#lx", start);
169
+			return 0;
170
+		}
171
+		if (abbrev(tcp)) {
172
+			abbrev_end = start + max_strlen * sizeof(gid);
173
+			if (abbrev_end < start)
174
+				abbrev_end = end;
175
+		} else {
176
+			abbrev_end = end;
177
+		}
178
+		tprints("[");
179
+		for (cur = start; cur < end; cur += sizeof(gid)) {
180
+			if (cur > start)
181
+				tprints(", ");
182
+			if (cur >= abbrev_end) {
183
+				tprints("...");
184
+				break;
185
+			}
186
+			if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
187
+				tprints("?");
188
+				failed = 1;
189
+				break;
190
+			}
191
+			tprintf("%u", (unsigned int) gid);
192
+		}
193
+		tprints("]");
194
+		if (failed)
195
+			tprintf(" %#lx", tcp->u_arg[1]);
196
+	}
197
+	return 0;
198
+}
199
+
200
+int
201
+sys_getgroups(struct tcb *tcp)
202
+{
203
+	unsigned long len;
204
+
205
+	if (entering(tcp)) {
206
+		len = tcp->u_arg[0];
207
+		tprintf("%lu, ", len);
208
+	} else {
209
+		unsigned long size, start, cur, end, abbrev_end;
210
+		uid_t gid;
211
+		int failed = 0;
212
+
213
+		start = tcp->u_arg[1];
214
+		if (start == 0) {
215
+			tprints("NULL");
216
+			return 0;
217
+		}
218
+		len = tcp->u_rval;
219
+		if (len == 0) {
220
+			tprints("[]");
221
+			return 0;
222
+		}
223
+		size = len * sizeof(gid);
224
+		end = start + size;
225
+		if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
226
+		    size / sizeof(gid) != len || end < start) {
227
+			tprintf("%#lx", start);
228
+			return 0;
229
+		}
230
+		if (abbrev(tcp)) {
231
+			abbrev_end = start + max_strlen * sizeof(gid);
232
+			if (abbrev_end < start)
233
+				abbrev_end = end;
234
+		} else {
235
+			abbrev_end = end;
236
+		}
237
+		tprints("[");
238
+		for (cur = start; cur < end; cur += sizeof(gid)) {
239
+			if (cur > start)
240
+				tprints(", ");
241
+			if (cur >= abbrev_end) {
242
+				tprints("...");
243
+				break;
244
+			}
245
+			if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
246
+				tprints("?");
247
+				failed = 1;
248
+				break;
249
+			}
250
+			tprintf("%u", (unsigned int) gid);
251
+		}
252
+		tprints("]");
253
+		if (failed)
254
+			tprintf(" %#lx", tcp->u_arg[1]);
255
+	}
256
+	return 0;
257
+}
258
+
144 259
 #endif /* STRACE_UID_SIZE */

Loading…
Cancel
Save