With -R -H or -L, chmod/chown/chgrp check --preserve-root on one lookup of the operand, then change it and descend through another. If the operand is replaced in between, for example by a symlink to /, the check sees the old directory and the recursion runs on /. Separately, chmod -R -P re-resolves the operand to change its mode, so a symlink put at that name in between is followed.
To reproduce, run chmod -R -H -v --preserve-root u+r d repeatedly while another process keeps swapping d with a symlink to / (renameat2 with RENAME_EXCHANGE). Some runs list files under /.
With
-R -Hor-L, chmod/chown/chgrp check--preserve-rooton one lookup of the operand, then change it and descend through another. If the operand is replaced in between, for example by a symlink to/, the check sees the old directory and the recursion runs on/. Separately,chmod -R -Pre-resolves the operand to change its mode, so a symlink put at that name in between is followed.To reproduce, run
chmod -R -H -v --preserve-root u+r drepeatedly while another process keeps swappingdwith a symlink to/(renameat2withRENAME_EXCHANGE). Some runs list files under/.