This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug nptl/12683] Race conditions in pthread cancellation
- From: "cvs-commit at gcc dot gnu.org" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Mon, 26 Feb 2018 21:10:11 +0000
- Subject: [Bug nptl/12683] Race conditions in pthread cancellation
- Auto-submitted: auto-generated
- References: <bug-12683-131@http.sourceware.org/bugzilla/>
https://sourceware.org/bugzilla/show_bug.cgi?id=12683
--- Comment #29 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".
The branch, azanella/bz12683 has been created
at d95b8c5f0fa8a8a2b99e63461df3fbe917990a5e (commit)
- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=d95b8c5f0fa8a8a2b99e63461df3fbe917990a5e
commit d95b8c5f0fa8a8a2b99e63461df3fbe917990a5e
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Tue Jan 24 21:05:56 2017 -0200
nptl: Remove THREAD_ATOMIC_* macros
This patch removes the ununsed THREAD_ATOMIC_* macros now that nptl
code is using C11 atomics.
Checked on x86_64-linux-gnu and i686-linux-gnu.
* manual/pattern.texi (THREAD_ATOMIC_BIT_SET): Remove.
(THREAD_ATOMIC_CMPXCHG_VAL): Likewise.
* nptl/pthreadP.h (THREAD_ATOMIC_CMPXCHG_VAL): Likewise.
(THREAD_ATOMIC_BIT_SET): Likewise.
* sysdeps/i386/nptl/tls.h (THREAD_ATOMIC_CMPXCHG_VAL): Likewise.
(THREAD_ATOMIC_AND): Likewise.
* sysdeps/x86_64/nptl/tls.h (THREAD_ATOMIC_CMPXCHG_VAL): Likewise.
(THREAD_ATOMIC_AND): Likewise.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=fdafb04cb8269446e056273bcd923a4186113790
commit fdafb04cb8269446e056273bcd923a4186113790
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Tue Jan 24 09:17:37 2017 -0200
nptl: cancelhandling refactor
This patch basically uses glibc C11 atomic function to access and
modify struct pthread cancelhandling variable. All plain access
are handled using the atomic_load_* functions and THREAD_ATOMIC_BIT_SET
is replaced by atomic_fetch_or_acquire.
Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
* nptl/descr.h (CANCELED_BITMASK): Rename to THREAD_CANCELED.
(EXITING_BITMASK): Rename to THREAD_EXITING.
(TERMINATED_BITMARK): Rename to THREAD_TERMINATED.
* nptl/allocatestack.c (setxid_mark_thread): Use THREAD_* instead of
*_BITMASK and use glibc C11 atomic function to access pthread
cancelhandling.
* nptl/libc-cancellation.c (__syscall_cancel): Likewise.
* nptl/nptl-init.c (sigcancel_handler): Likewise.
* nptl/pthread_cancel.c (pthread_cancel): Likewise.
* nptl/pthread_create.c (__free_tcb): Likewise.
(START_THREAD_DEFN): Likewise.
(__pthread_create_2_1): Likewise.
* nptl/pthread_detach.c (pthread_detach): Likewise.
* nptl/pthread_exit.c (__pthread_exit): Likewise.
* nptl/pthread_join.c (pthread_join): Likewise.
* nptl_db/td_thr_get_info.c (td_thr_get_info): Likewise.
* nptl_db/td_thr_getfpregs.c (td_thr_getfpregs): Likewise.
* nptl_db/td_thr_getgregs.c (td_thr_getregs): Likewise.
* nptl_db/td_thr_setfpregs.c (td_thr_setfpregs): Likewise.
* nptl_db/td_thr_setgregs.c (td_thr_setgregs): Likewise.
* sysdeps/unix/sysv/linux/arm/syscall_cancel.S
(__syscall_cancel_arch): Change CANCELED_BITMASK to
THREAD_CANCELED in comment.
* sysdeps/unix/sysv/linux/syscall_cancel.c
(__syscall_cancel_arch): Likewise.
* sysdeps/x86_64/nptl/tcb-offsets.sym (TCB_CANCELED_BITMASK):
Remove.
(TCB_EXITING_BITMASK): Likewise.
(TCB_TERMINATED_BITMASK): Likewise.
* sysdeps/unix/sysv/linux/i386/syscall_cancel.S
(__syscall_cancel_arch): Likewise.
* sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S
(__syscall_cancel_arch): Likewise.
* sysdeps/unix/sysv/linux/sh/syscall_cancel.S
(__syscall_cancel_arch): Likewise.
* sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S
(__syscall_cancel_arch): Likewise.
* sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S
(__syscall_cancel_arch): Likewise.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=9037ec95f5d0e8ac5d846f3b2181e468a15e6819
commit 9037ec95f5d0e8ac5d846f3b2181e468a15e6819
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Tue Jul 18 16:33:41 2017 -0300
nptl: Remove setxid bit from cancelhandling
This patch removes the setxid signaling out of cancelhandling flag
and use its own member of pthread instead. The idea is 1 simplify
setxid handling to now mix atomic operation with thread cancellation
since both are orthogonal, 2. isolate cancelhandling variable to only
track thread cancel state.
It also uses glibc C11 atomic operation while accessing new setxid_op
field.
Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
* nptl/allocatestack.c (get_cached_stack): Set sexid_op on new
allocated stack.
(setxid_mark_thread): Use setxid_op to mark thread as executing
a sexid operation insteaf of using cancelhandling. Also adapt
algorithm to use C11 atomic analogous functions.
(setxid_unmark_thread): Likewise.
(setxid_signal_thread): Likewise.
* nptl/nptl-init.c (sighandler_setxid): Likewise.
* nptl/pthread_create.c (sighandler_setxid): Likewise.
* nptl/descr.h (SETXID_BIT): Remove define.
(SETXID_BITMASK): Likewise.
(setxid_op): New member.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c3f33edb679e95ded02b15fd5fe8d760a759ac3c
commit c3f33edb679e95ded02b15fd5fe8d760a759ac3c
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Fri Jan 20 17:24:35 2017 -0200
nptl: Move cancel state and type out cancelhandling
This patch move both the cancel state (PTHREAD_CANCEL_ENABLE and
PTHREAD_CANCEL_DISABLE) and cancel type (PTHREAD_CANCEL_DEFERRED and
PTHREAD_CANCEL_ASYNCHRONOUS) out of cancelhandling member. The idea
is to avoid atomic handling of cancelhandling where these states
are concerned since with exclusive member they are not concurrent
accessed:
* pthread_setcancel{type,state} and internal functions
__pthread_{un}register_cancel_defer (and its analogous compat
versions) only change the type/state of the calling thread.
* __syscall_cancel also only requires to check the state of
calling thread.
* sigcancel_handler is executed only for the thread about to be
potentially canceled.
* pthread_join deadlock checks only requires access the state for
the calling thread.
* Same behavior for pthread_testcancel.
With this change the cancelhandling member from pthread struct is
used solely for cancelation handling and setxid signaling.
Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
* nptl/allocatestack.c (get_cached_stack): Set both cancelstate
and canceltype on new stack allocation.
* nptl/cleanup_defer.c (__pthread_register_cancel_defer): Set
canceltype directly instead of using cancelhandling member.
(__pthread_unregister_cancel_restore): Likewise.
* nptl/cleanup_defer_compat.c (_pthread_cleanup_push_defer):
Likewise.
(_pthread_cleanup_pop_restore): Likewise.
* nptl/descr.h (CANCELSTATE_BIT): Remove flag.
(CANCELSTATE_BITMASK): Likewise.
(CANCELTYPE_BIT): Likewise.
(CANCELTYPE_BITMSK): Likewise.
(CANCEL_RESTMASK): Likewise.
(CANCEL_ENABLED_AND_CANCELED): Likewise.
(CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS): Likewise.
(cancelstate): New member.
(canceltype): Likewise.
* nptl/libc-cancellation.c (__syscall_cancel): Use cancelstate
instead of cancelhandling member.
* nptl/nptl-init.c (sigcancel_handler): Likewise.
* nptl/pthreadP.h (__do_cancel): Likewise.
(CANCELLATION_P): Likewise.
* nptl/pthread_join.c (pthread_join): Remove CANCELLATION_P
usage.
* nptl/pthread_testcancel.c (__pthread_testcancel): Likewise.
* nptl/pthread_setcancelstate.c (__pthread_setcancelstate):
Use cancelstate member instead of cancelhandling.
* nptl/pthread_setcanceltype.c (__pthread_setcanceltype): Use
canceltype member instead of canceltype.
* sysdeps/x86_64/nptl/tcb-offsets.sym (TCB_CANCELSTATE_BITMASK):
Remove.
(TCB_CANCELTYPE_BITMASK): Likewise.
(TCB_CANCEL_RETMASK): Likewise.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=ca81de5ed9021e4b96e7e3b0ce49eea806f92460
commit ca81de5ed9021e4b96e7e3b0ce49eea806f92460
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Mon Feb 26 16:24:15 2018 -0300
nptl: riscv: Fix Race conditions in pthread cancellation (BZ#12683)
This patch adds the riscv modifications required for the BZ#12683.
It basically adds the required ucontext_get_pc function.
The default syscall_cancel.c should be as expected for RISCV. With
GCC 7.3.1 syscall_cancel.c generates the following code:
0000000000000000 <__GI___syscall_cancel_arch>:
0: 8346 mv t1,a7
0000000000000002 <__syscall_cancel_arch_start>:
2: 00052883 lw a7,0(a0)
6: 0048f893 andi a7,a7,4
a: 00089c63 bnez a7,22 <.L0 >
e: 88ae mv a7,a1
10: 8532 mv a0,a2
12: 85b6 mv a1,a3
14: 863a mv a2,a4
16: 86be mv a3,a5
18: 8742 mv a4,a6
1a: 879a mv a5,t1
1c: 00000073 ecall
0000000000000020 <__syscall_cancel_arch_end>:
20: 8082 ret
22: 1141 addi sp,sp,-16
24: e406 sd ra,8(sp)
26: 00000097 auipc ra,0x0
2a: 000080e7 jalr ra # 26 <.L0 >
Checked with a build for riscv64-linux-gnu with run-built-tests=no.
[BZ #12683]
* sysdeps/unix/sysv/linux/riscv/sigcontextinfo.h (ucontext_get_pc):
New fuction.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=33154acabe37c1bc4b4c180229d7f120b512dab9
commit 33154acabe37c1bc4b4c180229d7f120b512dab9
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Fri Feb 3 21:07:07 2017 -0200
nptl: hppa: Fix Race conditions in pthread cancellation (BZ#12683)
This patch adds the hppa modifications required for the BZ#12683.
It basically adds the required __pthread_get_pc function.
HPPA requires an arch-specific syscall_cancel because the
INTERNAL_SYSCALL_NCS adds some instruction to fetch the returned
syscalls value. The implementation were based on on default C
version built with GCC 6.1
Checked on hppa-linux-gnu.
[BZ #12683]
* sysdeps/unix/sysv/linux/hppa/sigcontextinfo.h: New file.
* sysdeps/unix/sysv/linux/hppa/syscall_cancel.S: Likewise.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5f51f6b99358e17c177010167bd5dc56fecf1788
commit 5f51f6b99358e17c177010167bd5dc56fecf1788
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Mon Jan 16 17:03:07 2017 -0200
nptl: mips: Fix Race conditions in pthread cancellation (BZ#12683)
This patch adds the mips modifications required for the BZ#12683.
It adds the required ucontext_get_pc function, a mips32 cancellable
syscall wrapper and 7 argument cancellable syscall support.
To avoid code pessimization and add a requirement on all architectures
to support {INLINE,INTERNAL)_SYSCALL with 7 argument, its support is
added through a flag, HAVE_CANCELABLE_SYSCALL_WITH_7_ARGS, which changes
the signature and prototype of the requires macros and functions
(SYSCALL_CANCEL, __syscall_cancel and __syscall_cancel_arch). As
default 6 arguments cancellable syscalls are use.
MIPS o32 requires an arch-specific implementation because
INTERNAL_SYSCALL_NCS adds an 'addiu' just after the syscall
instruction which invalidates the checks on sigcancel_handler.
Checked against a build and make check run-built-tests=no for
mips-gnu-linux, mips64-linux-gnu, mips64-n32-linux-gnu. I also
ran some basic o32 and n64 cancellation tests on a simulated
mips64 qemu system.
[BZ #12683]
* nptl/libc-cancellation.c (__syscall_cancel): Define and use 7
argument syscall if architecture requires it.
* nptl/pthreadP.h (__syscall_cancel_arch): Likewise.
* sysdeps/unix/sysdep.h (__syscall_cancel, __SYSCALL_CANCEL*): Define
with 7 argument if architecture requires it.
(__SYSCALL_CANCEL7_ARG_DEF): New macro.
(__SYSCALL_CANCEL7_ARG): Likewise.
(__SYSCALL_CANCEL7_ARG7): Likewise.
* sysdeps/unix/sysv/linux/syscall_cancel.c (__syscall_cancel_arch):
Likewise.
* sysdeps/mips/nptl/tls.h (READ_THREAD_POINTER): Check __mips_isa_rev
existance for macro definition.
* sysdeps/unix/sysv/linux/mips/sigcontextinfo.h (ucontext_get_pc):
New function.
* sysdeps/unix/sysv/linux/mips/mips32/syscall_cancel.S: New file.
* sysdeps/unix/sysv/linux/mips/mips32/sysdep.h
(HAVE_CANCELABLE_SYSCALL_WITH_7_ARGS): Define.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=e4db079ad7eea4a58dc6713dc2f8f1817e8de480
commit e4db079ad7eea4a58dc6713dc2f8f1817e8de480
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Mon Jan 16 17:03:03 2017 -0200
nptl: sh: Fix Race conditions in pthread cancellation (BZ#12683)
This patch adds the sh modifications required for the BZ#12683.
It basically adds the required ucontext_get_pc function and a
cancellable syscall wrapper.
SH requires an arch-specific syscall_cancel because the
INTERNAL_SYSCALL_NCS adds the required or instruction to workaround
a hardware bug [1]. The implementation were based on on default C
version built with GCC 6.2.1.
Checked against a build and make check run-built-tests=no for
sh4-linux-gnu.
[BZ #12683]
* sysdeps/unix/sysv/linux/sh/syscall_cancel.S: New file.
* sysdeps/unix/sysv/linux/sh/sigcontextinfo.h (ucontext_get_pc):
New function.
[1] http://documentation.renesas.com/eng/products/mpumcu/tu/tnsh7456ae.pdf
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=793aeb3010780a615f2f4b2236cad3f1707e88e4
commit 793aeb3010780a615f2f4b2236cad3f1707e88e4
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Mon Jan 16 17:02:53 2017 -0200
nptl: nios2: Fix Race conditions in pthread cancellation (BZ#12683)
This patch adds the nios2 modifications required for the BZ#12683.
It basically adds the required ucontext_get_pc function.
The default syscall_cancel.c should be as expected for NIOS2. With
GCC 6.2.1 syscall_cancel.c generates the following code:
---
00000000 <__GI___syscall_cancel_arch>:
0: defffe04 addi sp,sp,-8
4: dd800015 stw r22,0(sp)
8: 002ce03a nextpc r22
c: 02000034 movhi r8,0
10: 42000004 addi r8,r8,0
14: dfc00115 stw ra,4(sp)
18: b22d883a add r22,r22,r8
0000001c <__syscall_cancel_arch_start>:
1c: 20c00017 ldw r3,0(r4)
20: 18c0010c andi r3,r3,4
24: 18000f1e bne r3,zero,64 <__syscall_cancel_arch_end+0x18>
28: 3015883a mov r10,r6
2c: 2805883a mov r2,r5
30: da400517 ldw r9,20(sp)
34: 380b883a mov r5,r7
38: da000417 ldw r8,16(sp)
3c: d9c00317 ldw r7,12(sp)
40: d9800217 ldw r6,8(sp)
44: 5009883a mov r4,r10
48: 003b683a trap 0
0000004c <__syscall_cancel_arch_end>:
4c: 38000126 beq r7,zero,54 <__syscall_cancel_arch_end+0x8>
50: 0085c83a sub r2,zero,r2
54: dfc00117 ldw ra,4(sp)
58: dd800017 ldw r22,0(sp)
5c: dec00204 addi sp,sp,8
60: f800283a ret
64: b0800017 ldw r2,0(r22)
68: 103ee83a callr r2
---
Checked against a build and make check run-built-tests=no for
nios2-linux-gnu.
[BZ #12683]
* sysdeps/unix/sysv/linux/nios2/sigcontextinfo.h (ucontext_get_pc):
New function.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=14f629ccf56a06dba93cf6c1808496acb81edec8
commit 14f629ccf56a06dba93cf6c1808496acb81edec8
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Mon Jan 16 17:02:36 2017 -0200
nptl: sparc: Fix Race conditions in pthread cancellation (BZ#12683)
This patch adds the sparc modifications required for the BZ#12683.
It basically adds the required ucontext_get_pc function, cancellable
syscall wrappers, and a fix for pause.
Sparc requires arch-specific syscall_cancel implementation because
INLINE_SYSCALL_NCS uses the __SYSCALL_STRING (defined different
for sparc32 and sparc64) and it issues additional instructions
after the syscall one to check the resulting error code. When used
in the default syscall_cancel.c implementation the label
__syscall_cancel_arch_end is not placed just after the syscall as
expected. Both 32 and 64 bits version were based on default C version
built with GCC 6.1.
Also, different than other architectures, SPARC passes the sigcontext_t
struct pointer as third argument in the signal handler set with
SA_SIGINFO (some info at [1]) for 64 bits and the pt_regs in 32 bits.
From Linux code:
* arch/sparc/kernel/signal_64.c
428 /* 3. signal handler back-trampoline and parameters */
429 regs->u_regs[UREG_FP] = ((unsigned long) sf) - STACK_BIAS;
430 regs->u_regs[UREG_I0] = ksig->sig;
431 regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
432
433 /* The sigcontext is passed in this way because of how it
434 * is defined in GLIBC's /usr/include/bits/sigcontext.h
435 * for sparc64. It includes the 128 bytes of siginfo_t.
436 */
437 regs->u_regs[UREG_I2] = (unsigned long) &sf->info;
* arch/sparc/kernel/signal_32.c:
392 regs->u_regs[UREG_FP] = (unsigned long) sf;
393 regs->u_regs[UREG_I0] = ksig->sig;
394 regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
395 regs->u_regs[UREG_I2] = (unsigned long) &sf->regs;
396
397 regs->pc = (unsigned long) ksig->ka.sa.sa_handler;
398 regs->npc = (regs->pc + 4);
So to access the signal mask in the signal frame, a arch-specific
ucontext_get_mask is defined which obtain the sa_mask from the context.
Checked on a SPARC T5 for sparc64-linux-gnu and sparcv9-linux-gnu.
[BZ #12683]
* sysdeps/unix/sysv/linux/sparc/sparc32/sigcontextinfo.h
(ucontext_get_pc): New function.
* sysdeps/unix/sysv/linux/sparc/sparc64/sigcontextinfo.h
(ucontext_get_pc): Likewise.
* sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S: New file.
* sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S: Likwise.
* sysdeps/unix/sysv/linux/sparc/sparc64/pause.c: New file.
[1] https://www.spinics.net/lists/sparclinux/msg05037.html
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=9f21ab0e6f18e0f548d36a6f460b7ac6ae5f476e
commit 9f21ab0e6f18e0f548d36a6f460b7ac6ae5f476e
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Mon Jan 16 17:02:28 2017 -0200
nptl: tile: Fix Race conditions in pthread cancellation (BZ#12683)
This patch adds the tile modifications required for the BZ#12683.
It basically adds the required ucontext_get_pc function
The default syscall_cancel.c should be as expected for TILE. With
GCC 6.1 syscall_cancel.c generates the following code:
* TILEGX
0000000000000000 <__GI___syscall_cancel_arch>:
0: c7bf46ce576bfd9d { move r29, sp ; addi r28, sp, -24 ; st sp,
lr }
8: 283bf825401e0db6 { addi sp, sp, -32 ; move r10, r1 }
10: eeedf85b85c18d9b { addi r27, sp, 24 ; move lr, r2 ; st r28,
r29 }
18: eef5f88155bbf0c1 { move r1, r3 ; move r2, r4 ; st r27, r30 }
20: 283bf8c25107f143 { move r3, r5 ; move r4, r6 }
28: 283bf8e2d1483000 { move r5, r7 }
0000000000000030 <__syscall_cancel_arch_start>:
30: 9c5e4000340c3000 { ld4s r11, r0 }
38: 18182165d1483000 { andi r11, r11, 4 }
40: 17c00163d1483000 { bnez r11, 78
<__syscall_cancel_arch_end+0x20> }
48: 283bfee051483000 { move r0, lr }
50: 286b180051485000 { swint1 }
0000000000000058 <__syscall_cancel_arch_end>:
58: 180906ced1401ff7 { subx lr, zero, r1 ; addi r29, sp, 32 }
60: 87b8c6ce4dd77040 { cmovnez r0, r1, lr ; addi r28, sp, 24 ;
ld lr, r29 }
68: 9ef6400035cc3000 { ld r30, r28 }
70: 286a6ee040120db6 { addi sp, sp, 32 ; jrp lr }
78: 2000000051483000 { jal 78 <__syscall_cancel_arch_end+0x20> }
* TILEGX32
00000000 <__GI___syscall_cancel_arch>:
0: cbbfc6ce576bfd9d { move r29, sp ; addxi r28, sp, -8 ; st sp,
lr }
8: 283bf825402f0db6 { addxi sp, sp, -16 ; move r10, r1 }
10: eeedf860d5cbf0b7 { move lr, r2 ; move r1, r3 ; st r28, r29 }
18: 283bf8a1d107f102 { move r2, r4 ; move r3, r5 }
20: 283bf8e2d107f184 { move r4, r6 ; move r5, r7 }
00000028 <__syscall_cancel_arch_start>:
28: 9c5e4000340c3000 { ld4s r11, r0 }
30: 18182165d1483000 { andi r11, r11, 4 }
38: 17c0016351483000 { bnez r11, 68
<__syscall_cancel_arch_end+0x18> }
40: 283bfee051483000 { move r0, lr }
48: 286b180051485000 { swint1 }
00000050 <__syscall_cancel_arch_end>:
50: 28660fe540210d9d { addxi r29, sp, 16 ; subx r10, zero, r1 }
58: 9fbe40004dd4a040 { cmovnez r0, r1, r10 ; ld lr, r29 }
60: 286a6ee040210db6 { addxi sp, sp, 16 ; jrp lr }
68: 2000000051483000 { jal 68 <__syscall_cancel_arch_end+0x18> }
Checked against a build and make check run-built-tests=no for
tile-linux-gnu.
[BZ #12683]
* sysdeps/unix/sysv/linux/tile/sigcontextinfo.h (ucontext_get_pc):
New function.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5868f2b379c4dc9fed02585f5a9f6d41951a4b7f
commit 5868f2b379c4dc9fed02585f5a9f6d41951a4b7f
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Mon Jan 16 17:02:17 2017 -0200
nptl: microblaze: Fix Race conditions in pthread cancellation (BZ#12683)
This patch adds the microblaze modifications required for the BZ#12683.
It basically adds the required ucontext_get_pc function.
Microblaze requires an arch specific assembly implementation because
the archicture INTERNAL_SYSCALL_NCS implementation adds a nop after
the brki instruction because the instruction expect a delay branch
slot. I based this implementation on generated assembly using GCC 6.1.
Checked against a build and make check run-built-tests=no for
microblaze-linux-gnu.
[BZ #12683]
* sysdeps/unix/sysv/linux/microblaze/syscall_cancel.S: New file.
* sysdeps/unix/sysv/linux/microblaze/sigcontextinfo.h
(ucontext_get_pc): New function.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=a9d375373acbfc69dded5b12efbeef5c6ecdcf87
commit a9d375373acbfc69dded5b12efbeef5c6ecdcf87
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Mon Jan 16 17:02:08 2017 -0200
nptl: m68k: Fix Race conditions in pthread cancellation (BZ#12683)
This patch adds the m68k modifications required for the BZ#12683.
It basically adds the required ucontext_get_pc function
The default syscall_cancel.c should is as expected for m68k with
GCC 6.2.1. It generates the following code for syscall_cancel.os:
---
00000000 <__GI___syscall_cancel_arch>:
0: 4e56 0000 linkw %fp,#0
4: 48e7 3c00 moveml %d2-%d5,%sp@-
00000008 <__syscall_cancel_arch_start>:
8: 206e 0008 moveal %fp@(8),%a0
c: 2010 movel %a0@,%d0
e: 0800 0002 btst #2,%d0
12: 6628 bnes 3c <__syscall_cancel_arch_end+0xa>
14: 206e 0024 moveal %fp@(36),%a0
18: 2a2e 0020 movel %fp@(32),%d5
1c: 282e 001c movel %fp@(28),%d4
20: 262e 0018 movel %fp@(24),%d3
24: 242e 0014 movel %fp@(20),%d2
28: 222e 0010 movel %fp@(16),%d1
2c: 202e 000c movel %fp@(12),%d0
30: 4e40 trap #0
00000032 <__syscall_cancel_arch_end>:
32: 4cee 003c fff0 moveml %fp@(-16),%d2-%d5
38: 4e5e unlk %fp
3a: 4e75 rts
3c: 61ff 0000 0000 bsrl 3e <__syscall_cancel_arch_end+0xc>
---
Checked against a build and make check run-built-tests=no for
m68k-linux-gnu.
[BZ #12683]
* sysdeps/unix/sysv/linux/m68k/sigcontextinfo.h (ucontext_get_pc):
New function.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5bd68272946551afa1d5578fc67b4acacf46e09a
commit 5bd68272946551afa1d5578fc67b4acacf46e09a
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Mon Jan 16 17:01:58 2017 -0200
nptl: alpha: Fix Race conditions in pthread cancellation (BZ#12683)
This patch adds the alpha modifications required for the BZ#12683.
It basically adds the required ucontext_get_pc function
The default syscall_cancel.c should be fine for alpha and GCC 6.1
generates the following cod for syscall_cancel.os:
---
0000000000000000 <__GI___syscall_cancel_arch>:
0: 00 00 bb 27 ldah gp,0(t12)
4: 00 00 bd 23 lda gp,0(gp)
8: f0 ff de 23 lda sp,-16(sp)
c: 00 04 f1 47 mov a1,v0
10: 00 00 5e b7 stq ra,0(sp)
0000000000000014 <__syscall_cancel_arch_start>:
14: 00 00 30 a0 ldl t0,0(a0)
18: 01 00 e1 43 sextl t0,t0
1c: 01 90 20 44 and t0,0x4,t0
20: 0f 00 20 f4 bne t0,60 <__syscall_cancel_arch_end+0x20>
24: 10 04 f2 47 mov a2,a0
28: 11 04 f3 47 mov a3,a1
2c: 12 04 f4 47 mov a4,a2
30: 10 00 9e a6 ldq a4,16(sp)
34: 13 04 f5 47 mov a5,a3
38: 18 00 be a6 ldq a5,24(sp)
3c: 83 00 00 00 callsys
0000000000000040 <__syscall_cancel_arch_end>:
40: 21 05 e0 43 negq v0,t0
44: 00 00 5e a7 ldq ra,0(sp)
48: c0 04 61 46 cmovne a3,t0,v0
4c: 10 00 de 23 lda sp,16(sp)
50: 01 80 fa 6b ret
54: 00 00 fe 2f unop
58: 1f 04 ff 47 nop
5c: 00 00 fe 2f unop
60: 00 00 7d a7 ldq t12,0(gp)
64: 00 40 5b 6b jsr ra,(t12),68
<__syscall_cancel_arch_end+0x28>
68: 1f 04 ff 47 nop
6c: 00 00 fe 2f unop
---
Checked on alpha-linux-gnu, no regression found.
[BZ #12683]
* sysdeps/unix/sysv/linux/alpha/sigcontextinfo.h (ucontext_get_pc):
New function.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=3a5a8aa8f6e665fb0fdf3ab6befbaa4a9b91a913
commit 3a5a8aa8f6e665fb0fdf3ab6befbaa4a9b91a913
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Mon Jan 16 17:01:44 2017 -0200
nptl: ia64: Fix Race conditions in pthread cancellation (BZ#12683)
This patch adds the s390 modifications required for the BZ#12683.
It basically adds the required ucontext_get_pc function. a workaround
for mismatched sigcontext::sa_flags defiition between kernel and
GLIBC (tracked by BZ#21634), and an arch specific syscall_cancel
implementation.
IA64 requires an arch-specific syscall_cancel implemetantion because
{INLINE,INTERNAL}_SYSCALL is implemented by branching to a gate
DSO (similar to i386) which renders the pointer comparison in
SIGCANCEL handler wrong. This incurs in performance penalty due the
use of a break instruction insteaf of a eds one, however
cancellable syscalls should potentially incur in syscalls blocking.
Checked with a ia64-linux-gnu build with run-tests-built=no.
[BZ #12683]
* sysdeps/unix/sysv/linux/ia64/sigcontextinfo.h (ucontext_get_pc,
ucontext_get_mask): New functions.
* sysdeps/unix/sysv/linux/ia64/syscall_cancel.S: New file.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=d47c1d0fa0b4ce173b9fd06caaf7a999a6a78af8
commit d47c1d0fa0b4ce173b9fd06caaf7a999a6a78af8
Author: Adhemerval Zanella <adhemerval.zanella@linaro.com>
Date: Wed Aug 12 10:51:38 2015 -0300
nptl: s390: Fix Race conditions in pthread cancellation (BZ#12683)
This patch adds the s390 modifications required for the BZ#12683 fix.
It basically adds the required ucontext_get_pc function.
The built cancelable syscall wrapper for s390 using GCC 7.2.1 and
default configuration flags shows the wrappers on expected corrected
places:
---
__GI___syscall_cancel_arch:
.LFB39:
.cfi_startproc
stm %r6,%r15,24(%r15)
.cfi_offset 6, -72
.cfi_offset 7, -68
.cfi_offset 8, -64
.cfi_offset 9, -60
.cfi_offset 10, -56
.cfi_offset 11, -52
.cfi_offset 12, -48
.cfi_offset 13, -44
.cfi_offset 14, -40
.cfi_offset 15, -36
ahi %r15,-96
.cfi_def_cfa_offset 192
.global __syscall_cancel_arch_start
.type __syscall_cancel_arch_start,@function
__syscall_cancel_arch_start:
l %r0,0(%r2)
tml %r0,4
jne .L5
lr %r1,%r3
lr %r2,%r4
lr %r3,%r5
lr %r4,%r6
l %r5,192(%r15)
l %r6,196(%r15)
l %r7,200(%r15)
svc 0
.global __syscall_cancel_arch_end
.type __syscall_cancel_arch_end,@function
__syscall_cancel_arch_end:
l %r4,152(%r15)
lm %r6,%r15,120(%r15)
.cfi_remember_state
.cfi_restore 15
.cfi_restore 14
.cfi_restore 13
.cfi_restore 12
.cfi_restore 11
.cfi_restore 10
.cfi_restore 9
.cfi_restore 8
.cfi_restore 7
.cfi_restore 6
.cfi_def_cfa_offset 96
br %r4
.L5:
.cfi_restore_state
brasl %r14,__syscall_do_cancel
.cfi_endproc
---
The s390x version also shows similar placement:
---
__GI___syscall_cancel_arch:
.cfi_startproc
stmg %r6,%r15,48(%r15)
.cfi_offset 6, -112
.cfi_offset 7, -104
.cfi_offset 8, -96
.cfi_offset 9, -88
.cfi_offset 10, -80
.cfi_offset 11, -72
.cfi_offset 12, -64
.cfi_offset 13, -56
.cfi_offset 14, -48
.cfi_offset 15, -40
aghi %r15,-160
.cfi_def_cfa_offset 320
.global __syscall_cancel_arch_start
.type __syscall_cancel_arch_start,@function
__syscall_cancel_arch_start:
l %r0,0(%r2)
tmll %r0,4
jne .L5
lgr %r1,%r3
lgr %r2,%r4
lgr %r3,%r5
lgr %r4,%r6
lg %r5,320(%r15)
lg %r6,328(%r15)
lg %r7,336(%r15)
svc 0
.global __syscall_cancel_arch_end
.type __syscall_cancel_arch_end,@function
__syscall_cancel_arch_end:
lg %r4,272(%r15)
lmg %r6,%r15,208(%r15)
.cfi_remember_state
.cfi_restore 15
.cfi_restore 14
.cfi_restore 13
.cfi_restore 12
.cfi_restore 11
.cfi_restore 10
.cfi_restore 9
.cfi_restore 8
.cfi_restore 7
.cfi_restore 6
.cfi_def_cfa_offset 160
br %r4
.L5:
.cfi_restore_state
brasl %r14,__syscall_do_cancel
.cfi_endproc
---
Checked on s390-linux-gnu and s390x-linux-gnu build with
run-tests-built=no.
[BZ #12683]
* sysdeps/unix/sysv/linux/s390/sigcontextinfo.h (ucontext_get_pc):
New function.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=4c686923b51f81cca01ad125f403b50fe05eeef4
commit 4c686923b51f81cca01ad125f403b50fe05eeef4
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Fri May 8 17:12:31 2015 -0300
nptl: arm: Fix Race conditions in pthread cancellation (BZ#12683)
This patch adds the ARM modifications required for the BZ#12683.
It basically adds the required ucontext_get_pc function and adjust
the generic syscall_cancel build.
For ARM we need to build syscall_cancel in ARM mode (-marm) to avoid
INTERNAL_SYSCALL to issue the syscall through the helper gate
__libc_do_syscall (which invalidates the mark checks on SIGCANCEL
handler).
Checked on arm-linux-gnueabihf.
[BZ #12683]
* sysdeps/unix/sysv/linux/arm/Makefile (CFLAGS-syscall_cancel.c): New
rule.
* sysdeps/unix/sysv/linux/arm/sigcontextinfo.h (ucontext_get_pc):
New function.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=1147b8b7f935fadfc4bc75f44bd50e5bebf4474e
commit 1147b8b7f935fadfc4bc75f44bd50e5bebf4474e
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Wed May 6 17:51:29 2015 -0300
nptl: aarch64: Fix Race conditions in pthread cancellation (BZ#12683)
This patch adds the aarch64 modifications required for the BZ#12683.
It basically adds the required ucontext_get_pc function.
The built cancelable syscall wrapper for aarch64 using GCC 7.2.1 and
default configuration flags shows an expected optimized version:
---
__GI___syscall_cancel_arch:
.LFB38:
.cfi_startproc
.global __syscall_cancel_arch_start
.type __syscall_cancel_arch_start,@function
__syscall_cancel_arch_start:
ldr w9, [x0]
tbnz x9, 2, .L7
mov x8, x1
mov x0, x2
mov x1, x3
mov x2, x4
mov x3, x5
mov x4, x6
mov x5, x7
svc 0 // syscall nr
.global __syscall_cancel_arch_end
.type __syscall_cancel_arch_end,@function
__syscall_cancel_arch_end:
ret
---
A similar code is obtained with GCC 5.3.1, so I see to need to provide
an arch-specific syscall_cancel.S for aarch64.
Checked on aarch64-linux-gnu.
[BZ #12683]
* sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h (PSEUDO): Redefine
to call __syscall_cancel function for cancellable syscalls.
(__pthread_get_ip): Add implementation.
* sysdeps/unix/sysv/linux/aarch64/sysdep.h (SYSCALL_CANCEL_ERROR): Add
definition.
(SYSCALL_CANCEL_ERRNO): Likewise.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c31e9f5f8549cfe2a3585d497d0764f2496c86a1
commit c31e9f5f8549cfe2a3585d497d0764f2496c86a1
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Fri Sep 18 18:14:19 2015 -0300
nptl: powerpc: Fix Race conditions in pthread cancellation (BZ#12683)
This patches adds the powerpc64 modification required for the BZ#12683.
It basically adds the required __pthread_get_pc function and a arch
specific syscall_cancel implementation.
The powerpc requires an arch-specific syscall_cancel because
INTERNAL_SYSCALL_NCS adds a mfcr just after the sc instruction to get
the CR0.SO bit information from kernel (which signals the error
return status). So for cancelled syscalls with side effects,
__pthread_get_pc will point to mcfr and thus invalidating the checks
on sigcancel_handler.
Checked on powerpc64le-linux-gnu and powerpc-linux-gnu.
[BZ #12683]
* sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S: New file.
* sysdeps/unix/sysv/linux/powerpc/sysdep-cancel.h
(__pthread_get_pc): New function.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=3bf87610132f283253be992d73762c2792752c14
commit 3bf87610132f283253be992d73762c2792752c14
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Mon May 4 16:30:13 2015 -0300
nptl: i386: Fix Race conditions in pthread cancellation (BZ#12683)
This patch adds the i386 modifications required for the BZ#12683.
It basically provides the required ucontext_get_pc symbol, add the
cancelable syscall wrapper and fix a thread atomic update macro.
On i386 an arch-specific cancellation implementation is required
because depending of the glibc configuration and underlying kernel
the syscall may be done using a vDSO symbol (__kernel_vsyscall).
By using the vDSO symbol the resulting PC value for an interrupted
syscall points to an adress outside the expected markers in
__syscall_cancel_arch. It has been discussed in LKML [1] on how
kernel could help userland to accomplish it, but afaik discussion
was stalled.
Also, since glibc supports i486, the old 'int 0x80' should be used
in the syscall wrapper. One option could make minimum default chip
to pentium II (which implements sysenter) or add a runtime check
on syscall_cancel.S to use 'int 0x80' or sysenter.
Similar to x86_64, it also remove bogus arch-specific
THREAD_ATOMIC_BIT_SET where it always reference to current thread
instead of the one referenced by input 'descr' argument.
Checked on i686-linux-gnu.
[BZ #12683]
* sysdeps/i386/nptl/tls.h (THREAD_ATOMIC_CMPXCHG_VAL,
THREAD_ATOMIC_BIT_SET): Remove macro.
* sysdeps/unix/sysv/linux/i386/Makefile
[$(subdir) = elf] (sysdep-rtld_routines): Add libc-do-syscall object.
* sysdeps/unix/sysv/linux/i386/lowlevellock.h (lll_wait_tid): Use
cancellable futex syscall macro.
* sysdeps/unix/sysv/linux/i386/syscall_cancel.S: New file.
* sysdeps/unix/sysv/linux/i386/sigcontextinfo.h (ucontext_get_pc):
New function.
[1] https://lkml.org/lkml/2016/3/8/1105
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c3619359a7a15ed73b7c5e7356173dcc2adf5d2c
commit c3619359a7a15ed73b7c5e7356173dcc2adf5d2c
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Sat May 9 14:20:26 2015 -0300
nptl: x32: Fix Race conditions in pthread cancellation (BZ#12683)
This patches adds the x32 modification required for the BZ#12683.
It basically adjust the syscall size used to pass the arguments to
the syscall cancel wrappers by zero extending pointers type while
preserting values for default types (such as off_t).
Checked on x86_64-linux-gnu-x32.
[BZ #12683]
* sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h (__syscall_arg_t):
Define type for x32.
(__SSC): Add platform specific macro.
* include/libc-pointer-arith.h (__integer_if_pointer_type_sub,
__integer_if_pointer_type, cast_to_integer): Parametrize integer type
cast.
(cast_to_uinteger): New macro.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=13c8c4809c7703c09d77a31601cba75cdc3de5d4
commit 13c8c4809c7703c09d77a31601cba75cdc3de5d4
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Mon Sep 29 09:48:34 2014 -0300
nptl: x86_64: Fix Race conditions in pthread cancellation (BZ#12683)
This patches adds the x86_64 modification required for the BZ#12683.
It basically provide the required ucontext_get_pc symbol and remove
the arch-specific libc-cancellation implementations.
It also remove bogus arch-specific THREAD_ATOMIC_BIT_SET where it
always reference to current thread instead of the one referenced by
input 'descr' argument. It works as long the input is the self thread
pointer, however it creates wrong code is it used along with a
description to a different one (as on nptl/pthread_cancel.c).
The code generated create an additional load to reference to TLS segment,
for instance the code:
THREAD_ATOMIC_BIT_SET (THREAD_SELF, cancelhandling, CANCELED_BIT);
Compiles to:
lock;orl $4, %fs:776
Where with patch changes it now compiles to:
mov %fs:16,%rax
lock;orl $4, 776(%rax)
If some usage indeed proves to be a hotspot we can add an extra macro
with a more descriptive name (THREAD_ATOMIC_BIT_SET_SELF for instance)
where x86_64 might optimize it. In fact all x86_64 THREAD_ATOMIC_* macros
do not respect the input descr and possible will fail when used with
a 'descr' difference than THREAD_SELF.
Checked on x86_64-linux-gnu.
[BZ #12683]
* sysdeps/unix/sysv/linux/x86_64/cancellation.S: Remove file.
* sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S: Remove file.
* sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S: Remove file.
* sysdeps/unix/sysv/linux/x86_64/lowlevellock.h (lll_wait_tid):
Use cancellable futex wait call.
* sysdeps/unix/sysv/linux/x86_64/sigcontextinfo.h (ucontext_get_pc):
New function.
* sysdeps/x86_64/nptl/tcb-offsets.sym (TCB_CANCELING_BITMASK):
Remove.
* sysdeps/x86_64/nptl/tls.h (THREAD_ATOMIC_CMPXCHG_VAL,
THREAD_ATOMIC_BIT_SET): Remove macros.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5c75e9c9cbecc95437a4bc5c9b030bd3af63116b
commit 5c75e9c9cbecc95437a4bc5c9b030bd3af63116b
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Fri Sep 18 18:26:35 2015 -0300
nptl: Fix Race conditions in pthread cancellation (BZ#12683)
This patches fixes some race conditions in NPTL cancellation code by
redefining how cancellable syscalls are defined and handled. Current
approach is to enable asynchronous cancellation prior to making the syscall
and restore the previous cancellation type once the syscall returns.
As decribed in BZ#12683, this approach shows 2 important problems:
1. Cancellation can act after the syscall has returned from kernel, but
before userspace saves the return value. It might result in a
resource
leak if the syscall allocated a resource or a side effect (partial
read/write), and there is no way to program handle it with
cancellation
handlers.
2. If a signal is handled while the thread is blocked at a cancellable
syscall, the entire signal handler runs with asynchronous cancellation
enabled. This can lead to issues if the signal handler call functions
which are async-signal-safe but not async-cancel-safe.
For cancellation to work correctly, there are 5 points at which the
cancellation signal could arrive:
1. Before the final "testcancel" and before the syscall is made.
2. Between the "testcancel" and the syscall.
3. While the syscall is blocked and no side effects have yet taken place.
4. While the syscall is blocked but with some side effects already having
taken place (e.g. a partial read or write).
5. After the syscall has returned.
And GLIBC wants to act on cancellation in cases 1, 2, and 3 but not in case
4 or 5. The proposed solution follows:
* Handling case 1 is trivial: do a conditional branch based on whether
the
thread has received a cancellation request;
* Case 2 can be caught by the signal handler determining that the saved
program counter (from the ucontext_t) is in some address range
beginning
just before the "testcancel" and ending with the syscall instruction.
* In this case, except for certain syscalls that ALWAYS fail with EINTR
even for non-interrupting signals, the kernel will reset the program
counter to point at the syscall instruction during signal handling, so
that the syscall is restarted when the signal handler returns. So, from
the signal handler's standpoint, this looks the same as case 2, and
thus
it's taken care of.
* In this case, the kernel cannot restart the syscall; when it's
interrupted by a signal, the kernel must cause the syscall to return
with whatever partial result it obtained (e.g. partial read or write).
* In this case, the saved program counter points just after the syscall
instruction, so the signal handler won't act on cancellation.
This one is equal to 4. since the program counter is past the syscall
instruction already.
Another case that needs handling is syscalls that fail with EINTR even
when the signal handler is non-interrupting. In this case, the syscall
wrapper code can just check the cancellation flag when the errno result
is EINTR, and act on cancellation if it's set.
The proposed GLIBC adjustments are:
1. Remove the enable_asynccancel/disable_asynccancel function usage in
syscall definition and instead make them call a common symbol that
will
check if cancellation is enabled (__syscall_cancel at
nptl/libc-cancellation.c), call the arch-specific cancellable
entry-point (__syscall_cancel_arch) and cancel the thread when
required.
2. Provide a arch-specific symbol that contains global markers. These
markers will be used in SIGCANCEL handler to check if the interruption
has been called in a valid syscall and if the syscalls has been
completed or not.
A default version is provided
(sysdeps/unix/sysv/linux/syscall_cancel.c),
however the markers may not be set on correct expected places depeding
of how INTERNAL_SYSCALL_NCS is implemented by the underlying
architecture.
In this case arch-specific implementation should be provided.
3. Rewrite SIGCANCEL asynchronous handler to check for both cancelling
type
and if current IP from signal handler falls between the global markes
and act accordingly (sigcancel_handler at nptl/nptl-init.c).
4. Adjust nptl/pthread_cancel.c to send an signal instead of acting
directly. This avoid synchronization issues when updating the
cancellation status and also focus the logic on signal handler and
cancellation syscall code.
5. Adjust pthread code to replace CANCEL_ASYNC/CANCEL_RESET calls to
appropriated cancelable futex syscalls.
6. Adjust libc code to replace LIBC_CANCEL_ASYNC/LIBC_CANCEL_RESET to
appropriated cancelable syscalls.
7. Adjust 'lowlevellock-futex.h' arch-specific implementations to provide
cancelable futex calls (used in libpthread code).
This patch adds the proposed changes to NPTL. The code leaves all the
ports
broken without further patches in the list.
[BZ #12683]
* nptl/Makefile [routines]: Add syscall_cancel object.
[libpthread-routines]: Remove cancellation object.
(CFLAGS-cancellation.c): Remove rule.
(CFLAGS-syscall_cancel.c): New rule.
(tests): Add tst-cancel28.
* nptl/Versions [GLIBC_PRIVATE] (libc): Add __syscall_cancel,
__syscall_cancel_arch_start, and __syscall_cancel_arch_end.
* nptl/cancellation.c: Remove file.
* nptl/descr.h (CANCELING_BIT): Remove define.
(CANCELING_BITMASK): Likewise.
(CANCEL_RESTMASK): Adjust value with CANCELED_BIT remove.
* nptl/libc-cancellation.c (__syscall_cancel): Add non-cancellable
implementation for loader and cancellable one for libc.
(__syscall_do_cancel): New function: cancel call for syscall wrappers.
* nptl/lll_timedlock_wait.c (__lll_timedlock_wait): Use cancellable
futex operation.
(__lll_timedwait_tid): Likewise.
* nptl/nptl-init.c (sigcancel_handler): Rewrite function to avoid race
conditions.
(__pthread_initialize_minimal_internal): Add SA_RESTART to SIGCANCEL
handler.
* nptl/pt-system.c [LIBC_CANCEL_HANDLED]: Remove definition.
* io/creat.c (LIBC_CANCEL_HANDLED): Likewise.
* io/ppoll.c [ppoll] (LIBC_CANCEL_HANDLED): Likewise.
* misc/pselect [__pselect] (LIBC_CANCEL_HANDLED): Likewise.
* sysdeps/posix/pause.c (LIBC_CANCEL_HANDLED): Likewise.
* sysdeps/unix/sysv/linux/generic/creat.c (LIBC_CANCEL_HANDLED):
Likewise.
* nptl/pthreadP.h (__do_cancel): Rewrite to both disable asynchronous
cancellation and setting the thread as cancelled.
(CANCEL_ASYNC): Remove definition.
(CANCEL_RESET): Likewise.
(LIBC_CANCEL_ASYNC): Likewise.
(LIBC_CANCEL_RESET): Likewise.
(LIBC_CANCEL_HANDLED): Likewise.
(__syscall_cancel_arch): Add prototype.
(__pthread_enable_asynccancel): Remove prototype.
(__pthread_disable_asynccancel): Likewise.
(__libc_enable_asynccancel): Likewise.
(__libc_disable_asynccancel): Likewise.
(__librt_enable_asynccancel): Likewise.
(__librt_disable_asynccancel): Likewise.
(__syscall_cancel_arch): Add prototype.
(__syscall_do_cancel): Likewise.
* nptl/pthread_cancel.c (pthread_cancel): Rewrite to just set
CANCELLED_BIT and call __pthread_kill.
* nptl/pthread_create.c (start_thread): Likewise.
* nptl/pthread_timedjoin.c (pthread_timedjoin_np): Likewise.
* nptl/sem_timedwait.c (sem_timedwait): Likewise.
* nptl/sem_wait.c (__new_sem_wait): Likewise.
* nptl/sem_waitcommon.c (futex_abstimed_wait): Likewise.
* sysdeps/nptl/aio_misc.h (AIO_MISC_WAIT): Likewise.
* sysdeps/nptl/gai_misc.h (GAI_MISC_WAIT): Likewise.
* sysdeps/posix/sigpause.c (do_sigpause): Likewise.
* sysdeps/posix/sigwait.c (__sigwait): Likewise.
* sysdeps/posix/waitid.c (__waitid): Likewise.
* sysdeps/nptl/lowlevellock.h (lll_wait_tid): Likewise.
* sysdeps/posix/open64.c (__libc_open64): Likewise.
* sysdeps/unix/sysv/linux/sigwait.c (__sigwait): Likewise.
* nptl/pthread_exit.c (pthread_exit): Rewrite to set EXITING_BIT
before call __pthread_unwind.
* nptl/pthread_join.c (pthread_join): Remove CANCEL_ASYNC/CANCEL_RESET
usage.
* rt/Makefile [CFLAGS-librt-cancellation.c]: Remove rule.
* sysdeps/generic/sysdep-cancel.h (LIBC_CANCEL_ASYNC): Remove define.
(LIBC_CANCEL_RESET): Likewise.
(LIBC_CANCEL_HANDLED): Likewise.
* sysdeps/unix/sysv/linux/clock_nanosleep.c (__clock_nanosleep):
Likewise.
* sysdeps/unix/sysv/linux/fcntl.c (__libc_fcntl): Likewise.
* sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c (__libc_fcntl):
Likewise.
* sysdeps/nptl/Makefile [$(subdir) = rt] (librt-sysdep_routines):
Remove librt-cancellation object.
[$(subdir) = rt] (librt-cancellation.c): Remove rule.
* sysdeps/nptl/librt-cancellation.c: Remove file.
* sysdeps/unix/sysv/linux/futex-internal.h (lll_futex_wait_cancel):
Use lll_futex_timed_wait_cancel.
(futex_reltimed_wait_cancelable): Likewise.
(futex_abstimed_wait_cancelable)): Use
lll_futex_timed_wait_bitset_cancel.
* sysdeps/unix/sysv/linux/lowlevellock-futex.h
(lll_futex_wait_cancel): New macro.
(lll_futex_timed_wait_cancel): Likewise.
(lll_futex_timed_wait_bitset_cancel): Likewise.
* sysdeps/unix/sysdep.h (SYSCALL_CANCEL): New macro: cancelable
syscall calls.
(INTERNAL_SYSCALL_NCS_CALL): New macro.
(__syscall_cancel): New prototype.
* sysdeps/unix/sysv/linux/socketcall.h (SOCKETCALL): Use __SSC macros.
(SOCKETCALL_CANCEL): Use SYSCALL_CANCEL macros.
* sysdeps/generic/sysdep-cancel.h (LIBC_CANCEL_ASYNC): Remove define.
(LIBC_CANCEL_RESET): Likewise.
(LIBC_CANCEL_HANDLED): Likewise.
* sysdeps/unix/sysv/linux/pthread_kill.c (__pthread_kill): Allow
SIGCANCEL to be sent.
* nptl/tst-cancel28.c: New file.
* sysdeps/unix/sysv/linux/syscall_cancel.c: Likewise.
* support/temp_file.c (create_temp_fifo): New function.
* support/temp_file.h (create_temp_fifo): Likewise.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=0796a7c793e817c84a4e06e405ed902c41d0a8de
commit 0796a7c793e817c84a4e06e405ed902c41d0a8de
Author: Adhemerval Zanella <adhemerval.zanella@linaro.com>
Date: Mon Sep 21 15:55:58 2015 -0700
nptl: Fix testcases for new pthread cancellation mechanism
With upcoming fix for BZ#12683, pthread cancellation does not act for:
1. If syscall is blocked but with some side effects already having
taken place (e.g. a partial read or write).
2. After the syscall has returned.
The main change is due the fact programs need to act in syscalls with
side-effects (for instance, to avoid leak of allocated resources or
handle partial read/write).
This patch changes the NPTL testcase that assumes the old behavior and
also remove the tst-cancel-wrappers.sh test (which checks for symbols
that will not exist anymore). For tst-cancel{2,3} case it remove the
pipe close because it might cause the write syscall to return with
side effects if the close is executed before the pthread cancel.
It also changes how to call the read syscall on tst-backtrace{5,6}
to use syscall instead of read cancelable syscall to avoid need to
handle the cancelable bridge function calls. It requires a change
on powerpc syscall implementation to create a stackframe, since
powerpc backtrace rely on such information.
Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
aarch64-linux-gnu, arm-linux-gnueabihf, powerpc64le-linux-gnu,
powerpc-linux-gnu, sparcv9-linux-gnu, and sparc64-linux-gnu.
* debug/tst-backtrace5.c (handle_signal): Check for syscall
instead of read.
(fn): Issue the read syscall instead of call the cancellable
syscall.
* nptl/Makefile [$(run-built-tests) = yes] (tests-special): Remove
tst-cancel-wrappers.sh.
* nptl/tst-cancel-wrappers.sh: Remove file.
* nptl/tst-cancel2.c (do_test): Do not close pipe.
* nptl/tst-cancel3.c (do_test): Likewise.
* nptl/tst-cancel4.c (tf_write): Handle cancelled syscall with
side-effects.
(tf_send): Likewise.
* sysdeps/unix/sysv/linux/powerpc/syscall.S (syscall): Create stack
frame.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=9a5fd16b1327cdcab9cd26687c7f70779c2d63dd
commit 9a5fd16b1327cdcab9cd26687c7f70779c2d63dd
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Mon Feb 26 17:52:02 2018 -0300
powerpc: Create stackframe information on syscall
This patch adds a minimal stackframe creation on powerpc syscall
implementation so backtrace works correctly on a signal handler.
Checked on powerpc64le-linux-gnu.
* sysdeps/unix/sysv/linux/powerpc/syscall.S (syscall): Create stack
frame.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=7a2c0ea11bac560392d4002626129523968f6c22
commit 7a2c0ea11bac560392d4002626129523968f6c22
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Thu Feb 22 15:47:33 2018 -0300
nptl: Fix tst-cancel4 sendto tests
Now that send might be implemented calling sendto syscall on Linux,
I am seeing some issue in some kernel configurations where tst-cancel4
sendto do not block as expected.
The socket used to force the syscall blocking is used with default
system configuration for buffer sending size, which might not be
correct to force blocking. This patch fixes it by explicit setting
buffer socket lower than the buffer size used. It also enabled sendto
cancellation tests to work in both ways (since internally send is
implemented routing to sendto on Linux kernel).
The patch also removes unrequired make rules on some archictures
for send/recv. The generic nptl Makefile already set the compiler flags
required on some architectures for correct unwinding and libc object
are not strictly required to support unwind (since pthread_cancel
requires linking against libpthread).
Checked on aarch64-linux-gnu and x86_64-linux-gnu. I also did a
sniff test with tst-cancel{4,5} on a simulated mips64-linux-gnu.
* nptl/tst-cancel4-common.h (set_socket_buffer): New function.
* nptl/tst-cancel4-common.c (do_test): Call set_socket_buffer
for socketpair endpoint.
* nptl/tst-cancel4.c (tf_send): Call set_socket_buffer and use
WRITE_BUFFER_SIZE as buffer size for sending socket.
(tf_sendto): Use SOCK_STREAM instead of SOCK_DGRAM and fix an
issue on system where send is implemented with sendto syscall.
* sysdeps/unix/sysv/linux/mips/mips64/Makefile [$(subdir) = socket]
(CFLAGS-recv.c, CFLAGS-send.c): Remove rules.
[$(subdir) = nptl] (CFLAGS-recv.c, CFLAGS-send.c): Likewise.
* sysdeps/unix/sysv/linux/riscv/rv64/Makefile: Remove file.
-----------------------------------------------------------------------
--
You are receiving this mail because:
You are on the CC list for the bug.