glibc-2.27.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. diff -ruNp a/elf/dl-load.c b/elf/dl-load.c
  2. --- a/elf/dl-load.c
  3. +++ b/elf/dl-load.c
  4. @@ -46,6 +46,7 @@
  5. #include <dl-machine-reject-phdr.h>
  6. #include <dl-sysdep-open.h>
  7. +#include <glibc-version.h>
  8. #include <endian.h>
  9. #if BYTE_ORDER == BIG_ENDIAN
  10. @@ -1318,6 +1319,9 @@ cannot enable executable stack as shared
  11. DL_AFTER_LOAD (l);
  12. #endif
  13. + /* register the library to SHIM */
  14. + register_library(l->l_name, l->l_addr);
  15. +
  16. /* Now that the object is fully initialized add it to the object list. */
  17. _dl_add_to_namespace_list (l, nsid);
  18. diff -ruNp a/elf/Makefile b/elf/Makefile
  19. --- a/elf/Makefile
  20. +++ b/elf/Makefile
  21. @@ -21,7 +21,7 @@ subdir := elf
  22. include ../Makeconfig
  23. -headers = elf.h bits/elfclass.h link.h bits/link.h
  24. +headers = elf.h bits/elfclass.h link.h bits/link.h syscalldb.h
  25. routines = $(all-dl-routines) dl-support dl-iteratephdr \
  26. dl-addr dl-addr-obj enbl-secure dl-profstub \
  27. dl-origin dl-libc dl-sym dl-sysdep dl-error \
  28. @@ -33,7 +33,8 @@ dl-routines = $(addprefix dl-,load looku
  29. runtime init fini debug misc \
  30. version profile tls origin scope \
  31. execstack caller open close trampoline \
  32. - exception sort-maps)
  33. + exception sort-maps) \
  34. + syscalldb syscallas
  35. ifeq (yes,$(use-ldconfig))
  36. dl-routines += dl-cache
  37. endif
  38. diff -ruNp a/elf/rtld.c b/elf/rtld.c
  39. --- a/elf/rtld.c
  40. +++ b/elf/rtld.c
  41. @@ -439,6 +439,23 @@ _dl_start_final (void *arg, struct dl_st
  42. return start_addr;
  43. }
  44. +/* For graphene, check if glibc version match to the compatible SHIM
  45. + library. If not, tell the user to update glibc. */
  46. +#include "glibc-version.h"
  47. +
  48. +const unsigned int glibc_version __attribute__((weak)) = GLIBC_VERSION;
  49. +
  50. +static void __attribute__((noinline,optimize("-O0")))
  51. +check_glibc_version (void)
  52. +{
  53. + if (glibc_version != GLIBC_VERSION)
  54. + {
  55. + _dl_fatal_printf ("Warning from Graphene: "
  56. + "Glibc version is incorrect. Please rebuild Glibc.\n");
  57. + _exit (1);
  58. + }
  59. +}
  60. +
  61. static ElfW(Addr) __attribute_used__
  62. _dl_start (void *arg)
  63. {
  64. @@ -510,6 +527,9 @@ _dl_start (void *arg)
  65. therefore need not test whether we have to allocate the array
  66. for the relocation results (as done in dl-reloc.c). */
  67. + /* For Graphene, check if the glibc version is correct. */
  68. + check_glibc_version();
  69. +
  70. /* Now life is sane; we can call functions and access global data.
  71. Set up to use the operating system facilities, and find out from
  72. the operating system's program loader where to find the program
  73. diff -ruNp a/elf/Versions b/elf/Versions
  74. --- a/elf/Versions
  75. +++ b/elf/Versions
  76. @@ -79,4 +82,7 @@ ld {
  77. # Set value of a tunable.
  78. __tunable_get_val;
  79. }
  80. + SHIM {
  81. + syscalldb; glibc_version; glibc_option; register_library;
  82. + }
  83. }
  84. diff -ruNp a/Makeconfig b/Makeconfig
  85. --- a/Makeconfig
  86. +++ b/Makeconfig
  87. @@ -916,7 +916,8 @@ endif # $(+cflags) == ""
  88. # current directory.
  89. +includes = -I$(..)include $(if $(subdir),$(objpfx:%/=-I%)) \
  90. $(+sysdep-includes) $(includes) \
  91. - $(patsubst %/,-I%,$(..)) $(libio-include) -I. $(sysincludes)
  92. + $(patsubst %/,-I%,$(..)) $(libio-include) -I. $(sysincludes) \
  93. + -I$(common-objpfx)../shim/include
  94. # Since libio has several internal header files, we use a -I instead
  95. # of many little headers in the include directory.
  96. diff -ruNp a/Makefile b/Makefile
  97. --- a/Makefile
  98. +++ b/Makefile
  99. @@ -179,6 +179,8 @@ $(inst_includedir)/gnu/stubs.h: $(+force
  100. install-others-nosubdir: $(installed-stubs)
  101. endif
  102. +# For Graphene
  103. +CFLAGS-syscalldb.c = -fPIC
  104. # Since stubs.h is never needed when building the library, we simplify the
  105. # hairy installation process by producing it in place only as the last part
  106. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/cancellation.S b/sysdeps/unix/sysv/linux/x86_64/cancellation.S
  107. --- a/sysdeps/unix/sysv/linux/x86_64/cancellation.S
  108. +++ b/sysdeps/unix/sysv/linux/x86_64/cancellation.S
  109. @@ -109,7 +109,7 @@ ENTRY(__pthread_disable_asynccancel)
  110. xorq %r10, %r10
  111. addq $CANCELHANDLING, %rdi
  112. LOAD_PRIVATE_FUTEX_WAIT (%esi)
  113. - syscall
  114. + SYSCALLDB
  115. movl %fs:CANCELHANDLING, %eax
  116. jmp 3b
  117. END(__pthread_disable_asynccancel)
  118. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/clone.S b/sysdeps/unix/sysv/linux/x86_64/clone.S
  119. --- a/sysdeps/unix/sysv/linux/x86_64/clone.S
  120. +++ b/sysdeps/unix/sysv/linux/x86_64/clone.S
  121. @@ -73,7 +73,7 @@ ENTRY (__clone)
  122. /* End FDE now, because in the child the unwind info will be
  123. wrong. */
  124. cfi_endproc;
  125. - syscall
  126. + SYSCALLDB
  127. testq %rax,%rax
  128. jl SYSCALL_ERROR_LABEL
  129. @@ -96,7 +96,7 @@ L(thread_start):
  130. /* Call exit with return value from function call. */
  131. movq %rax, %rdi
  132. movl $SYS_ify(exit), %eax
  133. - syscall
  134. + SYSCALLDB
  135. cfi_endproc;
  136. cfi_startproc;
  137. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/getcontext.S b/sysdeps/unix/sysv/linux/x86_64/getcontext.S
  138. --- a/sysdeps/unix/sysv/linux/x86_64/getcontext.S
  139. +++ b/sysdeps/unix/sysv/linux/x86_64/getcontext.S
  140. @@ -75,7 +75,7 @@ ENTRY(__getcontext)
  141. #endif
  142. movl $_NSIG8,%r10d
  143. movl $__NR_rt_sigprocmask, %eax
  144. - syscall
  145. + SYSCALLDB
  146. cmpq $-4095, %rax /* Check %rax for error. */
  147. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  148. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
  149. --- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
  150. +++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
  151. @@ -84,7 +84,7 @@ ENTRY(____longjmp_chk)
  152. xorl %edi, %edi
  153. lea -sizeSS(%rsp), %RSI_LP
  154. movl $__NR_sigaltstack, %eax
  155. - syscall
  156. + SYSCALLDB
  157. /* Without working sigaltstack we cannot perform the test. */
  158. testl %eax, %eax
  159. jne .Lok2
  160. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S b/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
  161. --- a/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
  162. +++ b/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
  163. @@ -90,7 +90,7 @@ __lll_lock_wait_private:
  164. 1: LIBC_PROBE (lll_lock_wait_private, 1, %rdi)
  165. movl $SYS_futex, %eax
  166. - syscall
  167. + SYSCALLDB
  168. 2: movl %edx, %eax
  169. xchgl %eax, (%rdi) /* NB: lock is implied */
  170. @@ -130,7 +130,7 @@ __lll_lock_wait:
  171. 1: LIBC_PROBE (lll_lock_wait, 2, %rdi, %rsi)
  172. movl $SYS_futex, %eax
  173. - syscall
  174. + SYSCALLDB
  175. 2: movl %edx, %eax
  176. xchgl %eax, (%rdi) /* NB: lock is implied */
  177. @@ -185,7 +185,7 @@ __lll_timedlock_wait:
  178. 1: movl $SYS_futex, %eax
  179. movl $2, %edx
  180. - syscall
  181. + SYSCALLDB
  182. 2: xchgl %edx, (%rdi) /* NB: lock is implied */
  183. @@ -279,7 +279,7 @@ __lll_timedlock_wait:
  184. LOAD_FUTEX_WAIT (%esi)
  185. movq %r12, %rdi
  186. movl $SYS_futex, %eax
  187. - syscall
  188. + SYSCALLDB
  189. /* NB: %edx == 2 */
  190. xchgl %edx, (%r12)
  191. @@ -336,7 +336,7 @@ __lll_unlock_wake_private:
  192. LOAD_PRIVATE_FUTEX_WAKE (%esi)
  193. movl $1, %edx /* Wake one thread. */
  194. movl $SYS_futex, %eax
  195. - syscall
  196. + SYSCALLDB
  197. popq %rdx
  198. cfi_adjust_cfa_offset(-8)
  199. @@ -366,7 +366,7 @@ __lll_unlock_wake:
  200. LOAD_FUTEX_WAKE (%esi)
  201. movl $1, %edx /* Wake one thread. */
  202. movl $SYS_futex, %eax
  203. - syscall
  204. + SYSCALLDB
  205. popq %rdx
  206. cfi_adjust_cfa_offset(-8)
  207. @@ -436,7 +436,7 @@ __lll_timedwait_tid:
  208. #endif
  209. movq %r12, %rdi
  210. movl $SYS_futex, %eax
  211. - syscall
  212. + SYSCALLDB
  213. cmpl $0, (%rdi)
  214. jne 1f
  215. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/setcontext.S b/sysdeps/unix/sysv/linux/x86_64/setcontext.S
  216. --- a/sysdeps/unix/sysv/linux/x86_64/setcontext.S
  217. +++ b/sysdeps/unix/sysv/linux/x86_64/setcontext.S
  218. @@ -43,7 +43,7 @@ ENTRY(__setcontext)
  219. movl $SIG_SETMASK, %edi
  220. movl $_NSIG8,%r10d
  221. movl $__NR_rt_sigprocmask, %eax
  222. - syscall
  223. + SYSCALLDB
  224. popq %rdi /* Reload %rdi, adjust stack. */
  225. cfi_adjust_cfa_offset(-8)
  226. cmpq $-4095, %rax /* Check %rax for error. */
  227. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/sigaction.c b/sysdeps/unix/sysv/linux/x86_64/sigaction.c
  228. --- a/sysdeps/unix/sysv/linux/x86_64/sigaction.c
  229. +++ b/sysdeps/unix/sysv/linux/x86_64/sigaction.c
  230. @@ -120,7 +120,7 @@ asm \
  231. " .type __" #name ",@function\n" \
  232. "__" #name ":\n" \
  233. " movq $" #syscall ", %rax\n" \
  234. - " syscall\n" \
  235. + SYSCALLDB_ASM \
  236. ".LEND_" #name ":\n" \
  237. ".section .eh_frame,\"a\",@progbits\n" \
  238. ".LSTARTFRAME_" #name ":\n" \
  239. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
  240. --- a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
  241. +++ b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
  242. @@ -75,7 +75,7 @@ ENTRY(__swapcontext)
  243. movl $SIG_SETMASK, %edi
  244. movl $_NSIG8,%r10d
  245. movl $__NR_rt_sigprocmask, %eax
  246. - syscall
  247. + SYSCALLDB
  248. cmpq $-4095, %rax /* Check %rax for error. */
  249. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  250. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/syscall.S b/sysdeps/unix/sysv/linux/x86_64/syscall.S
  251. --- a/sysdeps/unix/sysv/linux/x86_64/syscall.S
  252. +++ b/sysdeps/unix/sysv/linux/x86_64/syscall.S
  253. @@ -34,7 +34,7 @@ ENTRY (syscall)
  254. movq %r8, %r10
  255. movq %r9, %r8
  256. movq 8(%rsp),%r9 /* arg6 is on the stack. */
  257. - syscall /* Do the system call. */
  258. + SYSCALLDB /* Do the system call. */
  259. cmpq $-4095, %rax /* Check %rax for error. */
  260. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  261. ret /* Return to caller. */
  262. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
  263. --- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
  264. +++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
  265. @@ -22,6 +22,7 @@
  266. #include <sysdeps/unix/sysv/linux/sysdep.h>
  267. #include <sysdeps/unix/x86_64/sysdep.h>
  268. #include <tls.h>
  269. +#include "syscalldb.h"
  270. #if IS_IN (rtld)
  271. # include <dl-sysdep.h> /* Defines RTLD_PRIVATE_ERRNO. */
  272. @@ -177,7 +178,7 @@
  273. # define DO_CALL(syscall_name, args) \
  274. DOARGS_##args \
  275. movl $SYS_ify (syscall_name), %eax; \
  276. - syscall;
  277. + SYSCALLDB;
  278. # define DOARGS_0 /* nothing */
  279. # define DOARGS_1 /* nothing */
  280. @@ -241,7 +260,7 @@
  281. ({ \
  282. unsigned long int resultvar; \
  283. asm volatile ( \
  284. - "syscall\n\t" \
  285. + SYSCALLDB \
  286. : "=a" (resultvar) \
  287. : "0" (number) \
  288. : "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \
  289. @@ -255,7 +270,7 @@
  290. TYPEFY (arg1, __arg1) = ARGIFY (arg1); \
  291. register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \
  292. asm volatile ( \
  293. - "syscall\n\t" \
  294. + SYSCALLDB \
  295. : "=a" (resultvar) \
  296. : "0" (number), "r" (_a1) \
  297. : "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \
  298. @@ -271,7 +286,7 @@
  299. register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \
  300. register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \
  301. asm volatile ( \
  302. - "syscall\n\t" \
  303. + SYSCALLDB \
  304. : "=a" (resultvar) \
  305. : "0" (number), "r" (_a1), "r" (_a2) \
  306. : "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \
  307. @@ -289,7 +304,7 @@
  308. register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \
  309. register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \
  310. asm volatile ( \
  311. - "syscall\n\t" \
  312. + SYSCALLDB \
  313. : "=a" (resultvar) \
  314. : "0" (number), "r" (_a1), "r" (_a2), "r" (_a3) \
  315. : "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \
  316. @@ -309,7 +324,7 @@
  317. register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \
  318. register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \
  319. asm volatile ( \
  320. - "syscall\n\t" \
  321. + SYSCALLDB \
  322. : "=a" (resultvar) \
  323. : "0" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4) \
  324. : "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \
  325. @@ -331,7 +346,7 @@
  326. register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \
  327. register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \
  328. asm volatile ( \
  329. - "syscall\n\t" \
  330. + SYSCALLDB \
  331. : "=a" (resultvar) \
  332. : "0" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4), \
  333. "r" (_a5) \
  334. @@ -356,7 +371,7 @@
  335. register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \
  336. register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \
  337. asm volatile ( \
  338. - "syscall\n\t" \
  339. + SYSCALLDB \
  340. : "=a" (resultvar) \
  341. : "0" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4), \
  342. "r" (_a5), "r" (_a6) \
  343. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/vfork.S b/sysdeps/unix/sysv/linux/x86_64/vfork.S
  344. --- a/sysdeps/unix/sysv/linux/x86_64/vfork.S
  345. +++ b/sysdeps/unix/sysv/linux/x86_64/vfork.S
  346. @@ -36,7 +36,7 @@ ENTRY (__vfork)
  347. /* Stuff the syscall number in RAX and enter into the kernel. */
  348. movl $SYS_ify (vfork), %eax
  349. - syscall
  350. + SYSCALLDB
  351. /* Push back the return PC. */
  352. pushq %rdi
  353. diff -ruNp a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
  354. --- a/sysdeps/x86_64/dl-machine.h
  355. +++ b/sysdeps/x86_64/dl-machine.h
  356. @@ -577,7 +577,8 @@ elf_machine_lazy_rel (struct link_map *m
  357. value = ((ElfW(Addr) (*) (void)) value) ();
  358. *reloc_addr = value;
  359. }
  360. - else
  361. + /* for graphene, get around R_X86_64_NONE */
  362. + else if (__builtin_expect (r_type != R_X86_64_NONE, 1))
  363. _dl_reloc_bad_type (map, r_type, 1);
  364. }
  365. diff -ruNp a/sysdeps/x86_64/nptl/tls.h b/sysdeps/x86_64/nptl/tls.h
  366. --- a/sysdeps/x86_64/nptl/tls.h
  367. +++ b/sysdeps/x86_64/nptl/tls.h
  368. @@ -29,6 +29,7 @@
  369. # include <libc-pointer-arith.h> /* For cast_to_integer. */
  370. # include <kernel-features.h>
  371. # include <dl-dtv.h>
  372. +# include <syscalldb.h>
  373. /* Replacement type for __m128 since this file is included by ld.so,
  374. which is compiled with -mno-sse. It must not change the alignment
  375. @@ -144,7 +149,7 @@ typedef struct
  376. _head->self = _thrdescr; \
  377. \
  378. /* It is a simple syscall to set the %fs value for the thread. */ \
  379. - asm volatile ("syscall" \
  380. + asm volatile (SYSCALLDB \
  381. : "=a" (_result) \
  382. : "0" ((unsigned long int) __NR_arch_prctl), \
  383. "D" ((unsigned long int) ARCH_SET_FS), \