sandbox-2.11-symlinkat-renameat.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. From 4c47cfa22802fd8201586bef233d8161df4ff61b Mon Sep 17 00:00:00 2001
  2. From: Mike Frysinger <vapier@gentoo.org>
  3. Date: Fri, 10 Mar 2017 10:15:50 -0800
  4. Subject: [PATCH] libsandbox: whitelist renameat/symlinkat as symlink funcs
  5. These funcs don't deref their path args, so flag them as such.
  6. URL: https://bugs.gentoo.org/612202
  7. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
  8. ---
  9. libsandbox/libsandbox.c | 4 +++-
  10. tests/renameat-2.sh | 12 ++++++++++++
  11. tests/renameat-3.sh | 11 +++++++++++
  12. tests/renameat.at | 2 ++
  13. tests/symlinkat-2.sh | 10 ++++++++++
  14. tests/symlinkat-3.sh | 9 +++++++++
  15. tests/symlinkat.at | 2 ++
  16. 7 files changed, 49 insertions(+), 1 deletion(-)
  17. create mode 100755 tests/renameat-2.sh
  18. create mode 100755 tests/renameat-3.sh
  19. create mode 100755 tests/symlinkat-2.sh
  20. create mode 100755 tests/symlinkat-3.sh
  21. diff --git a/libsandbox/libsandbox.c b/libsandbox/libsandbox.c
  22. index e809308d717d..de48bd79ba53 100644
  23. --- a/libsandbox/libsandbox.c
  24. +++ b/libsandbox/libsandbox.c
  25. @@ -650,8 +650,10 @@ static bool symlink_func(int sb_nr, int flags, const char *abs_path)
  26. sb_nr == SB_NR_LCHOWN ||
  27. sb_nr == SB_NR_REMOVE ||
  28. sb_nr == SB_NR_RENAME ||
  29. + sb_nr == SB_NR_RENAMEAT ||
  30. sb_nr == SB_NR_RMDIR ||
  31. - sb_nr == SB_NR_SYMLINK))
  32. + sb_nr == SB_NR_SYMLINK ||
  33. + sb_nr == SB_NR_SYMLINKAT))
  34. {
  35. /* These funcs sometimes operate on symlinks */
  36. if (!((sb_nr == SB_NR_FCHOWNAT ||
  37. diff --git a/tests/renameat-2.sh b/tests/renameat-2.sh
  38. new file mode 100755
  39. index 000000000000..d0fbe8ae4574
  40. --- /dev/null
  41. +++ b/tests/renameat-2.sh
  42. @@ -0,0 +1,12 @@
  43. +#!/bin/sh
  44. +# make sure we can clobber symlinks #612202
  45. +
  46. +addwrite $PWD
  47. +
  48. +ln -s /asdf sym || exit 1
  49. +touch file
  50. +renameat-0 0 AT_FDCWD file AT_FDCWD sym || exit 1
  51. +[ ! -e file ]
  52. +[ ! -L sym ]
  53. +[ -e sym ]
  54. +test ! -s "${SANDBOX_LOG}"
  55. diff --git a/tests/renameat-3.sh b/tests/renameat-3.sh
  56. new file mode 100755
  57. index 000000000000..9ae5c9a6511a
  58. --- /dev/null
  59. +++ b/tests/renameat-3.sh
  60. @@ -0,0 +1,11 @@
  61. +#!/bin/sh
  62. +# make sure we reject bad renames #612202
  63. +
  64. +addwrite $PWD
  65. +mkdir deny
  66. +adddeny $PWD/deny
  67. +
  68. +touch file
  69. +renameat-0 -1,EACCES AT_FDCWD file AT_FDCWD deny/file || exit 1
  70. +[ -e file ]
  71. +test -s "${SANDBOX_LOG}"
  72. diff --git a/tests/renameat.at b/tests/renameat.at
  73. index 081d7d20277e..eec4638deeaa 100644
  74. --- a/tests/renameat.at
  75. +++ b/tests/renameat.at
  76. @@ -1 +1,3 @@
  77. SB_CHECK(1)
  78. +SB_CHECK(2)
  79. +SB_CHECK(3)
  80. diff --git a/tests/symlinkat-2.sh b/tests/symlinkat-2.sh
  81. new file mode 100755
  82. index 000000000000..168362e8806f
  83. --- /dev/null
  84. +++ b/tests/symlinkat-2.sh
  85. @@ -0,0 +1,10 @@
  86. +#!/bin/sh
  87. +# make sure we can clobber symlinks #612202
  88. +
  89. +addwrite $PWD
  90. +
  91. +symlinkat-0 0 /asdf AT_FDCWD ./sym || exit 1
  92. +[ -L sym ]
  93. +symlinkat-0 -1,EEXIST /asdf AT_FDCWD ./sym || exit 1
  94. +[ -L sym ]
  95. +test ! -s "${SANDBOX_LOG}"
  96. diff --git a/tests/symlinkat-3.sh b/tests/symlinkat-3.sh
  97. new file mode 100755
  98. index 000000000000..a01c750dd2b6
  99. --- /dev/null
  100. +++ b/tests/symlinkat-3.sh
  101. @@ -0,0 +1,9 @@
  102. +#!/bin/sh
  103. +# make sure we reject bad symlinks #612202
  104. +
  105. +addwrite $PWD
  106. +mkdir deny
  107. +adddeny $PWD/deny
  108. +
  109. +symlinkat-0 -1,EACCES ./ AT_FDCWD deny/sym || exit 1
  110. +test -s "${SANDBOX_LOG}"
  111. diff --git a/tests/symlinkat.at b/tests/symlinkat.at
  112. index 081d7d20277e..eec4638deeaa 100644
  113. --- a/tests/symlinkat.at
  114. +++ b/tests/symlinkat.at
  115. @@ -1 +1,3 @@
  116. SB_CHECK(1)
  117. +SB_CHECK(2)
  118. +SB_CHECK(3)
  119. --
  120. 2.12.0