]> git.ipfire.org Git - thirdparty/util-linux.git/commit
unshare: Fix PDEATHSIG race for --kill-child
authorEarl Chew <earl_chew@yahoo.com>
Sat, 1 Jan 2022 22:44:47 +0000 (14:44 -0800)
committerEarl Chew <earl_chew@yahoo.com>
Sun, 9 Jan 2022 22:07:00 +0000 (14:07 -0800)
commit764bb68af8e6d1b6c10a154c1dace64c450100c0
tree6e0cf824441a7a53cd1a0cc500fdcc92551cd076
parent312b64d9d1cedeac8d926cc503ffb4fbe023ade0
unshare: Fix PDEATHSIG race for --kill-child

Kill the child explicitly should the parent terminate
just before the child invokes prctl(PR_SET_PDEATHSIG).

The underlying issue can be reproduced as follows:

  #!/bin/bash

  rm -f /tmp/unshare.log.*
  strace -ff -tt -o /tmp/unshare.log /usr/bin/unshare --kill-child --fork true
  head -1 /tmp/unshare.log.*

  while : ; do
    PARENT=$(
      /usr/bin/unshare --kill-child --fork bash -c 'echo $PPID' &
      sleep 0 # sleep 0.00$RANDOM
      kill -9 $! 2>/dev/null
    )
    [ "$PARENT" != 1 ] || { echo "$PARENT" ; break ; }
  done

Signed-off-by: Earl Chew <earl_chew@yahoo.com>
sys-utils/unshare.c