FWIW, bug #1480411, "rm -r * fails to delete directories when using overlayfs in a user-namespace", might be a duplicate of this bug. In both bugs the script works on the host but fails in a user-namespace with error EPERM. In this bug the operation which triggers the error is 'mkdir', while in bug #1480411 it is 'rmdir'.
FWIW, bug #1480411, "rm -r * fails to delete directories when using overlayfs in a user-namespace", might be a duplicate of this bug. In both bugs the script works on the host but fails in a user-namespace with error EPERM. In this bug the operation which triggers the error is 'mkdir', while in bug #1480411 it is 'rmdir'.
The equivalent script for bug #1480411 is,
#====== ======= ======= ======= =====
#!/bin/sh -ex
dir=`mktemp -d`
cleanup() {
umount -l $dir/t
rm -rf $dir
}
trap cleanup EXIT
echo "dir is $dir" $dir/l, upperdir= $dir/u, workdir= $dir/w o $dir/t ======= ======= ======= ======= =
mkdir -p $dir/l $dir/u $dir/w $dir/t
mkdir $dir/l/dev
touch $dir/l/dev/foo.txt
mount -t overlay -o lowerdir=
stat $dir/t/dev
rm $dir/t/dev/foo.txt
rmdir $dir/t/dev
echo $?
echo "rmdir should have succeeded"
#======