ptracesandbox.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541
  1. /*
  2. * Part of Very Secure FTPd
  3. * Licence: GPL v2
  4. * Author: Chris Evans
  5. * ptracesandbox.c
  6. *
  7. * Generic routines to setup and run a process under a restrictive ptrace()
  8. * based sandbox.
  9. * Note that the style in this file is to not go via the helper functions in
  10. * sysutil.c, but instead hit the system APIs directly. This is because I may
  11. * very well release just this file to the public domain, and do not want
  12. * dependencies on other parts of vsftpd.
  13. */
  14. #include "ptracesandbox.h"
  15. #if defined(__linux__) && defined(__i386__)
  16. #include <sys/mman.h>
  17. #include <sys/prctl.h>
  18. #include <sys/ptrace.h>
  19. /* For AF_MAX (NPROTO is defined to this) */
  20. #include <sys/socket.h>
  21. #include <sys/types.h>
  22. #include <sys/user.h>
  23. #include <sys/wait.h>
  24. #include <err.h>
  25. #include <errno.h>
  26. #include <fcntl.h>
  27. #include <signal.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <unistd.h>
  31. #include <syslog.h>
  32. #include <asm/unistd.h>
  33. #ifndef __NR_sendfile64
  34. #define __NR_sendfile64 239
  35. #endif
  36. #ifndef __NR_exit_group
  37. #define __NR_exit_group 252
  38. #endif
  39. #ifndef __NR_utimes
  40. #define __NR_utimes 271
  41. #endif
  42. /* For the socketcall() multiplex args. */
  43. #include <linux/net.h>
  44. #ifndef PTRACE_SETOPTIONS
  45. #define PTRACE_SETOPTIONS 0x4200
  46. #endif
  47. #ifndef PTRACE_O_TRACESYSGOOD
  48. #define PTRACE_O_TRACESYSGOOD 1
  49. #endif
  50. #ifndef PTRACE_O_TRACEFORK
  51. #define PTRACE_O_TRACEFORK 2
  52. #endif
  53. #ifndef PTRACE_O_TRACEVFORK
  54. #define PTRACE_O_TRACEVFORK 4
  55. #endif
  56. #ifndef PTRACE_O_TRACECLONE
  57. #define PTRACE_O_TRACECLONE 8
  58. #endif
  59. #ifndef O_DIRECT
  60. #define O_DIRECT 040000
  61. #endif
  62. static void sanitize_child();
  63. static int get_action(struct pt_sandbox* p_sandbox);
  64. static int validate_mmap2(struct pt_sandbox* p_sandbox, void* p_arg);
  65. static int validate_open_default(struct pt_sandbox* p_sandbox, void* p_arg);
  66. static int validate_open_readonly(struct pt_sandbox* p_sandbox, void* p_arg);
  67. static int validate_fcntl(struct pt_sandbox* p_sandbox, void* p_arg);
  68. static int validate_socketcall(struct pt_sandbox* p_sandbox, void* p_arg);
  69. static void install_socketcall(struct pt_sandbox* p_sandbox);
  70. #define MAX_SYSCALL 300
  71. struct pt_sandbox
  72. {
  73. int read_event_fd;
  74. int write_event_fd;
  75. pid_t pid;
  76. int is_allowed[MAX_SYSCALL];
  77. ptrace_sandbox_validator_t validator[MAX_SYSCALL];
  78. void* validator_arg[MAX_SYSCALL];
  79. int is_exit;
  80. struct user_regs_struct regs;
  81. int is_socketcall_allowed[NPROTO];
  82. ptrace_sandbox_validator_t socketcall_validator[NPROTO];
  83. void* socketcall_validator_arg[NPROTO];
  84. };
  85. static int s_sigchld_fd = -1;
  86. void
  87. handle_sigchld(int sig)
  88. {
  89. int ret;
  90. if (sig != SIGCHLD)
  91. {
  92. _exit(1);
  93. }
  94. if (s_sigchld_fd != -1)
  95. {
  96. do
  97. {
  98. static const char zero = '\0';
  99. ret = write(s_sigchld_fd, &zero, sizeof(zero));
  100. } while (ret == -1 && errno == EINTR);
  101. if (ret != 1)
  102. {
  103. _exit(2);
  104. }
  105. }
  106. }
  107. struct pt_sandbox*
  108. ptrace_sandbox_alloc()
  109. {
  110. int i;
  111. struct sigaction sigact;
  112. struct pt_sandbox* ret = malloc(sizeof(struct pt_sandbox));
  113. if (ret == NULL)
  114. {
  115. return NULL;
  116. }
  117. ret->pid = -1;
  118. ret->read_event_fd = -1;
  119. ret->write_event_fd = -1;
  120. ret->is_exit = 0;
  121. memset(&ret->regs, '\0', sizeof(ret->regs));
  122. for (i = 0; i < MAX_SYSCALL; ++i)
  123. {
  124. ret->is_allowed[i] = 0;
  125. ret->validator[i] = 0;
  126. ret->validator_arg[i] = 0;
  127. }
  128. for (i = 0; i < NPROTO; ++i)
  129. {
  130. ret->is_socketcall_allowed[i] = 0;
  131. ret->socketcall_validator[i] = 0;
  132. ret->socketcall_validator_arg[i] = 0;
  133. }
  134. memset((void*) &sigact, '\0', sizeof(sigact));
  135. sigact.sa_handler = handle_sigchld;
  136. if (sigaction(SIGCHLD, &sigact, NULL) != 0)
  137. {
  138. goto err_out;
  139. }
  140. return ret;
  141. err_out:
  142. ptrace_sandbox_free(ret);
  143. return NULL;
  144. }
  145. void
  146. ptrace_sandbox_free(struct pt_sandbox* p_sandbox)
  147. {
  148. if (p_sandbox->pid != -1)
  149. {
  150. warnx("bug: pid active in ptrace_sandbox_free");
  151. /* We'll kill it for you so it doesn't escape the sandbox totally, but
  152. * we won't reap the zombie.
  153. * Killing it like this is a risk: if it's stopped in syscall entry,
  154. * that syscall will execute before the pending kill takes effect.
  155. * If that pending syscall were to be a fork(), there could be trouble.
  156. */
  157. (void) kill(p_sandbox->pid, SIGKILL);
  158. }
  159. if (p_sandbox->read_event_fd != -1)
  160. {
  161. s_sigchld_fd = -1;
  162. close(p_sandbox->read_event_fd);
  163. close(p_sandbox->write_event_fd);
  164. }
  165. free(p_sandbox);
  166. }
  167. void
  168. ptrace_sandbox_attach_point()
  169. {
  170. long pt_ret;
  171. int ret;
  172. pid_t pid = getpid();
  173. if (pid <= 1)
  174. {
  175. warnx("weird pid");
  176. _exit(1);
  177. }
  178. /* You don't have to use PTRACE_TRACEME, but if you don't, a rogue SIGCONT
  179. * might wake you up from the STOP below before the tracer has attached.
  180. */
  181. pt_ret = ptrace(PTRACE_TRACEME, 0, 0, 0);
  182. if (pt_ret != 0)
  183. {
  184. warn("PTRACE_TRACEME failed");
  185. _exit(2);
  186. }
  187. ret = kill(pid, SIGSTOP);
  188. if (ret != 0)
  189. {
  190. warn("kill SIGSTOP failed");
  191. _exit(3);
  192. }
  193. }
  194. int
  195. ptrace_sandbox_launch_process(struct pt_sandbox* p_sandbox,
  196. void (*p_func)(void*),
  197. void* p_arg)
  198. {
  199. long pt_ret;
  200. pid_t ret;
  201. int status;
  202. if (p_sandbox->pid != -1)
  203. {
  204. warnx("bug: process already active");
  205. return -1;
  206. }
  207. ret = fork();
  208. if (ret < 0)
  209. {
  210. return -1;
  211. }
  212. else if (ret == 0)
  213. {
  214. /* Child context. */
  215. sanitize_child();
  216. (*p_func)(p_arg);
  217. _exit(0);
  218. }
  219. /* Parent context */
  220. p_sandbox->pid = ret;
  221. do
  222. {
  223. ret = waitpid(p_sandbox->pid, &status, 0);
  224. } while (ret == -1 && errno == EINTR);
  225. if (ret == -1)
  226. {
  227. warn("waitpid failed");
  228. goto kill_out;
  229. }
  230. else if (ret != p_sandbox->pid)
  231. {
  232. warnx("unknown pid %d", ret);
  233. goto kill_out;
  234. }
  235. if (!WIFSTOPPED(status))
  236. {
  237. warnx("not stopped status %d\n", status);
  238. goto kill_out;
  239. }
  240. if (WSTOPSIG(status) != SIGSTOP)
  241. {
  242. warnx("not SIGSTOP status %d\n", status);
  243. goto kill_out;
  244. }
  245. /* The fork, etc. tracing options are worth a bit of explanation. We don't
  246. * permit process launching syscalls at all as they are dangerous. But
  247. * there's a small race if the untrusted process attempts a denied fork()
  248. * and then takes a rouge SIGKILL before the supervisor gets a chance to
  249. * clear the orig_eax register. In this case the syscall will still execute.
  250. * (Policies may not include signal sending capabilities, thus mitigating this
  251. * direct attack, however a rogue SIGKILL may come from a non-malicious
  252. * source). Therefore, we'd rather any fork()ed process starts off traced,
  253. * just in case this tiny race condition triggers.
  254. */
  255. pt_ret = ptrace(PTRACE_SETOPTIONS,
  256. p_sandbox->pid,
  257. 0,
  258. PTRACE_O_TRACESYSGOOD | PTRACE_O_TRACEFORK |
  259. PTRACE_O_TRACEVFORK | PTRACE_O_TRACECLONE);
  260. if (pt_ret != 0)
  261. {
  262. warn("PTRACE_SETOPTIONS failure");
  263. goto kill_out;
  264. }
  265. return p_sandbox->pid;
  266. kill_out:
  267. (void) kill(p_sandbox->pid, SIGKILL);
  268. p_sandbox->pid = -1;
  269. return -1;
  270. }
  271. int
  272. ptrace_sandbox_continue_process(struct pt_sandbox* p_sandbox, int sig)
  273. {
  274. long pt_ret = ptrace(PTRACE_SYSCALL, p_sandbox->pid, 0, sig);
  275. if (pt_ret != 0)
  276. {
  277. warn("PTRACE_SYSCALL failure");
  278. if (errno == ESRCH)
  279. {
  280. return PTRACE_SANDBOX_ERR_DEAD;
  281. }
  282. return PTRACE_SANDBOX_ERR_PTRACE;
  283. }
  284. return 0;
  285. }
  286. int
  287. ptrace_sandbox_get_event_fd(struct pt_sandbox* p_sandbox)
  288. {
  289. /* TODO: allocate pipe fds */
  290. (void) p_sandbox;
  291. return -1;
  292. }
  293. int
  294. ptrace_sandbox_get_event(struct pt_sandbox* p_sandbox, int* status, int block)
  295. {
  296. pid_t pid;
  297. int options = 0;
  298. if (!block)
  299. {
  300. options = WNOHANG;
  301. }
  302. do
  303. {
  304. pid = waitpid(p_sandbox->pid, status, options);
  305. } while (pid == -1 && errno == EINTR);
  306. if (pid == -1)
  307. {
  308. warn("waitpid failure");
  309. if (errno == ECHILD)
  310. {
  311. return PTRACE_SANDBOX_ERR_DEAD;
  312. }
  313. return PTRACE_SANDBOX_ERR_WAITPID;
  314. }
  315. return pid;
  316. }
  317. int
  318. ptrace_sandbox_handle_event(struct pt_sandbox* p_sandbox, int status)
  319. {
  320. int sig;
  321. int action;
  322. if (WIFEXITED(status) || WIFSIGNALED(status))
  323. {
  324. p_sandbox->pid = -1;
  325. return 1;
  326. }
  327. if (!WIFSTOPPED(status))
  328. {
  329. warnx("weird status: %d\n", status);
  330. return PTRACE_SANDBOX_ERR_WAIT_STATUS;
  331. }
  332. sig = WSTOPSIG(status);
  333. if (sig >= 0 && sig < 0x80)
  334. {
  335. /* It's a normal signal; deliver it right on. SIGSTOP / SIGCONT handling
  336. * are buggy in the kernel and I'm not sure it's safe to pass either on,
  337. * so the signal becomes a little more... robust :)
  338. */
  339. if (sig == SIGSTOP || sig == SIGCONT)
  340. {
  341. sig = SIGKILL;
  342. }
  343. return ptrace_sandbox_continue_process(p_sandbox, sig);
  344. }
  345. if (!(sig & 0x80))
  346. {
  347. warnx("weird status: %d\n", status);
  348. return PTRACE_SANDBOX_ERR_WAIT_STATUS;
  349. }
  350. /* Syscall trap. */
  351. if (p_sandbox->is_exit)
  352. {
  353. p_sandbox->is_exit = 0;
  354. }
  355. else
  356. {
  357. p_sandbox->is_exit = 1;
  358. action = get_action(p_sandbox);
  359. if (action != 0)
  360. {
  361. return action;
  362. }
  363. }
  364. return ptrace_sandbox_continue_process(p_sandbox, 0);
  365. }
  366. int
  367. ptrace_sandbox_run_processes(struct pt_sandbox* p_sandbox)
  368. {
  369. if (ptrace_sandbox_continue_process(p_sandbox, 0) != 0)
  370. {
  371. goto kill_out;
  372. }
  373. while (1)
  374. {
  375. int status;
  376. int ret = ptrace_sandbox_get_event(p_sandbox, &status, 1);
  377. if (ret <= 0)
  378. {
  379. goto kill_out;
  380. }
  381. ret = ptrace_sandbox_handle_event(p_sandbox, status);
  382. if (ret < 0)
  383. {
  384. warnx("couldn't handle sandbox event");
  385. goto kill_out;
  386. }
  387. if (ret == 1)
  388. {
  389. return 0;
  390. }
  391. }
  392. kill_out:
  393. ptrace_sandbox_kill_processes(p_sandbox);
  394. return -1;
  395. }
  396. void
  397. ptrace_sandbox_kill_processes(struct pt_sandbox* p_sandbox)
  398. {
  399. long pt_ret;
  400. struct user_regs_struct regs;
  401. pid_t pid = p_sandbox->pid;
  402. if (pid == -1)
  403. {
  404. return;
  405. }
  406. p_sandbox->pid = -1;
  407. pt_ret = ptrace(PTRACE_GETREGS, pid, 0, &regs);
  408. if (pt_ret != 0)
  409. {
  410. warn("PTRACE_GETREGS failure");
  411. /* This API is supposed to be called with the process stopped; but if it
  412. * is still running, we can at least help a bit. See security related
  413. * comment in ptrace_sandbox_free(), though.
  414. */
  415. (void) kill(pid, SIGKILL);
  416. return;
  417. }
  418. /* Kind of nasty, but the only way of stopping a started syscall from
  419. * executing is to rewrite the registers to execute a different syscall.
  420. */
  421. regs.orig_eax = __NR_exit_group;
  422. regs.eip = 0xffffffff;
  423. pt_ret = ptrace(PTRACE_SETREGS, pid, 0, &regs);
  424. if (pt_ret != 0)
  425. {
  426. warn("PTRACE_SETREGS failure");
  427. /* Deliberate fall-thru. */
  428. }
  429. pt_ret = ptrace(PTRACE_KILL, pid, 0, 0);
  430. if (pt_ret != 0)
  431. {
  432. warn("PTRACE_KILL failure");
  433. /* Deliberate fall-thru. */
  434. }
  435. /* Just to make ourselves clear. */
  436. (void) kill(pid, SIGKILL);
  437. /* So the GETREGS succeeded, so the process definitely _was_ there. We can
  438. * safely wait for it to reap the zombie.
  439. */
  440. (void) waitpid(pid, NULL, 0);
  441. }
  442. int
  443. ptrace_sandbox_get_arg(struct pt_sandbox* p_sandbox,
  444. int arg,
  445. unsigned long* p_out)
  446. {
  447. long ret = 0;
  448. struct user_regs_struct* p_regs = &p_sandbox->regs;
  449. if (p_regs->orig_eax == 0)
  450. {
  451. return PTRACE_SANDBOX_ERR_API_ABUSE_STOPIT;
  452. }
  453. if (arg < 0 || arg > 5)
  454. {
  455. return PTRACE_SANDBOX_ERR_API_ABUSE_STOPIT;
  456. }
  457. switch (arg)
  458. {
  459. case 0:
  460. ret = p_regs->ebx;
  461. break;
  462. case 1:
  463. ret = p_regs->ecx;
  464. break;
  465. case 2:
  466. ret = p_regs->edx;
  467. break;
  468. case 3:
  469. ret = p_regs->esi;
  470. break;
  471. case 4:
  472. ret = p_regs->edi;
  473. break;
  474. case 5:
  475. ret = p_regs->ebp;
  476. break;
  477. }
  478. *p_out = ret;
  479. return 0;
  480. }
  481. int
  482. ptrace_sandbox_get_socketcall_arg(struct pt_sandbox* p_sandbox,
  483. int arg,
  484. unsigned long* p_out)
  485. {
  486. unsigned long ptr;
  487. int ret;
  488. struct user_regs_struct* p_regs = &p_sandbox->regs;
  489. if (p_regs->orig_eax == 0)
  490. {
  491. return PTRACE_SANDBOX_ERR_API_ABUSE_STOPIT;
  492. }
  493. if (arg < 0 || arg > 2)
  494. {
  495. return PTRACE_SANDBOX_ERR_API_ABUSE_STOPIT;
  496. }
  497. ret = ptrace_sandbox_get_arg(p_sandbox, 1, &ptr);
  498. if (ret != 0)
  499. {
  500. return ret;
  501. }
  502. ptr += (arg * 4);
  503. ret = ptrace_sandbox_get_long(p_sandbox, ptr, p_out);
  504. return ret;
  505. }
  506. int
  507. ptrace_sandbox_get_long(struct pt_sandbox* p_sandbox,
  508. unsigned long ptr,
  509. unsigned long* p_out)
  510. {
  511. return ptrace_sandbox_get_buf(p_sandbox, ptr, sizeof(long), (void*) p_out);
  512. }
  513. int
  514. ptrace_sandbox_get_buf(struct pt_sandbox* p_sandbox,
  515. unsigned long ptr,
  516. unsigned long len,
  517. void* p_buf)
  518. {
  519. long pt_ret;
  520. char* p_out = (char*) p_buf;
  521. for (; len > 0; len -= sizeof(long))
  522. {
  523. errno = 0;
  524. pt_ret = ptrace(PTRACE_PEEKDATA, p_sandbox->pid, (void*) ptr, 0);
  525. if (pt_ret == -1 && errno != 0)
  526. {
  527. warn("PTRACE_GETREGS failure");
  528. if (errno == ESRCH)
  529. {
  530. return PTRACE_SANDBOX_ERR_DEAD;
  531. }
  532. return PTRACE_SANDBOX_ERR_PTRACE;
  533. }
  534. if (len >= sizeof(long))
  535. {
  536. memcpy(p_out, &pt_ret, sizeof(long));
  537. }
  538. else
  539. {
  540. memcpy(p_out, &pt_ret, len);
  541. }
  542. p_out += sizeof(long);
  543. ptr += sizeof(long);
  544. }
  545. return 0;
  546. }
  547. static void
  548. sanitize_child()
  549. {
  550. /* Ensure that if our sandbox supervisor goes down, so do we. */
  551. int ret = prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
  552. if (ret != 0)
  553. {
  554. _exit(3);
  555. }
  556. }
  557. static int
  558. get_action(struct pt_sandbox* p_sandbox)
  559. {
  560. int ret;
  561. int call;
  562. int cs;
  563. long pt_ret = ptrace(PTRACE_GETREGS, p_sandbox->pid, 0, &(p_sandbox->regs));
  564. if (pt_ret != 0)
  565. {
  566. warn("PTRACE_GETREGS failure");
  567. if (errno == ESRCH)
  568. {
  569. return PTRACE_SANDBOX_ERR_DEAD;
  570. }
  571. return PTRACE_SANDBOX_ERR_PTRACE;
  572. }
  573. /* We need to be sure that the child is attempting a syscall against the
  574. * 32-bit syscall table, otherwise they can bypass the policy by abusing the
  575. * fact that e.g. syscall 200 is getgid32() on 32-bit but tkill() on 64-bit.
  576. * If the syscall instruct was int80 or sysenter, is it guaranteed to hit
  577. * the 32-bit table. If it is syscall, the current CS selector determines
  578. * the table. Therefore, we can check the current CS selector references a
  579. * known system-only selector that is guaranteed 32-bit (not long mode).
  580. */
  581. cs = p_sandbox->regs.xcs;
  582. if (cs != 0x73 && cs != 0x23)
  583. {
  584. warnx("bad CS %d", cs);
  585. ret = PTRACE_SANDBOX_ERR_BAD_SYSCALL;
  586. goto out;
  587. }
  588. call = (int) p_sandbox->regs.orig_eax;
  589. if (call < 0 || call >= MAX_SYSCALL)
  590. {
  591. warnx("syscall %d out of bounds", call);
  592. ret = PTRACE_SANDBOX_ERR_BAD_SYSCALL;
  593. goto out;
  594. }
  595. if (p_sandbox->is_allowed[call] != 1)
  596. {
  597. syslog(LOG_LOCAL0 | LOG_DEBUG, "syscall not permitted: %d", call);
  598. warnx("syscall not permitted: %d", call);
  599. ret = PTRACE_SANDBOX_ERR_POLICY_SYSCALL;
  600. goto out;
  601. }
  602. if (p_sandbox->validator[call])
  603. {
  604. ptrace_sandbox_validator_t p_validate = p_sandbox->validator[call];
  605. int validate_ret = (*p_validate)(p_sandbox, p_sandbox->validator_arg[call]);
  606. if (validate_ret != 0)
  607. {
  608. syslog(LOG_LOCAL0 | LOG_DEBUG,
  609. "syscall validate fail: %d (%d)",
  610. call,
  611. validate_ret);
  612. warnx("syscall validate failed: %d (%d)", call, validate_ret);
  613. ret = PTRACE_SANDBOX_ERR_POLICY_ARGS;
  614. goto out;
  615. }
  616. }
  617. ret = 0;
  618. out:
  619. memset(&p_sandbox->regs, '\0', sizeof(p_sandbox->regs));
  620. return ret;
  621. }
  622. void
  623. ptrace_sandbox_permit_exit(struct pt_sandbox* p_sandbox)
  624. {
  625. p_sandbox->is_allowed[__NR_exit] = 1;
  626. p_sandbox->is_allowed[__NR_exit_group] = 1;
  627. }
  628. void
  629. ptrace_sandbox_permit_read(struct pt_sandbox* p_sandbox)
  630. {
  631. p_sandbox->is_allowed[__NR_read] = 1;
  632. }
  633. void
  634. ptrace_sandbox_permit_write(struct pt_sandbox* p_sandbox)
  635. {
  636. p_sandbox->is_allowed[__NR_write] = 1;
  637. }
  638. void
  639. ptrace_sandbox_permit_sigaction(struct pt_sandbox* p_sandbox)
  640. {
  641. p_sandbox->is_allowed[__NR_sigaction] = 1;
  642. p_sandbox->is_allowed[__NR_rt_sigaction] = 1;
  643. }
  644. void
  645. ptrace_sandbox_permit_alarm(struct pt_sandbox* p_sandbox)
  646. {
  647. p_sandbox->is_allowed[__NR_alarm] = 1;
  648. }
  649. void
  650. ptrace_sandbox_permit_query_time(struct pt_sandbox* p_sandbox)
  651. {
  652. p_sandbox->is_allowed[__NR_gettimeofday] = 1;
  653. p_sandbox->is_allowed[__NR_time] = 1;
  654. }
  655. void
  656. ptrace_sandbox_permit_mmap(struct pt_sandbox* p_sandbox)
  657. {
  658. p_sandbox->is_allowed[__NR_mmap2] = 1;
  659. p_sandbox->validator[__NR_mmap2] = validate_mmap2;
  660. }
  661. static int
  662. validate_mmap2(struct pt_sandbox* p_sandbox, void* p_arg)
  663. {
  664. unsigned long arg4;
  665. int ret = ptrace_sandbox_get_arg(p_sandbox, 3, &arg4);
  666. (void) p_arg;
  667. if (ret != 0)
  668. {
  669. return ret;
  670. }
  671. if (arg4 & MAP_SHARED)
  672. {
  673. return -1;
  674. }
  675. return 0;
  676. }
  677. void
  678. ptrace_sandbox_permit_mprotect(struct pt_sandbox* p_sandbox)
  679. {
  680. p_sandbox->is_allowed[__NR_mprotect] = 1;
  681. }
  682. void
  683. ptrace_sandbox_permit_file_stats(struct pt_sandbox* p_sandbox)
  684. {
  685. p_sandbox->is_allowed[__NR_stat] = 1;
  686. p_sandbox->is_allowed[__NR_stat64] = 1;
  687. p_sandbox->is_allowed[__NR_lstat] = 1;
  688. p_sandbox->is_allowed[__NR_lstat64] = 1;
  689. }
  690. void
  691. ptrace_sandbox_permit_fd_stats(struct pt_sandbox* p_sandbox)
  692. {
  693. p_sandbox->is_allowed[__NR_fstat] = 1;
  694. p_sandbox->is_allowed[__NR_fstat64] = 1;
  695. }
  696. void
  697. ptrace_sandbox_permit_getcwd(struct pt_sandbox* p_sandbox)
  698. {
  699. p_sandbox->is_allowed[__NR_getcwd] = 1;
  700. }
  701. void
  702. ptrace_sandbox_permit_chdir(struct pt_sandbox* p_sandbox)
  703. {
  704. p_sandbox->is_allowed[__NR_chdir] = 1;
  705. }
  706. void
  707. ptrace_sandbox_permit_umask(struct pt_sandbox* p_sandbox)
  708. {
  709. p_sandbox->is_allowed[__NR_umask] = 1;
  710. }
  711. void
  712. ptrace_sandbox_permit_open(struct pt_sandbox* p_sandbox, int writeable)
  713. {
  714. p_sandbox->is_allowed[__NR_open] = 1;
  715. if (writeable == 1)
  716. {
  717. p_sandbox->validator[__NR_open] = validate_open_default;
  718. }
  719. else
  720. {
  721. p_sandbox->validator[__NR_open] = validate_open_readonly;
  722. }
  723. }
  724. static int
  725. validate_open_default(struct pt_sandbox* p_sandbox, void* p_arg)
  726. {
  727. unsigned long arg2;
  728. int ret = ptrace_sandbox_get_arg(p_sandbox, 1, &arg2);
  729. (void) p_arg;
  730. if (ret != 0)
  731. {
  732. return ret;
  733. }
  734. if (arg2 & (O_ASYNC | O_DIRECT | O_SYNC))
  735. {
  736. return -1;
  737. }
  738. return 0;
  739. }
  740. static int
  741. validate_open_readonly(struct pt_sandbox* p_sandbox, void* p_arg)
  742. {
  743. unsigned long arg2;
  744. int ret = validate_open_default(p_sandbox, p_arg);
  745. if (ret != 0)
  746. {
  747. return ret;
  748. }
  749. ret = ptrace_sandbox_get_arg(p_sandbox, 1, &arg2);
  750. if (ret != 0)
  751. {
  752. return ret;
  753. }
  754. if ((arg2 & O_ACCMODE) != O_RDONLY)
  755. {
  756. return -1;
  757. }
  758. return 0;
  759. }
  760. void
  761. ptrace_sandbox_permit_close(struct pt_sandbox* p_sandbox)
  762. {
  763. p_sandbox->is_allowed[__NR_close] = 1;
  764. }
  765. void
  766. ptrace_sandbox_permit_getdents(struct pt_sandbox* p_sandbox)
  767. {
  768. p_sandbox->is_allowed[__NR_getdents] = 1;
  769. p_sandbox->is_allowed[__NR_getdents64] = 1;
  770. }
  771. void
  772. ptrace_sandbox_permit_fcntl(struct pt_sandbox* p_sandbox)
  773. {
  774. p_sandbox->is_allowed[__NR_fcntl] = 1;
  775. p_sandbox->validator[__NR_fcntl] = validate_fcntl;
  776. p_sandbox->is_allowed[__NR_fcntl64] = 1;
  777. p_sandbox->validator[__NR_fcntl64] = validate_fcntl;
  778. }
  779. static int
  780. validate_fcntl(struct pt_sandbox* p_sandbox, void* p_arg)
  781. {
  782. unsigned long arg2;
  783. unsigned long arg3;
  784. int ret = ptrace_sandbox_get_arg(p_sandbox, 1, &arg2);
  785. (void) p_arg;
  786. if (ret != 0)
  787. {
  788. return ret;
  789. }
  790. ret = ptrace_sandbox_get_arg(p_sandbox, 2, &arg3);
  791. if (ret != 0)
  792. {
  793. return ret;
  794. }
  795. if (arg2 != F_GETFL &&
  796. arg2 != F_SETFL &&
  797. arg2 != F_SETOWN &&
  798. arg2 != F_SETLK &&
  799. arg2 != F_SETLKW &&
  800. arg2 != F_SETLK64 &&
  801. arg2 != F_SETLKW64 &&
  802. arg2 != F_SETFD &&
  803. arg2 != F_GETFD)
  804. {
  805. syslog(LOG_LOCAL0 | LOG_DEBUG, "fcntl not permitted: %ld", arg2);
  806. warnx("fcntl not permitted: %ld", arg2);
  807. return -1;
  808. }
  809. if (arg2 == F_SETFL && (arg3 & (O_ASYNC | O_DIRECT)))
  810. {
  811. return -2;
  812. }
  813. if (arg2 == F_SETOWN && (int) arg3 != p_sandbox->pid)
  814. {
  815. return -3;
  816. }
  817. return 0;
  818. }
  819. void
  820. ptrace_sandbox_permit_sendfile(struct pt_sandbox* p_sandbox)
  821. {
  822. p_sandbox->is_allowed[__NR_sendfile] = 1;
  823. p_sandbox->is_allowed[__NR_sendfile64] = 1;
  824. }
  825. void
  826. ptrace_sandbox_permit_seek(struct pt_sandbox* p_sandbox)
  827. {
  828. p_sandbox->is_allowed[__NR_lseek] = 1;
  829. p_sandbox->is_allowed[__NR__llseek] = 1;
  830. }
  831. void
  832. ptrace_sandbox_permit_select(struct pt_sandbox* p_sandbox)
  833. {
  834. p_sandbox->is_allowed[__NR_select] = 1;
  835. p_sandbox->is_allowed[__NR__newselect] = 1;
  836. }
  837. void
  838. ptrace_sandbox_permit_unlink(struct pt_sandbox* p_sandbox)
  839. {
  840. p_sandbox->is_allowed[__NR_unlink] = 1;
  841. }
  842. void
  843. ptrace_sandbox_permit_mkdir(struct pt_sandbox* p_sandbox)
  844. {
  845. p_sandbox->is_allowed[__NR_mkdir] = 1;
  846. }
  847. void
  848. ptrace_sandbox_permit_rmdir(struct pt_sandbox* p_sandbox)
  849. {
  850. p_sandbox->is_allowed[__NR_rmdir] = 1;
  851. }
  852. void
  853. ptrace_sandbox_permit_rename(struct pt_sandbox* p_sandbox)
  854. {
  855. p_sandbox->is_allowed[__NR_rename] = 1;
  856. }
  857. void
  858. ptrace_sandbox_permit_utime(struct pt_sandbox* p_sandbox)
  859. {
  860. p_sandbox->is_allowed[__NR_utime] = 1;
  861. p_sandbox->is_allowed[__NR_utimes] = 1;
  862. }
  863. void
  864. ptrace_sandbox_permit_sigreturn(struct pt_sandbox* p_sandbox)
  865. {
  866. p_sandbox->is_allowed[__NR_sigreturn] = 1;
  867. }
  868. void
  869. ptrace_sandbox_permit_recv(struct pt_sandbox* p_sandbox)
  870. {
  871. install_socketcall(p_sandbox);
  872. p_sandbox->is_socketcall_allowed[SYS_RECV] = 1;
  873. }
  874. static void
  875. install_socketcall(struct pt_sandbox* p_sandbox)
  876. {
  877. p_sandbox->is_allowed[__NR_socketcall] = 1;
  878. p_sandbox->validator[__NR_socketcall] = validate_socketcall;
  879. }
  880. static int
  881. validate_socketcall(struct pt_sandbox* p_sandbox, void* p_arg)
  882. {
  883. unsigned long arg1;
  884. int ret = ptrace_sandbox_get_arg(p_sandbox, 0, &arg1);
  885. (void) p_arg;
  886. if (ret != 0)
  887. {
  888. return ret;
  889. }
  890. if (arg1 < 1 || arg1 >= NPROTO)
  891. {
  892. return -1;
  893. }
  894. if (p_sandbox->is_socketcall_allowed[arg1] != 1)
  895. {
  896. syslog(LOG_LOCAL0 | LOG_DEBUG, "socketcall not permitted: %ld", arg1);
  897. warnx("socketcall not permitted: %ld", arg1);
  898. return -2;
  899. }
  900. if (p_sandbox->socketcall_validator[arg1])
  901. {
  902. ptrace_sandbox_validator_t p_val = p_sandbox->socketcall_validator[arg1];
  903. ret = (*p_val)(p_sandbox, p_sandbox->socketcall_validator_arg[arg1]);
  904. if (ret != 0)
  905. {
  906. syslog(LOG_LOCAL0 | LOG_DEBUG,
  907. "socketcall validate fail: %ld (%d)",
  908. arg1,
  909. ret);
  910. warnx("socketcall validate fail: %ld (%d)", arg1, ret);
  911. return -3;
  912. }
  913. }
  914. return 0;
  915. }
  916. void
  917. ptrace_sandbox_permit_readlink(struct pt_sandbox* p_sandbox)
  918. {
  919. p_sandbox->is_allowed[__NR_readlink] = 1;
  920. }
  921. void
  922. ptrace_sandbox_permit_brk(struct pt_sandbox* p_sandbox)
  923. {
  924. p_sandbox->is_allowed[__NR_brk] = 1;
  925. }
  926. void
  927. ptrace_sandbox_permit_sleep(struct pt_sandbox* p_sandbox)
  928. {
  929. p_sandbox->is_allowed[__NR_nanosleep] = 1;
  930. }
  931. void
  932. ptrace_sandbox_permit_fchmod(struct pt_sandbox* p_sandbox)
  933. {
  934. p_sandbox->is_allowed[__NR_fchmod] = 1;
  935. }
  936. void
  937. ptrace_sandbox_permit_chmod(struct pt_sandbox* p_sandbox)
  938. {
  939. p_sandbox->is_allowed[__NR_chmod] = 1;
  940. }
  941. void
  942. ptrace_sandbox_permit_fchown(struct pt_sandbox* p_sandbox)
  943. {
  944. p_sandbox->is_allowed[__NR_fchown] = 1;
  945. p_sandbox->is_allowed[__NR_fchown32] = 1;
  946. }
  947. void
  948. ptrace_sandbox_permit_mremap(struct pt_sandbox* p_sandbox)
  949. {
  950. p_sandbox->is_allowed[__NR_mremap] = 1;
  951. }
  952. void
  953. ptrace_sandbox_permit_ftruncate(struct pt_sandbox* p_sandbox)
  954. {
  955. p_sandbox->is_allowed[__NR_ftruncate] = 1;
  956. p_sandbox->is_allowed[__NR_ftruncate64] = 1;
  957. }
  958. void
  959. ptrace_sandbox_permit_socket(struct pt_sandbox* p_sandbox)
  960. {
  961. install_socketcall(p_sandbox);
  962. p_sandbox->is_socketcall_allowed[SYS_SOCKET] = 1;
  963. }
  964. void
  965. ptrace_sandbox_set_socket_validator(struct pt_sandbox* p_sandbox,
  966. ptrace_sandbox_validator_t val,
  967. void* p_arg)
  968. {
  969. p_sandbox->socketcall_validator[SYS_SOCKET] = val;
  970. p_sandbox->socketcall_validator_arg[SYS_SOCKET] = p_arg;
  971. }
  972. void
  973. ptrace_sandbox_permit_bind(struct pt_sandbox* p_sandbox)
  974. {
  975. install_socketcall(p_sandbox);
  976. p_sandbox->is_socketcall_allowed[SYS_BIND] = 1;
  977. }
  978. void
  979. ptrace_sandbox_set_bind_validator(struct pt_sandbox* p_sandbox,
  980. ptrace_sandbox_validator_t val,
  981. void* p_arg)
  982. {
  983. p_sandbox->socketcall_validator[SYS_BIND] = val;
  984. p_sandbox->socketcall_validator_arg[SYS_BIND] = p_arg;
  985. }
  986. void
  987. ptrace_sandbox_permit_connect(struct pt_sandbox* p_sandbox)
  988. {
  989. install_socketcall(p_sandbox);
  990. p_sandbox->is_socketcall_allowed[SYS_CONNECT] = 1;
  991. }
  992. void
  993. ptrace_sandbox_set_connect_validator(struct pt_sandbox* p_sandbox,
  994. ptrace_sandbox_validator_t val,
  995. void* p_arg)
  996. {
  997. p_sandbox->socketcall_validator[SYS_CONNECT] = val;
  998. p_sandbox->socketcall_validator_arg[SYS_CONNECT] = p_arg;
  999. }
  1000. void
  1001. ptrace_sandbox_permit_listen(struct pt_sandbox* p_sandbox)
  1002. {
  1003. install_socketcall(p_sandbox);
  1004. p_sandbox->is_socketcall_allowed[SYS_LISTEN] = 1;
  1005. }
  1006. void
  1007. ptrace_sandbox_permit_accept(struct pt_sandbox* p_sandbox)
  1008. {
  1009. install_socketcall(p_sandbox);
  1010. p_sandbox->is_socketcall_allowed[SYS_ACCEPT] = 1;
  1011. }
  1012. void
  1013. ptrace_sandbox_permit_setsockopt(struct pt_sandbox* p_sandbox)
  1014. {
  1015. install_socketcall(p_sandbox);
  1016. p_sandbox->is_socketcall_allowed[SYS_SETSOCKOPT] = 1;
  1017. }
  1018. void
  1019. ptrace_sandbox_set_setsockopt_validator(struct pt_sandbox* p_sandbox,
  1020. ptrace_sandbox_validator_t val,
  1021. void* p_arg)
  1022. {
  1023. p_sandbox->socketcall_validator[SYS_SETSOCKOPT] = val;
  1024. p_sandbox->socketcall_validator_arg[SYS_SETSOCKOPT] = p_arg;
  1025. }
  1026. void
  1027. ptrace_sandbox_permit_getsockopt(struct pt_sandbox* p_sandbox)
  1028. {
  1029. install_socketcall(p_sandbox);
  1030. p_sandbox->is_socketcall_allowed[SYS_GETSOCKOPT] = 1;
  1031. }
  1032. void
  1033. ptrace_sandbox_set_getsockopt_validator(struct pt_sandbox* p_sandbox,
  1034. ptrace_sandbox_validator_t val,
  1035. void* p_arg)
  1036. {
  1037. p_sandbox->socketcall_validator[SYS_GETSOCKOPT] = val;
  1038. p_sandbox->socketcall_validator_arg[SYS_GETSOCKOPT] = p_arg;
  1039. }
  1040. void
  1041. ptrace_sandbox_permit_shutdown(struct pt_sandbox* p_sandbox)
  1042. {
  1043. install_socketcall(p_sandbox);
  1044. p_sandbox->is_socketcall_allowed[SYS_SHUTDOWN] = 1;
  1045. }
  1046. #else /* __linux__ && __i386__ */
  1047. struct pt_sandbox*
  1048. ptrace_sandbox_alloc()
  1049. {
  1050. return 0;
  1051. }
  1052. void
  1053. ptrace_sandbox_free(struct pt_sandbox* p_sandbox)
  1054. {
  1055. (void) p_sandbox;
  1056. }
  1057. int
  1058. ptrace_sandbox_launch_process(struct pt_sandbox* p_sandbox,
  1059. void (*p_func)(void*),
  1060. void* p_arg)
  1061. {
  1062. (void) p_sandbox;
  1063. (void) p_func;
  1064. (void) p_arg;
  1065. return -1;
  1066. }
  1067. int
  1068. ptrace_sandbox_run_processes(struct pt_sandbox* p_sandbox)
  1069. {
  1070. (void) p_sandbox;
  1071. return -1;
  1072. }
  1073. void
  1074. ptrace_sandbox_attach_point(void)
  1075. {
  1076. }
  1077. void
  1078. ptrace_sandbox_permit_exit(struct pt_sandbox* p_sandbox)
  1079. {
  1080. (void) p_sandbox;
  1081. }
  1082. void
  1083. ptrace_sandbox_permit_read(struct pt_sandbox* p_sandbox)
  1084. {
  1085. (void) p_sandbox;
  1086. }
  1087. void
  1088. ptrace_sandbox_permit_write(struct pt_sandbox* p_sandbox)
  1089. {
  1090. (void) p_sandbox;
  1091. }
  1092. void
  1093. ptrace_sandbox_permit_sigaction(struct pt_sandbox* p_sandbox)
  1094. {
  1095. (void) p_sandbox;
  1096. }
  1097. void
  1098. ptrace_sandbox_permit_alarm(struct pt_sandbox* p_sandbox)
  1099. {
  1100. (void) p_sandbox;
  1101. }
  1102. void
  1103. ptrace_sandbox_permit_query_time(struct pt_sandbox* p_sandbox)
  1104. {
  1105. (void) p_sandbox;
  1106. }
  1107. void
  1108. ptrace_sandbox_permit_mmap(struct pt_sandbox* p_sandbox)
  1109. {
  1110. (void) p_sandbox;
  1111. }
  1112. void
  1113. ptrace_sandbox_permit_mprotect(struct pt_sandbox* p_sandbox)
  1114. {
  1115. (void) p_sandbox;
  1116. }
  1117. void
  1118. ptrace_sandbox_permit_file_stats(struct pt_sandbox* p_sandbox)
  1119. {
  1120. (void) p_sandbox;
  1121. }
  1122. void
  1123. ptrace_sandbox_permit_fd_stats(struct pt_sandbox* p_sandbox)
  1124. {
  1125. (void) p_sandbox;
  1126. }
  1127. void
  1128. ptrace_sandbox_permit_getcwd(struct pt_sandbox* p_sandbox)
  1129. {
  1130. (void) p_sandbox;
  1131. }
  1132. void
  1133. ptrace_sandbox_permit_chdir(struct pt_sandbox* p_sandbox)
  1134. {
  1135. (void) p_sandbox;
  1136. }
  1137. void
  1138. ptrace_sandbox_permit_umask(struct pt_sandbox* p_sandbox)
  1139. {
  1140. (void) p_sandbox;
  1141. }
  1142. void
  1143. ptrace_sandbox_permit_open(struct pt_sandbox* p_sandbox, int writeable)
  1144. {
  1145. (void) p_sandbox;
  1146. (void) writeable;
  1147. }
  1148. void
  1149. ptrace_sandbox_permit_close(struct pt_sandbox* p_sandbox)
  1150. {
  1151. (void) p_sandbox;
  1152. }
  1153. void
  1154. ptrace_sandbox_permit_getdents(struct pt_sandbox* p_sandbox)
  1155. {
  1156. (void) p_sandbox;
  1157. }
  1158. void
  1159. ptrace_sandbox_permit_fcntl(struct pt_sandbox* p_sandbox)
  1160. {
  1161. (void) p_sandbox;
  1162. }
  1163. void
  1164. ptrace_sandbox_permit_sendfile(struct pt_sandbox* p_sandbox)
  1165. {
  1166. (void) p_sandbox;
  1167. }
  1168. void
  1169. ptrace_sandbox_permit_seek(struct pt_sandbox* p_sandbox)
  1170. {
  1171. (void) p_sandbox;
  1172. }
  1173. void
  1174. ptrace_sandbox_permit_select(struct pt_sandbox* p_sandbox)
  1175. {
  1176. (void) p_sandbox;
  1177. }
  1178. void
  1179. ptrace_sandbox_permit_unlink(struct pt_sandbox* p_sandbox)
  1180. {
  1181. (void) p_sandbox;
  1182. }
  1183. void
  1184. ptrace_sandbox_permit_mkdir(struct pt_sandbox* p_sandbox)
  1185. {
  1186. (void) p_sandbox;
  1187. }
  1188. void
  1189. ptrace_sandbox_permit_rmdir(struct pt_sandbox* p_sandbox)
  1190. {
  1191. (void) p_sandbox;
  1192. }
  1193. void
  1194. ptrace_sandbox_permit_rename(struct pt_sandbox* p_sandbox)
  1195. {
  1196. (void) p_sandbox;
  1197. }
  1198. void
  1199. ptrace_sandbox_permit_utime(struct pt_sandbox* p_sandbox)
  1200. {
  1201. (void) p_sandbox;
  1202. }
  1203. void
  1204. ptrace_sandbox_permit_utimes(struct pt_sandbox* p_sandbox)
  1205. {
  1206. (void) p_sandbox;
  1207. }
  1208. void
  1209. ptrace_sandbox_permit_sigreturn(struct pt_sandbox* p_sandbox)
  1210. {
  1211. (void) p_sandbox;
  1212. }
  1213. void
  1214. ptrace_sandbox_permit_recv(struct pt_sandbox* p_sandbox)
  1215. {
  1216. (void) p_sandbox;
  1217. }
  1218. void
  1219. ptrace_sandbox_kill_processes(struct pt_sandbox* p_sandbox)
  1220. {
  1221. (void) p_sandbox;
  1222. }
  1223. int
  1224. ptrace_sandbox_get_arg(struct pt_sandbox* p_sandbox,
  1225. int arg,
  1226. unsigned long* p_out)
  1227. {
  1228. (void) p_sandbox;
  1229. (void) arg;
  1230. (void) p_out;
  1231. return -1;
  1232. }
  1233. int
  1234. ptrace_sandbox_get_socketcall_arg(struct pt_sandbox* p_sandbox,
  1235. int arg,
  1236. unsigned long* p_out)
  1237. {
  1238. (void) p_sandbox;
  1239. (void) arg;
  1240. (void) p_out;
  1241. return -1;
  1242. }
  1243. int
  1244. ptrace_sandbox_get_long(struct pt_sandbox* p_sandbox,
  1245. unsigned long ptr,
  1246. unsigned long* p_out)
  1247. {
  1248. (void) p_sandbox;
  1249. (void) ptr;
  1250. (void) p_out;
  1251. return -1;
  1252. }
  1253. int
  1254. ptrace_sandbox_get_buf(struct pt_sandbox* p_sandbox,
  1255. unsigned long ptr,
  1256. unsigned long len,
  1257. void* p_buf)
  1258. {
  1259. (void) p_sandbox;
  1260. (void) ptr;
  1261. (void) len;
  1262. (void) p_buf;
  1263. return -1;
  1264. }
  1265. void
  1266. ptrace_sandbox_permit_readlink(struct pt_sandbox* p_sandbox)
  1267. {
  1268. (void) p_sandbox;
  1269. }
  1270. void
  1271. ptrace_sandbox_permit_brk(struct pt_sandbox* p_sandbox)
  1272. {
  1273. (void) p_sandbox;
  1274. }
  1275. void
  1276. ptrace_sandbox_permit_sleep(struct pt_sandbox* p_sandbox)
  1277. {
  1278. (void) p_sandbox;
  1279. }
  1280. void
  1281. ptrace_sandbox_permit_fchmod(struct pt_sandbox* p_sandbox)
  1282. {
  1283. (void) p_sandbox;
  1284. }
  1285. void
  1286. ptrace_sandbox_permit_chmod(struct pt_sandbox* p_sandbox)
  1287. {
  1288. (void) p_sandbox;
  1289. }
  1290. void
  1291. ptrace_sandbox_permit_fchown(struct pt_sandbox* p_sandbox)
  1292. {
  1293. (void) p_sandbox;
  1294. }
  1295. void
  1296. ptrace_sandbox_permit_mremap(struct pt_sandbox* p_sandbox)
  1297. {
  1298. (void) p_sandbox;
  1299. }
  1300. void
  1301. ptrace_sandbox_permit_ftruncate(struct pt_sandbox* p_sandbox)
  1302. {
  1303. (void) p_sandbox;
  1304. }
  1305. void
  1306. ptrace_sandbox_permit_socket(struct pt_sandbox* p_sandbox)
  1307. {
  1308. (void) p_sandbox;
  1309. }
  1310. void
  1311. ptrace_sandbox_set_socket_validator(struct pt_sandbox* p_sandbox,
  1312. ptrace_sandbox_validator_t val,
  1313. void* p_arg)
  1314. {
  1315. (void) p_sandbox;
  1316. (void) val;
  1317. (void) p_arg;
  1318. }
  1319. void
  1320. ptrace_sandbox_permit_bind(struct pt_sandbox* p_sandbox)
  1321. {
  1322. (void) p_sandbox;
  1323. }
  1324. void
  1325. ptrace_sandbox_set_bind_validator(struct pt_sandbox* p_sandbox,
  1326. ptrace_sandbox_validator_t val,
  1327. void* p_arg)
  1328. {
  1329. (void) p_sandbox;
  1330. (void) val;
  1331. (void) p_arg;
  1332. }
  1333. void
  1334. ptrace_sandbox_permit_connect(struct pt_sandbox* p_sandbox)
  1335. {
  1336. (void) p_sandbox;
  1337. }
  1338. void
  1339. ptrace_sandbox_set_connect_validator(struct pt_sandbox* p_sandbox,
  1340. ptrace_sandbox_validator_t val,
  1341. void* p_arg)
  1342. {
  1343. (void) p_sandbox;
  1344. (void) val;
  1345. (void) p_arg;
  1346. }
  1347. void
  1348. ptrace_sandbox_permit_listen(struct pt_sandbox* p_sandbox)
  1349. {
  1350. (void) p_sandbox;
  1351. }
  1352. void
  1353. ptrace_sandbox_permit_accept(struct pt_sandbox* p_sandbox)
  1354. {
  1355. (void) p_sandbox;
  1356. }
  1357. void
  1358. ptrace_sandbox_permit_setsockopt(struct pt_sandbox* p_sandbox)
  1359. {
  1360. (void) p_sandbox;
  1361. }
  1362. void
  1363. ptrace_sandbox_set_setsockopt_validator(struct pt_sandbox* p_sandbox,
  1364. ptrace_sandbox_validator_t val,
  1365. void* p_arg)
  1366. {
  1367. (void) p_sandbox;
  1368. (void) val;
  1369. (void) p_arg;
  1370. }
  1371. void
  1372. ptrace_sandbox_permit_getsockopt(struct pt_sandbox* p_sandbox)
  1373. {
  1374. (void) p_sandbox;
  1375. }
  1376. void
  1377. ptrace_sandbox_set_getsockopt_validator(struct pt_sandbox* p_sandbox,
  1378. ptrace_sandbox_validator_t val,
  1379. void* p_arg)
  1380. {
  1381. (void) p_sandbox;
  1382. (void) val;
  1383. (void) p_arg;
  1384. }
  1385. void
  1386. ptrace_sandbox_permit_shutdown(struct pt_sandbox* p_sandbox)
  1387. {
  1388. (void) p_sandbox;
  1389. }
  1390. #endif /* __linux__ && __i386__ */