[v3,00/21] nptl: Fix Race conditions in pthread cancellation (BZ#12683)

Message ID 20191014205656.29834-1-adhemerval.zanella@linaro.org
Headers show
Series
  • nptl: Fix Race conditions in pthread cancellation (BZ#12683)
Related show

Message

Adhemerval Zanella Oct. 14, 2019, 8:56 p.m.
This is an updated version of my previous version [1] to fix BZ#12683.
All the required internal changes not related to fix itself were
already pushed, so the patchset contains only the changes to fix
the issue itself.

The changes from previous version [1] are:

  - Add a syscall_cancel.S implementation for every port, as suggested
    by Zack Weinberg.  I agree with him that the reference C
    implementation is somewhat fragile to generate the correct markers,
    so I keep it only to use as reference for future ports to which
    semantic it should implement.

  - Fixed issues on ia64 regarding architecture instruction bundle
    and how kernel returned a syscall with side-effects.

  - Rework the SIGCANCEL handler so architectures that uses a different
    signature other than ucontext_t as third argument can override the
    required fields.

I also extended the architectures I 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/ml/libc-alpha/2018-02/msg00782.html

Adhemerval Zanella (21):
  nptl: Handle EPIPE on tst-cancel2
  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: ia64: Fix Race conditions in pthread cancellation (BZ#12683)
  nptl: mips: Fix Race conditions in pthread cancellation (BZ#12683)
  nptl: i386: 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)
  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 -
 include/libc-pointer-arith.h                  |  16 ++-
 io/creat.c                                    |   1 -
 io/ppoll.c                                    |   1 -
 malloc/malloc.c                               |   3 -
 manual/llio.texi                              |   4 +-
 misc/pselect.c                                |   1 -
 nptl/Makefile                                 |  12 +-
 nptl/Versions                                 |   3 +
 nptl/cancellation.c                           | 101 -------------
 nptl/descr.h                                  |  15 +-
 nptl/libc-cancellation.c                      |  46 +++++-
 nptl/nptl-init.c                              |  88 ++++++------
 nptl/pthreadP.h                               |  40 +++++-
 nptl/pthread_cancel.c                         |  69 ++-------
 nptl/pthread_create.c                         |   7 +-
 nptl/pthread_exit.c                           |   5 +-
 nptl/pthread_join_common.c                    |   2 +-
 nptl/pthread_kill.c                           |   7 +-
 .../pthread_kill_internal.c                   |  15 +-
 nptl/pthread_setcanceltype.c                  |   2 +-
 nptl/thrd_sleep.c                             |   8 +-
 nptl/tst-cancel2.c                            |   3 -
 nptl/tst-cancel28.c                           | 100 +++++++++++++
 rt/Makefile                                   |   2 +-
 sysdeps/generic/sysdep-cancel.h               |   7 -
 sysdeps/htl/pthreadP.h                        |   1 +
 sysdeps/mach/hurd/sysdep-cancel.h             |   8 --
 sysdeps/mips/dl-trampoline.c                  |   1 -
 sysdeps/mips/nptl/tls.h                       |   2 +-
 sysdeps/nptl/Makefile                         |   3 +-
 sysdeps/nptl/cancellation-pc-check.h          |  40 ++++++
 .../cancellation-sigmask.h}                   |  21 ++-
 sysdeps/posix/open64.c                        |   1 -
 sysdeps/posix/pause.c                         |   1 -
 sysdeps/posix/sigpause.c                      |   1 -
 sysdeps/posix/sigwait.c                       |   1 -
 sysdeps/posix/waitid.c                        |   1 -
 sysdeps/powerpc/powerpc32/sysdep.h            |   3 +
 sysdeps/powerpc/powerpc64/sysdep.h            |  19 +++
 sysdeps/sh/sysdep.h                           |   1 +
 sysdeps/unix/clock_nanosleep.c                |   1 -
 sysdeps/unix/sysdep.h                         | 136 ++++++++++++++----
 .../unix/sysv/linux/aarch64/syscall_cancel.S  |  61 ++++++++
 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    |  82 +++++++++++
 sysdeps/unix/sysv/linux/arm/syscall_cancel.S  |  80 +++++++++++
 sysdeps/unix/sysv/linux/clock_nanosleep.c     |   7 +-
 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 | 116 +++++++++++++++
 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 +-
 sysdeps/unix/sysv/linux/futex-internal.h      |  19 +--
 sysdeps/unix/sysv/linux/getrandom.c           |   1 -
 sysdeps/unix/sysv/linux/hppa/syscall_cancel.S |  82 +++++++++++
 sysdeps/unix/sysv/linux/i386/Makefile         |   2 +-
 sysdeps/unix/sysv/linux/i386/syscall_cancel.S | 105 ++++++++++++++
 .../sysv/linux/ia64/cancellation-pc-check.h   |  48 +++++++
 .../sysv/linux/ia64/cancellation-sigmask.h    |  33 +++++
 sysdeps/unix/sysv/linux/ia64/syscall_cancel.S |  83 +++++++++++
 sysdeps/unix/sysv/linux/lowlevellock-futex.h  |  46 ++++--
 sysdeps/unix/sysv/linux/m68k/syscall_cancel.S |  87 +++++++++++
 .../sysv/linux/microblaze/syscall_cancel.S    |  64 +++++++++
 .../sysv/linux/mips/mips32/syscall_cancel.S   | 128 +++++++++++++++++
 sysdeps/unix/sysv/linux/mips/mips32/sysdep.h  |   4 +
 .../sysv/linux/mips/mips64/syscall_cancel.S   | 114 +++++++++++++++
 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 +-
 sysdeps/unix/sysv/linux/nanosleep.c           |   3 +-
 sysdeps/unix/sysv/linux/nanosleep_nocancel.c  |   1 -
 .../unix/sysv/linux/nios2/syscall_cancel.S    |  97 +++++++++++++
 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/pause_nocancel.c      |   1 -
 sysdeps/unix/sysv/linux/poll.c                |   1 -
 .../unix/sysv/linux/powerpc/syscall_cancel.S  |  67 +++++++++
 sysdeps/unix/sysv/linux/ppoll.c               |   2 -
 sysdeps/unix/sysv/linux/pread.c               |   2 +-
 sysdeps/unix/sysv/linux/pread64.c             |   2 +-
 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             |   2 -
 ...pthread_kill.c => pthread_kill_internal.c} |  22 +--
 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    |  68 +++++++++
 .../sysv/linux/s390/s390-32/syscall_cancel.S  |  83 +++++++++++
 .../sysv/linux/s390/s390-64/syscall_cancel.S  |  83 +++++++++++
 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   | 128 +++++++++++++++++
 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 |  76 ++++++++++
 .../sysv/linux/sparc/sparc64/pause.c}         |  17 +--
 .../sysv/linux/sparc/sparc64/syscall_cancel.S |  77 ++++++++++
 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              |  20 +++
 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/wait.c                |   1 -
 sysdeps/unix/sysv/linux/waitid.c              |   1 -
 sysdeps/unix/sysv/linux/waitpid.c             |   1 -
 sysdeps/unix/sysv/linux/waitpid_nocancel.c    |   1 -
 sysdeps/unix/sysv/linux/write.c               |   2 +-
 sysdeps/unix/sysv/linux/write_nocancel.c      |   1 -
 sysdeps/unix/sysv/linux/writev.c              |   2 +-
 sysdeps/unix/sysv/linux/x86_64/cancellation.S | 104 --------------
 .../unix/sysv/linux/x86_64/syscall_cancel.S   |  61 ++++++++
 sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h   |  13 ++
 sysdeps/x86_64/nptl/tcb-offsets.sym           |   1 -
 166 files changed, 2560 insertions(+), 660 deletions(-)
 delete mode 100644 nptl/cancellation.c
 rename sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S => nptl/pthread_kill_internal.c (72%)
 create mode 100644 nptl/tst-cancel28.c
 delete mode 100644 sysdeps/generic/sysdep-cancel.h
 delete mode 100644 sysdeps/mach/hurd/sysdep-cancel.h
 create mode 100644 sysdeps/nptl/cancellation-pc-check.h
 rename sysdeps/{unix/sysv/linux/x86_64/librt-cancellation.S => nptl/cancellation-sigmask.h} (60%)
 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/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
 rename sysdeps/unix/sysv/linux/{pthread_kill.c => pthread_kill_internal.c} (75%)
 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
 rename sysdeps/{nptl/librt-cancellation.c => unix/sysv/linux/sparc/sparc64/pause.c} (63%)
 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
 delete mode 100644 sysdeps/unix/sysv/linux/x86_64/cancellation.S
 create mode 100644 sysdeps/unix/sysv/linux/x86_64/syscall_cancel.S

-- 
2.17.1