cherry-pick.FILE5_37-29-gfa46ca9d.allow-only-the-ioctls-we-use-shankara-pailoor.patch 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. Subject: Allow only the ioctls we use (Shankara Pailoor)
  2. Origin: FILE5_37-29-gfa46ca9d <https://github.com/file/file/commit/FILE5_37-29-gfa46ca9d>
  3. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  4. Date: Fri Jun 21 16:44:23 2019 +0000
  5. --- a/src/seccomp.c
  6. +++ b/src/seccomp.c
  7. @@ -33,6 +33,7 @@
  8. #if HAVE_LIBSECCOMP
  9. #include <seccomp.h> /* libseccomp */
  10. #include <sys/prctl.h> /* prctl */
  11. +#include <sys/ioctl.h>
  12. #include <sys/socket.h>
  13. #include <fcntl.h>
  14. #include <stdlib.h>
  15. @@ -49,8 +50,14 @@
  16. goto out; \
  17. while (/*CONSTCOND*/0)
  18. -static scmp_filter_ctx ctx;
  19. +#define ALLOW_IOCTL_RULE(param) \
  20. + do \
  21. + if (seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(ioctl), 1, \
  22. + SCMP_CMP(1, SCMP_CMP_EQ, param)) == -1) \
  23. + goto out; \
  24. + while (/*CONSTCOND*/0)
  25. +static scmp_filter_ctx ctx;
  26. int
  27. enable_sandbox_basic(void)
  28. @@ -171,7 +178,14 @@
  29. #ifdef __NR_getdents64
  30. ALLOW_RULE(getdents64);
  31. #endif
  32. - ALLOW_RULE(ioctl);
  33. +#ifdef FIONREAD
  34. + // called in src/compress.c under sread
  35. + ALLOW_IOCTL_RULE(FIONREAD);
  36. +#endif
  37. +#ifdef TIOCGWINSZ
  38. + // musl libc may call ioctl TIOCGWINSZ when calling stdout
  39. + ALLOW_IOCTL_RULE(TIOCGWINSZ);
  40. +#endif
  41. ALLOW_RULE(lseek);
  42. ALLOW_RULE(_llseek);
  43. ALLOW_RULE(lstat);