[PATCH v4 00/21] nptl: Fix Race conditions in pthread cancellation [BZ#12683]

Adhemerval Zanella adhemerval.zanella@linaro.org
Fri Apr 3 20:31:40 GMT 2020


This is an updated version of my previous version [1] to fix BZ#12683
and it is based on cancel type and state refactor [2] [3] (still
pending review).

The changes from previous version are:

  - Use CANCELED_BITMASK on syscall_cancel.S instead of hardcoded
    value and remove the archors type.

  - Reorganized the __do_cancel macro and its usage on various
    pthread functions (and once pthread_exit is moved to libc.so it
    can be replaced by __pthread_exit call).

  - Reword x32 fix to use the its expected kernel ABI.

Below there are the system where I could fully tested with a
make check on real hardware:

	aarch64			no regresssions
	alpha			no regresssions
	arm			no regresssions
	csky			no coverage
	hppa			no regresssions
	i386			no regresssions
	ia64			1 regression *
	m68k			basic tests on simulator
	microblaze		no coverage
	mips64			no regresssions
	mips64n32		no regresssions
	mips			no regresssions
	nios2			no coverage
	powerpc			no regresssions
	powerpc64		no regresssions
	powerpc64le		no regresssions
	riscv64			no coverage
	s390x			no regresssions
	s390			no regresssions
	sh4			no regresssions
	sparc64			1 regression **
	sparcv9			no regresssions
	x86_64			no regresssions
	x86_64-32		no regresssions

*  On ia64 I am seeing nptl/tst-cancel21-static failure on libunwind stack
   unwind on third internal test (for SA_SIGINFO).  It only happens also for
   exception based unwind (-fexceptions), so I presume it might be related to
   the arch-specific syscall_cancel.S implementation.

** on sparc64 I am seeing intermitent nptl/tst-cond25 failures I can't
   pinpoint exactly what is triggering the SEGFAULT.  I am inclined to
   see it as a codegen issue, I will try with an updated compiler.

[1] https://sourceware.org/pipermail/libc-alpha/2019-October/107284.html
[2] https://sourceware.org/pipermail/libc-alpha/2020-April/112416.html
[3] https://sourceware.org/pipermail/libc-alpha/2020-April/112417.html

Adhemerval Zanella (21):
  nptl: Do not close the pipe on tst-cancel{2,3}
  nptl: Fix Race conditions in pthread cancellation [BZ#12683]
  nptl: x86_64: Fix Race conditions in pthread cancellation [BZ#12683]
  nptl: x32: Fix Race conditions in pthread cancellation [BZ#12683]
  nptl: i386: Fix Race conditions in pthread cancellation [BZ#12683]
  nptl: ia64: Fix Race conditions in pthread cancellation [BZ#12683]
  nptl: mips: Fix Race conditions in pthread cancellation [BZ#12683]
  nptl: aarch64: Fix Race conditions in pthread cancellation [BZ#12683]
  nptl: arm: Fix Race conditions in pthread cancellation [BZ#12683]
  nptl: powerpc: Fix Race conditions in pthread cancellation [BZ#12683]
  nptl: microblaze: Fix Race conditions in pthread cancellation
    [BZ#12683]
  nptl: sparc: Fix Race conditions in pthread cancellation [BZ#12683]
  nptl: hppa: Fix Race conditions in pthread cancellation [BZ#12683]
  nptl: m68k: Fix Race conditions in pthread cancellation [BZ#12683]
  nptl: alpha: Fix Race conditions in pthread cancellation [BZ#12683]
  nptl: sh: Fix Race conditions in pthread cancellation [BZ#12683]
  nptl: riscv: Fix Race conditions in pthread cancellation [BZ#12683]
  nptl: s390: Fix Race conditions in pthread cancellation [BZ#12683]
  nptl: nios2: Fix Race conditions in pthread cancellation [BZ#12683]
  nptl: csky: Fix Race conditions in pthread cancellation [BZ#12683]
  Linux: Remove sysdep-cancel header

 elf/dl-close.c                                |   1 -
 elf/dl-lookup.c                               |   1 -
 elf/dl-open.c                                 |   1 -
 elf/dl-runtime.c                              |   1 -
 elf/dl-scope.c                                |   1 -
 elf/dl-sym.c                                  |   1 -
 io/creat.c                                    |   1 -
 io/ppoll.c                                    |   2 -
 malloc/malloc.c                               |   3 -
 manual/llio.texi                              |   4 +-
 nptl/Makefile                                 |  10 +-
 nptl/Versions                                 |   4 +
 nptl/cancellation.c                           |  78 ----------
 nptl/descr.h                                  |   3 -
 nptl/libc-cancellation.c                      |  44 +++++-
 nptl/nptl-init.c                              |  92 ++++++------
 nptl/pthreadP.h                               |  58 ++++++--
 nptl/pthread_cancel.c                         |  66 ++-------
 nptl/pthread_create.c                         |   7 +-
 nptl/pthread_exit.c                           |   9 +-
 nptl/pthread_join_common.c                    |   7 +-
 nptl/pthread_kill.c                           |   7 +-
 .../pthread_kill_internal.c                   |  21 +--
 nptl/pthread_setcanceltype.c                  |   2 +-
 nptl/pthread_testcancel.c                     |  12 +-
 nptl/sem_wait.c                               |   2 +-
 nptl/tst-cancel2.c                            |   3 -
 nptl/tst-cancel29.c                           | 100 +++++++++++++
 nptl/tst-cancel3.c                            |   3 -
 posix/nanosleep.c                             |   1 -
 rt/Makefile                                   |   2 +-
 sysdeps/aarch64/nptl/tcb-offsets.sym          |   3 +
 sysdeps/alpha/nptl/tcb-offsets.sym            |   3 +
 sysdeps/arm/nptl/tcb-offsets.sym              |   3 +
 sysdeps/csky/nptl/tcb-offsets.sym             |   3 +
 .../syscall_types.h}                          |  13 +-
 sysdeps/generic/sysdep-cancel.h               |   7 -
 sysdeps/hppa/nptl/tcb-offsets.sym             |   3 +
 sysdeps/i386/nptl/tcb-offsets.sym             |   3 +
 sysdeps/ia64/nptl/tcb-offsets.sym             |   3 +
 sysdeps/m68k/nptl/tcb-offsets.sym             |   3 +
 sysdeps/microblaze/nptl/tcb-offsets.sym       |   3 +
 sysdeps/mips/dl-trampoline.c                  |   1 -
 sysdeps/mips/nptl/tcb-offsets.sym             |   3 +
 sysdeps/nios2/nptl/tcb-offsets.sym            |   3 +
 sysdeps/nptl/Makefile                         |   3 +-
 sysdeps/nptl/cancellation-pc-check.h          |  53 +++++++
 sysdeps/nptl/cancellation-sigmask.h           |  30 ++++
 sysdeps/nptl/futex-internal.h                 |  19 +--
 sysdeps/nptl/lowlevellock-futex.h             |  42 ++++--
 sysdeps/posix/open64.c                        |   1 -
 sysdeps/posix/pause.c                         |   1 -
 sysdeps/posix/sigpause.c                      |   1 -
 sysdeps/posix/sigwait.c                       |   1 -
 sysdeps/powerpc/nptl/tcb-offsets.sym          |   3 +
 sysdeps/powerpc/powerpc32/sysdep.h            |   3 +
 sysdeps/powerpc/powerpc64/sysdep.h            |  19 +++
 sysdeps/pthread/thrd_sleep.c                  |   1 -
 sysdeps/riscv/nptl/tcb-offsets.sym            |   3 +
 sysdeps/riscv/nptl/tls.h                      |   2 +
 sysdeps/s390/nptl/tcb-offsets.sym             |   3 +
 sysdeps/sh/nptl/tcb-offsets.sym               |   3 +
 sysdeps/sh/sysdep.h                           |   1 +
 sysdeps/sparc/nptl/tcb-offsets.sym            |   3 +
 sysdeps/unix/sysdep.h                         | 139 ++++++++++++++----
 .../unix/sysv/linux/aarch64/syscall_cancel.S  |  59 ++++++++
 sysdeps/unix/sysv/linux/accept.c              |   1 -
 sysdeps/unix/sysv/linux/accept4.c             |   1 -
 sysdeps/unix/sysv/linux/access.c              |   2 +-
 sysdeps/unix/sysv/linux/alpha/select.c        |   1 -
 .../unix/sysv/linux/alpha/syscall_cancel.S    |  81 ++++++++++
 sysdeps/unix/sysv/linux/arm/syscall_cancel.S  |  78 ++++++++++
 sysdeps/unix/sysv/linux/clock_nanosleep.c     |   1 -
 sysdeps/unix/sysv/linux/close.c               |   1 -
 sysdeps/unix/sysv/linux/close_nocancel.c      |   1 -
 sysdeps/unix/sysv/linux/connect.c             |   1 -
 sysdeps/unix/sysv/linux/copy_file_range.c     |   1 -
 sysdeps/unix/sysv/linux/creat.c               |   1 -
 sysdeps/unix/sysv/linux/creat64.c             |   1 -
 sysdeps/unix/sysv/linux/csky/syscall_cancel.S | 115 +++++++++++++++
 sysdeps/unix/sysv/linux/epoll_pwait.c         |   1 -
 sysdeps/unix/sysv/linux/epoll_wait.c          |   1 -
 sysdeps/unix/sysv/linux/fallocate.c           |   1 -
 sysdeps/unix/sysv/linux/fallocate64.c         |   1 -
 sysdeps/unix/sysv/linux/fcntl.c               |   1 -
 sysdeps/unix/sysv/linux/fcntl64.c             |   1 -
 sysdeps/unix/sysv/linux/fcntl_nocancel.c      |   1 -
 sysdeps/unix/sysv/linux/fdatasync.c           |   2 +-
 sysdeps/unix/sysv/linux/fsync.c               |   2 +-
 .../unix/sysv/linux/generic/inotify_init.c    |   5 +-
 sysdeps/unix/sysv/linux/getrandom.c           |   1 -
 sysdeps/unix/sysv/linux/hppa/syscall_cancel.S |  83 +++++++++++
 sysdeps/unix/sysv/linux/hppa/sysdep.h         |   1 +
 sysdeps/unix/sysv/linux/i386/Makefile         |   2 +-
 sysdeps/unix/sysv/linux/i386/syscall_cancel.S | 104 +++++++++++++
 .../sysv/linux/ia64/cancellation-pc-check.h   |  48 ++++++
 .../sysv/linux/ia64/cancellation-sigmask.h    |  33 +++++
 sysdeps/unix/sysv/linux/ia64/syscall_cancel.S |  81 ++++++++++
 sysdeps/unix/sysv/linux/m68k/syscall_cancel.S |  85 +++++++++++
 sysdeps/unix/sysv/linux/microblaze/pselect.c  |   1 -
 .../sysv/linux/microblaze/syscall_cancel.S    |  61 ++++++++
 sysdeps/unix/sysv/linux/microblaze/sysdep.h   |   1 +
 .../sysv/linux/mips/mips32/syscall_cancel.S   | 128 ++++++++++++++++
 sysdeps/unix/sysv/linux/mips/mips32/sysdep.h  |   4 +
 .../linux/mips/mips64/n32/syscall_types.h     |  28 ++++
 .../sysv/linux/mips/mips64/syscall_cancel.S   | 130 ++++++++++++++++
 sysdeps/unix/sysv/linux/mips/mips64/sysdep.h  |  52 +++----
 sysdeps/unix/sysv/linux/mq_timedreceive.c     |   2 +-
 sysdeps/unix/sysv/linux/mq_timedsend.c        |   2 +-
 sysdeps/unix/sysv/linux/msgrcv.c              |   2 +-
 sysdeps/unix/sysv/linux/msgsnd.c              |   2 +-
 sysdeps/unix/sysv/linux/msync.c               |   2 +-
 .../unix/sysv/linux/nios2/syscall_cancel.S    |  95 ++++++++++++
 sysdeps/unix/sysv/linux/open.c                |   3 +-
 sysdeps/unix/sysv/linux/open64.c              |   4 +-
 sysdeps/unix/sysv/linux/open_by_handle_at.c   |   2 +-
 sysdeps/unix/sysv/linux/open_nocancel.c       |   1 -
 sysdeps/unix/sysv/linux/openat.c              |   3 +-
 sysdeps/unix/sysv/linux/openat64.c            |   3 +-
 sysdeps/unix/sysv/linux/openat64_nocancel.c   |   1 -
 sysdeps/unix/sysv/linux/openat_nocancel.c     |   1 -
 sysdeps/unix/sysv/linux/pause.c               |   2 +-
 sysdeps/unix/sysv/linux/poll.c                |   1 -
 .../unix/sysv/linux/powerpc/syscall_cancel.S  |  65 ++++++++
 sysdeps/unix/sysv/linux/ppoll.c               |   3 -
 sysdeps/unix/sysv/linux/pread.c               |   2 +-
 sysdeps/unix/sysv/linux/pread64.c             |   2 +-
 sysdeps/unix/sysv/linux/pread64_nocancel.c    |   1 -
 sysdeps/unix/sysv/linux/preadv.c              |   2 +-
 sysdeps/unix/sysv/linux/preadv2.c             |   2 +-
 sysdeps/unix/sysv/linux/preadv64.c            |   2 +-
 sysdeps/unix/sysv/linux/preadv64v2.c          |   2 +-
 sysdeps/unix/sysv/linux/pselect.c             |   5 +-
 sysdeps/unix/sysv/linux/pwrite.c              |   2 +-
 sysdeps/unix/sysv/linux/pwrite64.c            |   2 +-
 sysdeps/unix/sysv/linux/pwritev.c             |   2 +-
 sysdeps/unix/sysv/linux/pwritev2.c            |   2 +-
 sysdeps/unix/sysv/linux/pwritev64.c           |   2 +-
 sysdeps/unix/sysv/linux/pwritev64v2.c         |   2 +-
 sysdeps/unix/sysv/linux/read.c                |   2 +-
 sysdeps/unix/sysv/linux/read_nocancel.c       |   1 -
 sysdeps/unix/sysv/linux/readv.c               |   2 +-
 sysdeps/unix/sysv/linux/recv.c                |   1 -
 sysdeps/unix/sysv/linux/recvfrom.c            |   1 -
 sysdeps/unix/sysv/linux/recvmmsg.c            |   1 -
 sysdeps/unix/sysv/linux/recvmsg.c             |   1 -
 .../unix/sysv/linux/riscv/syscall_cancel.S    |  67 +++++++++
 .../sysv/linux/s390/s390-32/syscall_cancel.S  |  63 ++++++++
 .../sysv/linux/s390/s390-64/syscall_cancel.S  |  62 ++++++++
 sysdeps/unix/sysv/linux/select.c              |   1 -
 sysdeps/unix/sysv/linux/send.c                |   1 -
 sysdeps/unix/sysv/linux/sendmmsg.c            |   1 -
 sysdeps/unix/sysv/linux/sendmsg.c             |   1 -
 sysdeps/unix/sysv/linux/sendto.c              |   1 -
 sysdeps/unix/sysv/linux/sh/syscall_cancel.S   | 126 ++++++++++++++++
 sysdeps/unix/sysv/linux/sigsuspend.c          |   2 +-
 sysdeps/unix/sysv/linux/sigtimedwait.c        |   1 -
 sysdeps/unix/sysv/linux/sigwait.c             |   1 -
 sysdeps/unix/sysv/linux/sigwaitinfo.c         |   1 -
 sysdeps/unix/sysv/linux/socketcall.h          |  42 ++++--
 .../sysv/linux/sparc/cancellation-sigmask.h   |  39 +++++
 .../sysv/linux/sparc/sparc32/syscall_cancel.S |  71 +++++++++
 sysdeps/unix/sysv/linux/sparc/sparc64/pause.c |  25 ++++
 .../sysv/linux/sparc/sparc64/syscall_cancel.S |  74 ++++++++++
 sysdeps/unix/sysv/linux/splice.c              |   2 +-
 sysdeps/unix/sysv/linux/sync_file_range.c     |   2 +-
 sysdeps/unix/sysv/linux/syscall_cancel.c      |  64 ++++++++
 sysdeps/unix/sysv/linux/sysdep-cancel.h       |  67 ---------
 sysdeps/unix/sysv/linux/sysdep.h              |   9 ++
 sysdeps/unix/sysv/linux/tcdrain.c             |   1 -
 sysdeps/unix/sysv/linux/tee.c                 |   2 +-
 sysdeps/unix/sysv/linux/timer_routines.c      |   1 -
 sysdeps/unix/sysv/linux/vmsplice.c            |   2 +-
 sysdeps/unix/sysv/linux/wait4.c               |   2 +-
 sysdeps/unix/sysv/linux/waitid.c              |   1 -
 sysdeps/unix/sysv/linux/write.c               |   2 +-
 sysdeps/unix/sysv/linux/write_nocancel.c      |   1 -
 sysdeps/unix/sysv/linux/writev.c              |   2 +-
 .../unix/sysv/linux/x86_64/syscall_cancel.S   |  59 ++++++++
 .../sysv/linux/x86_64/x32/syscall_types.h     |  40 +++++
 180 files changed, 2661 insertions(+), 544 deletions(-)
 delete mode 100644 nptl/cancellation.c
 rename sysdeps/unix/sysv/linux/pthread_kill.c => nptl/pthread_kill_internal.c (75%)
 create mode 100644 nptl/tst-cancel29.c
 rename sysdeps/{nptl/librt-cancellation.c => generic/syscall_types.h} (70%)
 delete mode 100644 sysdeps/generic/sysdep-cancel.h
 create mode 100644 sysdeps/nptl/cancellation-pc-check.h
 create mode 100644 sysdeps/nptl/cancellation-sigmask.h
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/syscall_cancel.S
 create mode 100644 sysdeps/unix/sysv/linux/alpha/syscall_cancel.S
 create mode 100644 sysdeps/unix/sysv/linux/arm/syscall_cancel.S
 create mode 100644 sysdeps/unix/sysv/linux/csky/syscall_cancel.S
 create mode 100644 sysdeps/unix/sysv/linux/hppa/syscall_cancel.S
 create mode 100644 sysdeps/unix/sysv/linux/i386/syscall_cancel.S
 create mode 100644 sysdeps/unix/sysv/linux/ia64/cancellation-pc-check.h
 create mode 100644 sysdeps/unix/sysv/linux/ia64/cancellation-sigmask.h
 create mode 100644 sysdeps/unix/sysv/linux/ia64/syscall_cancel.S
 create mode 100644 sysdeps/unix/sysv/linux/m68k/syscall_cancel.S
 create mode 100644 sysdeps/unix/sysv/linux/microblaze/syscall_cancel.S
 create mode 100644 sysdeps/unix/sysv/linux/mips/mips32/syscall_cancel.S
 create mode 100644 sysdeps/unix/sysv/linux/mips/mips64/n32/syscall_types.h
 create mode 100644 sysdeps/unix/sysv/linux/mips/mips64/syscall_cancel.S
 create mode 100644 sysdeps/unix/sysv/linux/nios2/syscall_cancel.S
 create mode 100644 sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/syscall_cancel.S
 create mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/syscall_cancel.S
 create mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/syscall_cancel.S
 create mode 100644 sysdeps/unix/sysv/linux/sh/syscall_cancel.S
 create mode 100644 sysdeps/unix/sysv/linux/sparc/cancellation-sigmask.h
 create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S
 create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/pause.c
 create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S
 create mode 100644 sysdeps/unix/sysv/linux/syscall_cancel.c
 delete mode 100644 sysdeps/unix/sysv/linux/sysdep-cancel.h
 create mode 100644 sysdeps/unix/sysv/linux/x86_64/syscall_cancel.S
 create mode 100644 sysdeps/unix/sysv/linux/x86_64/x32/syscall_types.h

-- 
2.17.1



More information about the Libc-alpha mailing list