Repository navigation
Commit 99e6268
committed
cp: apply the finalize chmod without following a symlink
Both chmod sites in copy_file/copy_attributes decide whether to act by testing
dest for being a symlink, but the test happens long before the chmod: in
copy_file the lstat is taken before the copy starts, so the gap spans the whole
file copy. A symlink swapped into dest during that gap redirected the mode
change onto the link's target, off the destination tree.
Measured with a tight unlink/symlink loop against a 20MB copy, 40 rounds each,
an unrelated 0600 file taken to 0777:
before 12/40 and 13/40 rounds hit
after 0/40
GNU 9.10 2/40 and 3/40
Anchor the chmod to the parent directory fd with NoFollow, reusing
DirFd::chmod_at. EOPNOTSUPP/ELOOP mean dest is now a symlink, which is exactly
the "do nothing" case both guards already describe, so it maps to success.
Note GNU is affected by the same class at a lower rate, so this is hardening
beyond GNU rather than a compatibility fix. The remaining path-based steps in
copy_attributes (timestamps, xattr, ACL, SELinux) are unchanged.1 parent 0d02663 commit 99e6268
2 files changed
Lines changed: 79 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1881 | 1881 | | |
1882 | 1882 | | |
1883 | 1883 | | |
1884 | | - | |
| 1884 | + | |
1885 | 1885 | | |
1886 | 1886 | | |
1887 | 1887 | | |
| |||
2511 | 2511 | | |
2512 | 2512 | | |
2513 | 2513 | | |
| 2514 | + | |
| 2515 | + | |
| 2516 | + | |
| 2517 | + | |
| 2518 | + | |
| 2519 | + | |
| 2520 | + | |
| 2521 | + | |
| 2522 | + | |
| 2523 | + | |
| 2524 | + | |
| 2525 | + | |
| 2526 | + | |
| 2527 | + | |
| 2528 | + | |
| 2529 | + | |
| 2530 | + | |
| 2531 | + | |
| 2532 | + | |
| 2533 | + | |
| 2534 | + | |
| 2535 | + | |
| 2536 | + | |
| 2537 | + | |
| 2538 | + | |
| 2539 | + | |
| 2540 | + | |
| 2541 | + | |
| 2542 | + | |
| 2543 | + | |
| 2544 | + | |
| 2545 | + | |
| 2546 | + | |
| 2547 | + | |
| 2548 | + | |
| 2549 | + | |
2514 | 2550 | | |
2515 | 2551 | | |
2516 | 2552 | | |
| |||
2703 | 2739 | | |
2704 | 2740 | | |
2705 | 2741 | | |
2706 | | - | |
| 2742 | + | |
2707 | 2743 | | |
2708 | 2744 | | |
2709 | 2745 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6695 | 6695 | | |
6696 | 6696 | | |
6697 | 6697 | | |
| 6698 | + | |
| 6699 | + | |
| 6700 | + | |
| 6701 | + | |
| 6702 | + | |
| 6703 | + | |
| 6704 | + | |
| 6705 | + | |
| 6706 | + | |
| 6707 | + | |
| 6708 | + | |
| 6709 | + | |
| 6710 | + | |
| 6711 | + | |
| 6712 | + | |
| 6713 | + | |
| 6714 | + | |
| 6715 | + | |
| 6716 | + | |
| 6717 | + | |
| 6718 | + | |
| 6719 | + | |
| 6720 | + | |
| 6721 | + | |
| 6722 | + | |
| 6723 | + | |
| 6724 | + | |
| 6725 | + | |
| 6726 | + | |
| 6727 | + | |
| 6728 | + | |
| 6729 | + | |
| 6730 | + | |
| 6731 | + | |
| 6732 | + | |
| 6733 | + | |
| 6734 | + | |
| 6735 | + | |
| 6736 | + | |
| 6737 | + | |
| 6738 | + | |
6698 | 6739 | | |
6699 | 6740 | | |
6700 | 6741 | | |
| |||
0 commit comments