patch-packet_packet_c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. $OpenBSD: patch-packet_packet_c,v 1.2 2017/06/02 16:50:16 sthen Exp $
  2. Index: packet/packet.c
  3. --- packet/packet.c.orig
  4. +++ packet/packet.c
  5. @@ -23,6 +23,7 @@
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <unistd.h>
  9. +#include <pwd.h>
  10. #ifdef HAVE_LIBCAP
  11. #include <sys/capability.h>
  12. @@ -38,11 +39,25 @@ int drop_elevated_permissions(
  13. #ifdef HAVE_LIBCAP
  14. cap_t cap;
  15. #endif
  16. + struct passwd *pw;
  17. - /* Drop any suid permissions granted */
  18. - if (setgid(getgid()) || setuid(getuid())) {
  19. + if ((pw = getpwnam("_mtr")) == NULL) {
  20. return -1;
  21. }
  22. + if (chroot("/var/empty") == -1) {
  23. + return -1;
  24. + }
  25. + if (chdir("/") == -1) {
  26. + return -1;
  27. + }
  28. + if (pw) {
  29. + if (setgroups(1, &pw->pw_gid) == -1 ||
  30. + setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) == -1 ||
  31. + setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) == -1) {
  32. + return -1;
  33. + }
  34. + }
  35. + endpwent();
  36. if (geteuid() != getuid() || getegid() != getgid()) {
  37. return -1;