/src/sudo/plugins/sudoers/regress/fuzz/fuzz_policy.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2021-2023 Todd C. Miller <Todd.Miller@sudo.ws> |
3 | | * |
4 | | * Permission to use, copy, modify, and distribute this software for any |
5 | | * purpose with or without fee is hereby granted, provided that the above |
6 | | * copyright notice and this permission notice appear in all copies. |
7 | | * |
8 | | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
9 | | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
10 | | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
11 | | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
12 | | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
13 | | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
14 | | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
15 | | */ |
16 | | |
17 | | #include <config.h> |
18 | | |
19 | | #include <sys/types.h> |
20 | | #include <sys/socket.h> |
21 | | #include <netinet/in.h> |
22 | | #include <arpa/inet.h> |
23 | | |
24 | | #include <stdarg.h> |
25 | | #include <stdio.h> |
26 | | #include <stdlib.h> |
27 | | #if defined(HAVE_STDINT_H) |
28 | | # include <stdint.h> |
29 | | #elif defined(HAVE_INTTYPES_H) |
30 | | # include <inttypes.h> |
31 | | #endif |
32 | | #include <errno.h> |
33 | | #include <fcntl.h> |
34 | | #include <netdb.h> |
35 | | #include <unistd.h> |
36 | | #include <string.h> |
37 | | #ifndef HAVE_GETADDRINFO |
38 | | # include <compat/getaddrinfo.h> |
39 | | #endif |
40 | | |
41 | | #include <sudoers.h> |
42 | | #include <sudo_iolog.h> |
43 | | #include <interfaces.h> |
44 | | #include <timestamp.h> |
45 | | #include "auth/sudo_auth.h" |
46 | | |
47 | | extern char **environ; |
48 | | extern sudo_dso_public struct policy_plugin sudoers_policy; |
49 | | |
50 | | char *audit_msg; |
51 | | |
52 | | static int pass; |
53 | | |
54 | | /* STUB */ |
55 | | static const struct iolog_path_escape path_escapes[] = { |
56 | | { NULL, NULL }, |
57 | | { NULL, NULL } |
58 | | }; |
59 | | const struct iolog_path_escape *sudoers_iolog_path_escapes = path_escapes; |
60 | | |
61 | | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); |
62 | | |
63 | | static FILE * |
64 | | open_data(const uint8_t *data, size_t size) |
65 | 7.56k | { |
66 | 7.56k | #ifdef HAVE_FMEMOPEN |
67 | | /* Operate in-memory. */ |
68 | 7.56k | return fmemopen((void *)data, size, "r"); |
69 | | #else |
70 | | char tempfile[] = "/tmp/sudoers.XXXXXX"; |
71 | | size_t nwritten; |
72 | | int fd; |
73 | | |
74 | | /* Use (unlinked) temporary file. */ |
75 | | fd = mkstemp(tempfile); |
76 | | if (fd == -1) |
77 | | return NULL; |
78 | | unlink(tempfile); |
79 | | nwritten = write(fd, data, size); |
80 | | if (nwritten != size) { |
81 | | close(fd); |
82 | | return NULL; |
83 | | } |
84 | | lseek(fd, 0, SEEK_SET); |
85 | | return fdopen(fd, "r"); |
86 | | #endif |
87 | 7.56k | } |
88 | | |
89 | | /* |
90 | | * Array that gets resized as needed. |
91 | | */ |
92 | | struct dynamic_array { |
93 | | char **entries; |
94 | | size_t len; |
95 | | size_t size; |
96 | | }; |
97 | | |
98 | | static void |
99 | | free_strvec(char **vec) |
100 | 18.5k | { |
101 | 18.5k | size_t i; |
102 | | |
103 | 4.70M | for (i = 0; vec[i] != NULL; i++) |
104 | 4.68M | free(vec[i]); |
105 | 18.5k | } |
106 | | |
107 | | static void |
108 | | free_dynamic_array(struct dynamic_array *arr) |
109 | 37.8k | { |
110 | 37.8k | if (arr->entries != NULL) { |
111 | 18.5k | free_strvec(arr->entries); |
112 | 18.5k | free(arr->entries); |
113 | 18.5k | } |
114 | 37.8k | memset(arr, 0, sizeof(*arr)); |
115 | 37.8k | } |
116 | | |
117 | | static bool |
118 | | push(struct dynamic_array *arr, const char *entry) |
119 | 4.70M | { |
120 | 4.70M | char *copy = NULL; |
121 | | |
122 | 4.70M | if (entry != NULL) { |
123 | 4.68M | if ((copy = strdup(entry)) == NULL) |
124 | 0 | return false; |
125 | 4.68M | } |
126 | | |
127 | 4.70M | if (arr->len + (entry != NULL) >= arr->size) { |
128 | 22.9k | char **tmp = reallocarray(arr->entries, arr->size + 1024, sizeof(char *)); |
129 | 22.9k | if (tmp == NULL) { |
130 | 0 | free(copy); |
131 | 0 | return false; |
132 | 0 | } |
133 | 22.9k | arr->entries = tmp; |
134 | 22.9k | arr->size += 1024; |
135 | 22.9k | } |
136 | 4.70M | if (copy != NULL) |
137 | 4.68M | arr->entries[arr->len++] = copy; |
138 | 4.70M | arr->entries[arr->len] = NULL; |
139 | | |
140 | 4.70M | return true; |
141 | 4.70M | } |
142 | | |
143 | | static int |
144 | | fuzz_conversation(int num_msgs, const struct sudo_conv_message msgs[], |
145 | | struct sudo_conv_reply replies[], struct sudo_conv_callback *callback) |
146 | 20.2k | { |
147 | 20.2k | int n; |
148 | | |
149 | 101k | for (n = 0; n < num_msgs; n++) { |
150 | 81.6k | const struct sudo_conv_message *msg = &msgs[n]; |
151 | | |
152 | 81.6k | switch (msg->msg_type & 0xff) { |
153 | 0 | case SUDO_CONV_PROMPT_ECHO_ON: |
154 | 0 | case SUDO_CONV_PROMPT_MASK: |
155 | 0 | case SUDO_CONV_PROMPT_ECHO_OFF: |
156 | | /* input not supported */ |
157 | 0 | return -1; |
158 | 81.6k | case SUDO_CONV_ERROR_MSG: |
159 | 81.6k | case SUDO_CONV_INFO_MSG: |
160 | | /* no output for fuzzers */ |
161 | 81.6k | break; |
162 | 0 | default: |
163 | 0 | return -1; |
164 | 81.6k | } |
165 | 81.6k | } |
166 | 20.2k | return 0; |
167 | 20.2k | } |
168 | | |
169 | | static int |
170 | | fuzz_printf(int msg_type, const char * restrict fmt, ...) |
171 | 411k | { |
172 | 411k | return 0; |
173 | 411k | } |
174 | | |
175 | | static int |
176 | | fuzz_hook_stub(struct sudo_hook *hook) |
177 | 60.5k | { |
178 | 60.5k | return 0; |
179 | 60.5k | } |
180 | | |
181 | | /* |
182 | | * The fuzzing environment may not have DNS available, this may result |
183 | | * in long delays that cause a timeout when fuzzing. |
184 | | * This getaddrinfo() resolves every name as "localhost" (127.0.0.1). |
185 | | */ |
186 | | #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION |
187 | | /* Avoid compilation errors if getaddrinfo() or freeaddrinfo() are macros. */ |
188 | | # undef getaddrinfo |
189 | | # undef freeaddrinfo |
190 | | |
191 | | int |
192 | | # ifdef HAVE_GETADDRINFO |
193 | | getaddrinfo( |
194 | | # else |
195 | | sudo_getaddrinfo( |
196 | | # endif |
197 | | const char *nodename, const char *servname, |
198 | | const struct addrinfo *hints, struct addrinfo **res) |
199 | 29.7k | { |
200 | 29.7k | struct addrinfo *ai; |
201 | 29.7k | struct in_addr addr; |
202 | 29.7k | unsigned short port = 0; |
203 | | |
204 | | /* Stub getaddrinfo(3) to avoid a DNS timeout in CIfuzz. */ |
205 | 29.7k | if (servname == NULL) { |
206 | | /* Must have either nodename or servname. */ |
207 | 27.7k | if (nodename == NULL) |
208 | 0 | return EAI_NONAME; |
209 | 27.7k | } else { |
210 | 1.94k | struct servent *servent; |
211 | 1.94k | const char *errstr; |
212 | | |
213 | | /* Parse servname as a port number or IPv4 TCP service name. */ |
214 | 1.94k | port = sudo_strtonum(servname, 0, USHRT_MAX, &errstr); |
215 | 1.94k | if (errstr != NULL && errno == ERANGE) |
216 | 3 | return EAI_SERVICE; |
217 | 1.93k | if (hints != NULL && ISSET(hints->ai_flags, AI_NUMERICSERV)) |
218 | 0 | return EAI_NONAME; |
219 | 1.93k | servent = getservbyname(servname, "tcp"); |
220 | 1.93k | if (servent == NULL) |
221 | 1.93k | return EAI_NONAME; |
222 | 0 | port = htons(servent->s_port); |
223 | 0 | } |
224 | | |
225 | | /* Hard-code IPv4 localhost for fuzzing. */ |
226 | 27.7k | ai = calloc(1, sizeof(*ai) + sizeof(struct sockaddr_in)); |
227 | 27.7k | if (ai == NULL) |
228 | 0 | return EAI_MEMORY; |
229 | 27.7k | ai->ai_canonname = strdup("localhost"); |
230 | 27.7k | if (ai == NULL) { |
231 | 0 | free(ai); |
232 | 0 | return EAI_MEMORY; |
233 | 0 | } |
234 | 27.7k | ai->ai_family = AF_INET; |
235 | 27.7k | ai->ai_protocol = IPPROTO_TCP; |
236 | 27.7k | ai->ai_addrlen = sizeof(struct sockaddr_in); |
237 | 27.7k | ai->ai_addr = (struct sockaddr *)(ai + 1); |
238 | 27.7k | inet_pton(AF_INET, "127.0.0.1", &addr); |
239 | 27.7k | ((struct sockaddr_in *)ai->ai_addr)->sin_family = AF_INET; |
240 | 27.7k | ((struct sockaddr_in *)ai->ai_addr)->sin_addr = addr; |
241 | 27.7k | ((struct sockaddr_in *)ai->ai_addr)->sin_port = htons(port); |
242 | 27.7k | *res = ai; |
243 | 27.7k | return 0; |
244 | 27.7k | } |
245 | | |
246 | | void |
247 | | # ifdef HAVE_GETADDRINFO |
248 | | freeaddrinfo(struct addrinfo *ai) |
249 | | # else |
250 | | sudo_freeaddrinfo(struct addrinfo *ai) |
251 | | # endif |
252 | 27.7k | { |
253 | 27.7k | struct addrinfo *next; |
254 | | |
255 | 55.5k | while (ai != NULL) { |
256 | 27.7k | next = ai->ai_next; |
257 | 27.7k | free(ai->ai_canonname); |
258 | 27.7k | free(ai); |
259 | 27.7k | ai = next; |
260 | 27.7k | } |
261 | 27.7k | } |
262 | | #endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */ |
263 | | |
264 | | enum fuzz_policy_pass { |
265 | | PASS_NONE, |
266 | | PASS_VERSION, |
267 | | PASS_CHECK_LOG_LOCAL, |
268 | | PASS_CHECK_LOG_REMOTE, |
269 | | PASS_CHECK_NOT_FOUND, |
270 | | PASS_CHECK_NOT_FOUND_DOT, |
271 | | PASS_LIST, |
272 | | PASS_LIST_OTHER, |
273 | | PASS_LIST_CHECK, |
274 | | PASS_VALIDATE, |
275 | | PASS_INVALIDATE |
276 | | }; |
277 | | |
278 | | int |
279 | | LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
280 | 7.56k | { |
281 | 7.56k | struct dynamic_array plugin_args = { NULL }; |
282 | 7.56k | struct dynamic_array settings = { NULL }; |
283 | 7.56k | struct dynamic_array user_info = { NULL }; |
284 | 7.56k | struct dynamic_array argv = { NULL }; |
285 | 7.56k | struct dynamic_array env_add = { NULL }; |
286 | 7.56k | char **command_info = NULL, **argv_out = NULL, **user_env_out = NULL; |
287 | 7.56k | const char *errstr = NULL; |
288 | 7.56k | const int num_passes = 10; |
289 | 7.56k | char *line = NULL; |
290 | 7.56k | size_t linesize = 0; |
291 | 7.56k | ssize_t linelen; |
292 | 7.56k | int res = 1; |
293 | 7.56k | FILE *fp; |
294 | | |
295 | 7.56k | fp = open_data(data, size); |
296 | 7.56k | if (fp == NULL) |
297 | 0 | return 0; |
298 | | |
299 | 7.56k | initprogname("fuzz_policy"); |
300 | 7.56k | sudoers_debug_register(getprogname(), NULL); |
301 | 7.56k | if (getenv("SUDO_FUZZ_VERBOSE") == NULL) |
302 | 7.56k | sudo_warn_set_conversation(fuzz_conversation); |
303 | | |
304 | | /* user_info and settings must be non-NULL (even if empty). */ |
305 | 7.56k | push(&user_info, NULL); |
306 | 7.56k | push(&settings, NULL); |
307 | | |
308 | | /* Iterate over each line of data. */ |
309 | 4.82M | while ((linelen = getdelim(&line, &linesize, '\n', fp)) != -1) { |
310 | 4.81M | if (line[linelen - 1] == '\n') |
311 | 4.80M | line[linelen - 1] = '\0'; |
312 | | |
313 | | /* Skip comments and blank lines. */ |
314 | 4.81M | if (line[0] == '#' || line[0] == '\0') |
315 | 13.8k | continue; |
316 | | |
317 | | /* plugin args */ |
318 | 4.80M | if (strncmp(line, "error_recovery=", sizeof("error_recovery=") - 1) == 0) { |
319 | 48.4k | push(&plugin_args, line); |
320 | 48.4k | continue; |
321 | 48.4k | } |
322 | 4.75M | if (strncmp(line, "sudoers_file=", sizeof("sudoers_file=") - 1) == 0) { |
323 | 76.9k | push(&plugin_args, line); |
324 | 76.9k | continue; |
325 | 76.9k | } |
326 | 4.67M | if (strncmp(line, "sudoers_mode=", sizeof("sudoers_mode=") - 1) == 0) { |
327 | 53.4k | push(&plugin_args, line); |
328 | 53.4k | continue; |
329 | 53.4k | } |
330 | 4.62M | if (strncmp(line, "sudoers_gid=", sizeof("sudoers_gid=") - 1) == 0) { |
331 | 48.9k | push(&plugin_args, line); |
332 | 48.9k | continue; |
333 | 48.9k | } |
334 | 4.57M | if (strncmp(line, "sudoers_uid=", sizeof("sudoers_uid=") - 1) == 0) { |
335 | 47.7k | push(&plugin_args, line); |
336 | 47.7k | continue; |
337 | 47.7k | } |
338 | 4.52M | if (strncmp(line, "ldap_conf=", sizeof("ldap_conf=") - 1) == 0) { |
339 | 1.01M | push(&plugin_args, line); |
340 | 1.01M | continue; |
341 | 1.01M | } |
342 | 3.51M | if (strncmp(line, "ldap_secret=", sizeof("ldap_secret=") - 1) == 0) { |
343 | 53.3k | push(&plugin_args, line); |
344 | 53.3k | continue; |
345 | 53.3k | } |
346 | | |
347 | | /* user info */ |
348 | 3.46M | if (strncmp(line, "user=", sizeof("user=") - 1) == 0) { |
349 | 97.1k | push(&user_info, line); |
350 | 97.1k | continue; |
351 | 97.1k | } |
352 | 3.36M | if (strncmp(line, "uid=", sizeof("uid=") - 1) == 0) { |
353 | 358k | push(&user_info, line); |
354 | 358k | continue; |
355 | 358k | } |
356 | 3.00M | if (strncmp(line, "gid=", sizeof("gid=") - 1) == 0) { |
357 | 315k | push(&user_info, line); |
358 | 315k | continue; |
359 | 315k | } |
360 | 2.69M | if (strncmp(line, "groups=", sizeof("groups=") - 1) == 0) { |
361 | 35.8k | push(&user_info, line); |
362 | 35.8k | continue; |
363 | 35.8k | } |
364 | 2.65M | if (strncmp(line, "cwd=", sizeof("cwd=") - 1) == 0) { |
365 | 540 | push(&user_info, line); |
366 | 540 | continue; |
367 | 540 | } |
368 | 2.65M | if (strncmp(line, "tty=", sizeof("tty=") - 1) == 0) { |
369 | 1.28k | push(&user_info, line); |
370 | 1.28k | continue; |
371 | 1.28k | } |
372 | 2.65M | if (strncmp(line, "host=", sizeof("host=") - 1) == 0) { |
373 | 30.6k | push(&user_info, line); |
374 | 30.6k | continue; |
375 | 30.6k | } |
376 | 2.62M | if (strncmp(line, "lines=", sizeof("lines=") - 1) == 0) { |
377 | 287 | push(&user_info, line); |
378 | 287 | continue; |
379 | 287 | } |
380 | 2.62M | if (strncmp(line, "cols=", sizeof("cols=") - 1) == 0) { |
381 | 926 | push(&user_info, line); |
382 | 926 | continue; |
383 | 926 | } |
384 | 2.62M | if (strncmp(line, "sid=", sizeof("sid=") - 1) == 0) { |
385 | 272 | push(&user_info, line); |
386 | 272 | continue; |
387 | 272 | } |
388 | 2.62M | if (strncmp(line, "umask=", sizeof("umask=") - 1) == 0) { |
389 | 835 | push(&user_info, line); |
390 | 835 | continue; |
391 | 835 | } |
392 | 2.62M | if (strncmp(line, "rlimit_", sizeof("rlimit_") - 1) == 0) { |
393 | 479 | push(&user_info, line); |
394 | 479 | continue; |
395 | 479 | } |
396 | | |
397 | | /* First argv entry is the command, the rest are args. */ |
398 | 2.61M | if (strncmp(line, "argv=", sizeof("argv=") - 1) == 0) { |
399 | 1.53M | push(&argv, line); |
400 | 1.53M | continue; |
401 | 1.53M | } |
402 | | |
403 | | /* Additional environment variables to add. */ |
404 | 1.08M | if (strncmp(line, "env=", sizeof("env=") - 1) == 0) { |
405 | 246k | const char *cp = line + sizeof("env=") - 1; |
406 | 246k | if (strchr(cp, '=') != NULL) |
407 | 133k | push(&env_add, cp); |
408 | 246k | continue; |
409 | 246k | } |
410 | | |
411 | | /* Treat anything else as a setting. */ |
412 | 836k | push(&settings, line); |
413 | 836k | } |
414 | 7.56k | fclose(fp); |
415 | 7.56k | free(line); |
416 | 7.56k | line = NULL; |
417 | | |
418 | | /* Exercise code paths that use KRB5CCNAME and SUDO_PROMPT. */ |
419 | 7.56k | putenv((char *)"KRB5CCNAME=/tmp/krb5cc_123456"); |
420 | 7.56k | putenv((char *)"SUDO_PROMPT=[sudo] password for %p: "); |
421 | | |
422 | 7.56k | sudoers_policy.register_hooks(SUDO_API_VERSION, fuzz_hook_stub); |
423 | | |
424 | 33.3k | for (pass = 1; res == 1 && pass <= num_passes; pass++) { |
425 | | /* Call policy open function */ |
426 | 25.8k | res = sudoers_policy.open(SUDO_API_VERSION, fuzz_conversation, |
427 | 25.8k | fuzz_printf, settings.entries, user_info.entries, environ, |
428 | 25.8k | plugin_args.entries, &errstr); |
429 | 25.8k | if (res == 1) { |
430 | 20.2k | if (argv.len == 0) { |
431 | | /* Must have a command to check. */ |
432 | 1.67k | push(&argv, "/usr/bin/id"); |
433 | 1.67k | } |
434 | | |
435 | 20.2k | switch (pass) { |
436 | 0 | case PASS_NONE: |
437 | 0 | break; |
438 | 2.02k | case PASS_VERSION: |
439 | | /* sudo -V */ |
440 | 2.02k | sudoers_policy.show_version(true); |
441 | 2.02k | break; |
442 | 2.02k | case PASS_CHECK_LOG_LOCAL: { |
443 | | /* sudo command w/ local I/O logging (MODE_RUN) */ |
444 | 2.02k | sudoers_policy.check_policy((int)argv.len, argv.entries, |
445 | 2.02k | env_add.entries, &command_info, &argv_out, &user_env_out, |
446 | 2.02k | &errstr); |
447 | | /* call check_policy() again to check for leaks. */ |
448 | 2.02k | sudoers_policy.check_policy((int)argv.len, argv.entries, |
449 | 2.02k | env_add.entries, &command_info, &argv_out, &user_env_out, |
450 | 2.02k | &errstr); |
451 | | /* sudo_auth_begin_session() is stubbed out below. */ |
452 | 2.02k | sudoers_policy.init_session(NULL, NULL, NULL); |
453 | 2.02k | break; |
454 | 0 | } |
455 | 2.02k | case PASS_CHECK_LOG_REMOTE: |
456 | | /* sudo command w/ remote I/O logging (MODE_RUN) */ |
457 | 2.02k | sudoers_policy.check_policy((int)argv.len, argv.entries, |
458 | 2.02k | env_add.entries, &command_info, &argv_out, &user_env_out, |
459 | 2.02k | &errstr); |
460 | | /* call check_policy() again to check for leaks. */ |
461 | 2.02k | sudoers_policy.check_policy((int)argv.len, argv.entries, |
462 | 2.02k | env_add.entries, &command_info, &argv_out, &user_env_out, |
463 | 2.02k | &errstr); |
464 | | /* sudo_auth_begin_session() is stubbed out below. */ |
465 | 2.02k | sudoers_policy.init_session(NULL, NULL, NULL); |
466 | 2.02k | break; |
467 | 2.02k | case PASS_CHECK_NOT_FOUND: |
468 | | /* sudo command (not found) */ |
469 | 2.02k | sudoers_policy.check_policy((int)argv.len, argv.entries, |
470 | 2.02k | env_add.entries, &command_info, &argv_out, &user_env_out, |
471 | 2.02k | &errstr); |
472 | | /* sudo_auth_begin_session() is stubbed out below. */ |
473 | 2.02k | sudoers_policy.init_session(NULL, NULL, NULL); |
474 | 2.02k | break; |
475 | 2.02k | case PASS_CHECK_NOT_FOUND_DOT: |
476 | | /* sudo command (found but in cwd) */ |
477 | 2.02k | sudoers_policy.check_policy((int)argv.len, argv.entries, |
478 | 2.02k | env_add.entries, &command_info, &argv_out, &user_env_out, |
479 | 2.02k | &errstr); |
480 | | /* call check_policy() again to check for leaks. */ |
481 | 2.02k | sudoers_policy.check_policy((int)argv.len, argv.entries, |
482 | 2.02k | env_add.entries, &command_info, &argv_out, &user_env_out, |
483 | 2.02k | &errstr); |
484 | | /* sudo_auth_begin_session() is stubbed out below. */ |
485 | 2.02k | sudoers_policy.init_session(NULL, NULL, NULL); |
486 | 2.02k | break; |
487 | 2.02k | case PASS_LIST: |
488 | | /* sudo -l (MODE_LIST) */ |
489 | 2.02k | sudoers_policy.list(0, NULL, false, NULL, &errstr); |
490 | | /* call list() again to check for leaks. */ |
491 | 2.02k | sudoers_policy.list(0, NULL, false, NULL, &errstr); |
492 | 2.02k | break; |
493 | 2.02k | case PASS_LIST_OTHER: |
494 | | /* sudo -l -U root (MODE_LIST) */ |
495 | 2.02k | sudoers_policy.list(0, NULL, false, "root", &errstr); |
496 | | /* call list() again to check for leaks. */ |
497 | 2.02k | sudoers_policy.list(0, NULL, false, "root", &errstr); |
498 | 2.02k | break; |
499 | 2.02k | case PASS_LIST_CHECK: |
500 | | /* sudo -l command (MODE_CHECK) */ |
501 | 2.02k | sudoers_policy.list((int)argv.len, argv.entries, false, NULL, |
502 | 2.02k | &errstr); |
503 | | /* call list() again to check for leaks. */ |
504 | 2.02k | sudoers_policy.list((int)argv.len, argv.entries, false, NULL, |
505 | 2.02k | &errstr); |
506 | 2.02k | break; |
507 | 2.02k | case PASS_VALIDATE: |
508 | | /* sudo -v (MODE_VALIDATE) */ |
509 | 2.02k | sudoers_policy.validate(&errstr); |
510 | | /* call validate() again to check for leaks. */ |
511 | 2.02k | sudoers_policy.validate(&errstr); |
512 | 2.02k | break; |
513 | 2.02k | case PASS_INVALIDATE: |
514 | | /* sudo -k */ |
515 | 2.02k | sudoers_policy.invalidate(false); |
516 | | /* call invalidate() again to check for leaks. */ |
517 | 2.02k | sudoers_policy.invalidate(false); |
518 | 2.02k | break; |
519 | 20.2k | } |
520 | 20.2k | } |
521 | | |
522 | | /* Free resources. */ |
523 | 25.8k | if (sudoers_policy.close != NULL) |
524 | 25.8k | sudoers_policy.close(0, 0); |
525 | 0 | else |
526 | 0 | sudoers_cleanup(); |
527 | 25.8k | } |
528 | | |
529 | 7.56k | sudoers_policy.deregister_hooks(SUDO_API_VERSION, fuzz_hook_stub); |
530 | | |
531 | 7.56k | free_dynamic_array(&plugin_args); |
532 | 7.56k | free_dynamic_array(&settings); |
533 | 7.56k | free_dynamic_array(&user_info); |
534 | 7.56k | free_dynamic_array(&argv); |
535 | 7.56k | free_dynamic_array(&env_add); |
536 | | |
537 | 7.56k | sudoers_debug_deregister(); |
538 | | |
539 | 7.56k | fflush(stdout); |
540 | | |
541 | 7.56k | return 0; |
542 | 7.56k | } |
543 | | |
544 | | /* STUB */ |
545 | | bool |
546 | | user_is_exempt(const struct sudoers_context *ctx) |
547 | 0 | { |
548 | 0 | return false; |
549 | 0 | } |
550 | | |
551 | | /* STUB */ |
552 | | bool |
553 | | set_interfaces(const char *ai) |
554 | 291 | { |
555 | 291 | return true; |
556 | 291 | } |
557 | | |
558 | | /* STUB */ |
559 | | void |
560 | | dump_interfaces(const char *ai) |
561 | 2.02k | { |
562 | 2.02k | return; |
563 | 2.02k | } |
564 | | |
565 | | /* STUB */ |
566 | | void |
567 | | dump_auth_methods(void) |
568 | 2.02k | { |
569 | 2.02k | return; |
570 | 2.02k | } |
571 | | |
572 | | /* STUB */ |
573 | | int |
574 | | sudo_auth_begin_session(const struct sudoers_context *ctx, struct passwd *pw, |
575 | | char **user_env[]) |
576 | 8.11k | { |
577 | 8.11k | return 1; |
578 | 8.11k | } |
579 | | |
580 | | /* STUB */ |
581 | | int |
582 | | sudo_auth_end_session(void) |
583 | 21.2k | { |
584 | 21.2k | return 1; |
585 | 21.2k | } |
586 | | |
587 | | /* STUB */ |
588 | | bool |
589 | | sudo_auth_needs_end_session(void) |
590 | 0 | { |
591 | 0 | return false; |
592 | 0 | } |
593 | | |
594 | | /* STUB */ |
595 | | int |
596 | | timestamp_remove(const struct sudoers_context *ctx, bool unlink_it) |
597 | 3.41k | { |
598 | 3.41k | return true; |
599 | 3.41k | } |
600 | | |
601 | | /* STUB */ |
602 | | int |
603 | | create_admin_success_flag(const struct sudoers_context *ctx) |
604 | 26.3k | { |
605 | 26.3k | return true; |
606 | 26.3k | } |
607 | | |
608 | | /* STUB */ |
609 | | static int |
610 | | sudo_file_open(struct sudoers_context *ctx, struct sudo_nss *nss) |
611 | 20.2k | { |
612 | 20.2k | return 0; |
613 | 20.2k | } |
614 | | |
615 | | /* STUB */ |
616 | | static int |
617 | | sudo_file_close(struct sudoers_context *ctx, struct sudo_nss *nss) |
618 | 20.2k | { |
619 | 20.2k | return 0; |
620 | 20.2k | } |
621 | | |
622 | | /* STUB */ |
623 | | static struct sudoers_parse_tree * |
624 | | sudo_file_parse(struct sudoers_context *ctx, const struct sudo_nss *nss) |
625 | 20.2k | { |
626 | 20.2k | static struct sudoers_parse_tree parse_tree; |
627 | | |
628 | 20.2k | return &parse_tree; |
629 | 20.2k | } |
630 | | |
631 | | /* STUB */ |
632 | | static int |
633 | | sudo_file_query(struct sudoers_context *ctx, const struct sudo_nss *nss, |
634 | | struct passwd *pw) |
635 | 0 | { |
636 | 0 | return 0; |
637 | 0 | } |
638 | | |
639 | | /* STUB */ |
640 | | static int |
641 | | sudo_file_getdefs(struct sudoers_context *ctx, const struct sudo_nss *nss) |
642 | 26.2k | { |
643 | | /* Set some Defaults */ |
644 | 26.2k | set_default(ctx, "log_input", NULL, true, "sudoers", 1, 1, false); |
645 | 26.2k | set_default(ctx, "log_output", NULL, true, "sudoers", 1, 1, false); |
646 | 26.2k | set_default(ctx, "env_file", "/dev/null", true, "sudoers", 1, 1, false); |
647 | 26.2k | set_default(ctx, "restricted_env_file", "/dev/null", true, "sudoers", 1, 1, false); |
648 | 26.2k | set_default(ctx, "exempt_group", "sudo", true, "sudoers", 1, 1, false); |
649 | 26.2k | set_default(ctx, "runchroot", "/", true, "sudoers", 1, 1, false); |
650 | 26.2k | set_default(ctx, "runcwd", "~", true, "sudoers", 1, 1, false); |
651 | 26.2k | set_default(ctx, "fqdn", NULL, true, "sudoers", 1, 1, false); |
652 | 26.2k | set_default(ctx, "runas_default", "root", true, "sudoers", 1, 1, false); |
653 | 26.2k | set_default(ctx, "tty_tickets", NULL, true, "sudoers", 1, 1, false); |
654 | 26.2k | set_default(ctx, "umask", "022", true, "sudoers", 1, 1, false); |
655 | 26.2k | set_default(ctx, "logfile", "/var/log/sudo", true, "sudoers", 1, 1, false); |
656 | 26.2k | set_default(ctx, "syslog", "auth", true, "sudoers", 1, 1, false); |
657 | 26.2k | set_default(ctx, "syslog_goodpri", "notice", true, "sudoers", 1, 1, false); |
658 | 26.2k | set_default(ctx, "syslog_badpri", "alert", true, "sudoers", 1, 1, false); |
659 | 26.2k | set_default(ctx, "syslog_maxlen", "2048", true, "sudoers", 1, 1, false); |
660 | 26.2k | set_default(ctx, "loglinelen", "0", true, "sudoers", 1, 1, false); |
661 | 26.2k | set_default(ctx, "log_year", NULL, true, "sudoers", 1, 1, false); |
662 | 26.2k | set_default(ctx, "log_host", NULL, true, "sudoers", 1, 1, false); |
663 | 26.2k | set_default(ctx, "mailerpath", NULL, false, "sudoers", 1, 1, false); |
664 | 26.2k | set_default(ctx, "mailerflags", "-t", true, "sudoers", 1, 1, false); |
665 | 26.2k | set_default(ctx, "mailto", "root@localhost", true, "sudoers", 1, 1, false); |
666 | 26.2k | set_default(ctx, "mailfrom", "sudo@sudo.ws", true, "sudoers", 1, 1, false); |
667 | 26.2k | set_default(ctx, "mailsub", "Someone has been naughty on %h", true, "sudoers", 1, 1, false); |
668 | 26.2k | set_default(ctx, "timestampowner", "#0", true, "sudoers", 1, 1, false); |
669 | 26.2k | set_default(ctx, "compress_io", NULL, true, "sudoers", 1, 1, false); |
670 | 26.2k | set_default(ctx, "iolog_flush", NULL, true, "sudoers", 1, 1, false); |
671 | 26.2k | set_default(ctx, "iolog_flush", NULL, true, "sudoers", 1, 1, false); |
672 | 26.2k | set_default(ctx, "maxseq", "2176782336", true, "sudoers", 1, 1, false); |
673 | 26.2k | set_default(ctx, "sudoedit_checkdir", NULL, false, "sudoers", 1, 1, false); |
674 | 26.2k | set_default(ctx, "sudoedit_follow", NULL, true, "sudoers", 1, 1, false); |
675 | 26.2k | set_default(ctx, "ignore_iolog_errors", NULL, true, "sudoers", 1, 1, false); |
676 | 26.2k | set_default(ctx, "ignore_iolog_errors", NULL, true, "sudoers", 1, 1, false); |
677 | 26.2k | set_default(ctx, "noexec", NULL, true, "sudoers", 1, 1, false); |
678 | 26.2k | set_default(ctx, "exec_background", NULL, true, "sudoers", 1, 1, false); |
679 | 26.2k | set_default(ctx, "use_pty", NULL, true, "sudoers", 1, 1, false); |
680 | 26.2k | set_default(ctx, "utmp_runas", NULL, true, "sudoers", 1, 1, false); |
681 | 26.2k | set_default(ctx, "iolog_mode", "0640", true, "sudoers", 1, 1, false); |
682 | 26.2k | set_default(ctx, "iolog_user", NULL, false, "sudoers", 1, 1, false); |
683 | 26.2k | set_default(ctx, "iolog_group", NULL, false, "sudoers", 1, 1, false); |
684 | 26.2k | if (pass != PASS_CHECK_LOG_LOCAL) { |
685 | 22.2k | set_default(ctx, "log_servers", "localhost", true, "sudoers", 1, 1, false); |
686 | 22.2k | set_default(ctx, "log_server_timeout", "30", true, "sudoers", 1, 1, false); |
687 | 22.2k | set_default(ctx, "log_server_cabundle", "/etc/ssl/cacert.pem", true, "sudoers", 1, 1, false); |
688 | 22.2k | set_default(ctx, "log_server_peer_cert", "/etc/ssl/localhost.crt", true, "sudoers", 1, 1, false); |
689 | 22.2k | set_default(ctx, "log_server_peer_key", "/etc/ssl/private/localhost.key", true, "sudoers", 1, 1, false); |
690 | 22.2k | } |
691 | | |
692 | 26.2k | return 0; |
693 | 26.2k | } |
694 | | |
695 | | static struct sudo_nss sudo_nss_file = { |
696 | | { NULL, NULL }, |
697 | | "sudoers", |
698 | | sudo_file_open, |
699 | | sudo_file_close, |
700 | | sudo_file_parse, |
701 | | sudo_file_query, |
702 | | sudo_file_getdefs |
703 | | }; |
704 | | |
705 | | struct sudo_nss_list * |
706 | | sudo_read_nss(void) |
707 | 20.2k | { |
708 | 20.2k | static struct sudo_nss_list snl = TAILQ_HEAD_INITIALIZER(snl); |
709 | | |
710 | 20.2k | if (TAILQ_EMPTY(&snl)) |
711 | 1 | TAILQ_INSERT_TAIL(&snl, &sudo_nss_file, entries); |
712 | | |
713 | 20.2k | return &snl; |
714 | 20.2k | } |
715 | | |
716 | | /* STUB */ |
717 | | int |
718 | | check_user(struct sudoers_context *ctx, unsigned int validated, |
719 | | unsigned int mode) |
720 | 26.3k | { |
721 | 26.3k | return AUTH_SUCCESS; |
722 | 26.3k | } |
723 | | |
724 | | /* STUB */ |
725 | | int |
726 | | check_user_runchroot(const char *runchroot) |
727 | 26.3k | { |
728 | 26.3k | return true; |
729 | 26.3k | } |
730 | | |
731 | | /* STUB */ |
732 | | int |
733 | | check_user_runcwd(const char *runcwd) |
734 | 26.3k | { |
735 | 26.3k | return true; |
736 | 26.3k | } |
737 | | |
738 | | /* STUB */ |
739 | | void |
740 | | group_plugin_unload(void) |
741 | 0 | { |
742 | 0 | return; |
743 | 0 | } |
744 | | |
745 | | /* STUB */ |
746 | | bool |
747 | | log_warning(const struct sudoers_context *ctx, unsigned int flags, |
748 | | const char * restrict fmt, ...) |
749 | 0 | { |
750 | 0 | return true; |
751 | 0 | } |
752 | | |
753 | | /* STUB */ |
754 | | bool |
755 | | log_warningx(const struct sudoers_context *ctx, unsigned int flags, |
756 | | const char * restrict fmt, ...) |
757 | 4.22k | { |
758 | 4.22k | return true; |
759 | 4.22k | } |
760 | | |
761 | | /* STUB */ |
762 | | bool |
763 | | gai_log_warning(const struct sudoers_context *ctx, unsigned int flags, |
764 | | int errnum, const char * restrict fmt, ...) |
765 | 0 | { |
766 | 0 | return true; |
767 | 0 | } |
768 | | |
769 | | /* STUB */ |
770 | | bool |
771 | | log_denial(const struct sudoers_context *ctx, unsigned int status, |
772 | | bool inform_user) |
773 | 0 | { |
774 | 0 | return true; |
775 | 0 | } |
776 | | |
777 | | /* STUB */ |
778 | | bool |
779 | | log_failure(const struct sudoers_context *ctx,unsigned int status, int flags) |
780 | 0 | { |
781 | 0 | return true; |
782 | 0 | } |
783 | | |
784 | | /* STUB */ |
785 | | bool |
786 | | log_exit_status(const struct sudoers_context *ctx, int exit_status) |
787 | 21.2k | { |
788 | 21.2k | return true; |
789 | 21.2k | } |
790 | | |
791 | | /* STUB */ |
792 | | bool |
793 | | mail_parse_errors(const struct sudoers_context *ctx) |
794 | 48.0k | { |
795 | 48.0k | return true; |
796 | 48.0k | } |
797 | | |
798 | | /* STUB */ |
799 | | bool |
800 | | log_parse_error(const struct sudoers_context *ctx, const char *file, |
801 | | int line, int column, const char * restrict fmt, va_list args) |
802 | 0 | { |
803 | 0 | return true; |
804 | 0 | } |
805 | | |
806 | | /* STUB */ |
807 | | int |
808 | | audit_failure(const struct sudoers_context *ctx, char *const argv[], |
809 | | char const * restrict const fmt, ...) |
810 | 5.73k | { |
811 | 5.73k | return 0; |
812 | 5.73k | } |
813 | | |
814 | | /* STUB */ |
815 | | unsigned int |
816 | | sudoers_lookup(struct sudo_nss_list *snl, struct sudoers_context *ctx, |
817 | | time_t now, sudoers_lookup_callback_fn_t callback, void *cb_data, |
818 | | int *cmnd_status, int pwflag) |
819 | 26.4k | { |
820 | 26.4k | return VALIDATE_SUCCESS; |
821 | 26.4k | } |
822 | | |
823 | | /* STUB */ |
824 | | int |
825 | | display_cmnd(struct sudoers_context *ctx, const struct sudo_nss_list *snl, |
826 | | struct passwd *pw, int verbose) |
827 | 3.12k | { |
828 | 3.12k | return true; |
829 | 3.12k | } |
830 | | |
831 | | /* STUB */ |
832 | | int |
833 | | display_privs(struct sudoers_context *ctx, const struct sudo_nss_list *snl, |
834 | | struct passwd *pw, int verbose) |
835 | 6.24k | { |
836 | 6.24k | return true; |
837 | 6.24k | } |
838 | | |
839 | | /* STUB */ |
840 | | int |
841 | | find_path(const char *infile, char **outfile, struct stat *sbp, |
842 | | const char *path, const char *runchroot, bool ignore_dot, |
843 | | char * const *allowlist) |
844 | 23.5k | { |
845 | 23.5k | switch (pass) { |
846 | 2.02k | case PASS_CHECK_NOT_FOUND: |
847 | 2.02k | return NOT_FOUND; |
848 | 6.00k | case PASS_CHECK_NOT_FOUND_DOT: |
849 | 6.00k | return NOT_FOUND_DOT; |
850 | 15.5k | default: |
851 | 15.5k | if (infile[0] == '/') { |
852 | 13.2k | *outfile = strdup(infile); |
853 | 13.2k | } else { |
854 | 2.24k | if (asprintf(outfile, "/usr/bin/%s", infile) == -1) |
855 | 0 | *outfile = NULL; |
856 | 2.24k | } |
857 | 15.5k | if (*outfile == NULL) |
858 | 0 | return NOT_FOUND_ERROR; |
859 | 15.5k | return FOUND; |
860 | 23.5k | } |
861 | 23.5k | } |
862 | | |
863 | | /* STUB */ |
864 | | int |
865 | | resolve_cmnd(struct sudoers_context *ctx, const char *infile, char **outfile, |
866 | | const char *path, const char *runchroot) |
867 | 22.6k | { |
868 | 22.6k | return find_path(infile, outfile, NULL, path, NULL, false, NULL); |
869 | 22.6k | } |
870 | | |
871 | | /* STUB */ |
872 | | bool |
873 | | expand_iolog_path(const char *inpath, char *path, size_t pathlen, |
874 | | const struct iolog_path_escape *escapes, void *closure) |
875 | 5.52k | { |
876 | 5.52k | return strlcpy(path, inpath, pathlen) < pathlen; |
877 | 5.52k | } |
878 | | |
879 | | /* STUB */ |
880 | | bool |
881 | | iolog_nextid(const char *iolog_dir, char sessid[7]) |
882 | 0 | { |
883 | 0 | strlcpy(sessid, "000001", 7); |
884 | 0 | return true; |
885 | 0 | } |
886 | | |
887 | | /* STUB */ |
888 | | bool |
889 | | cb_maxseq(struct sudoers_context *ctx, const char *file, |
890 | | int line, int column, const union sudo_defs_val *sd_un, int op) |
891 | 26.2k | { |
892 | 26.2k | return true; |
893 | 26.2k | } |
894 | | |
895 | | /* STUB */ |
896 | | bool |
897 | | cb_iolog_user(struct sudoers_context *ctx, const char *file, |
898 | | int line, int column, const union sudo_defs_val *sd_un, int op) |
899 | 26.2k | { |
900 | 26.2k | return true; |
901 | 26.2k | } |
902 | | |
903 | | /* STUB */ |
904 | | bool |
905 | | cb_iolog_group(struct sudoers_context *ctx, const char *file, |
906 | | int line, int column, const union sudo_defs_val *sd_un, int op) |
907 | 26.2k | { |
908 | 26.2k | return true; |
909 | 26.2k | } |
910 | | |
911 | | /* STUB */ |
912 | | bool |
913 | | cb_iolog_mode(struct sudoers_context *ctx, const char *file, |
914 | | int line, int column, const union sudo_defs_val *sd_un, int op) |
915 | 26.2k | { |
916 | 26.2k | return true; |
917 | 26.2k | } |
918 | | |
919 | | /* STUB */ |
920 | | bool |
921 | | cb_group_plugin(struct sudoers_context *ctx, const char *file, |
922 | | int line, int column, const union sudo_defs_val *sd_un, int op) |
923 | 0 | { |
924 | 0 | return true; |
925 | 0 | } |
926 | | |
927 | | /* STUB */ |
928 | | bool |
929 | | cb_timestampowner(struct sudoers_context *ctx, const char *file, |
930 | | int line, int column, const union sudo_defs_val *sd_un, int op) |
931 | 26.2k | { |
932 | 26.2k | return true; |
933 | 26.2k | } |
934 | | |
935 | | /* STUB */ |
936 | | void |
937 | | bsdauth_set_style(const char *style) |
938 | 0 | { |
939 | 0 | return; |
940 | 0 | } |