Bugs Rust Won't Catch

13 points by PuercoPop


PuercoPop

This is a follow up to An update on rust-coreutils (discussed on /s/9p8j3s). Feel free to merge the story.

It goes over some of the common mistakes found in uutils on how the team is fixing them.

ssokolow

In the specific case of --preserve-root, this works because / has no parent directory, so there’s nothing for an attacker to swap from underneath you. In the more general case of comparing two arbitrary paths for filesystem identity, however, you’d want to open both and compare their (dev, inode) pairs, the way GNU coreutils does. (Think identity, not string equality.)

I'm not sure I understand. How does fs::canonicalize fall short of (dev, inode) for path comparison? Is it subject to the same PATH_MAX limitation as realpath in glibc? Is preferring (dev, inode) done to avoid a potential symlink-based memory exhaustion attack loosely reminiscent of billion laughs leveraging how filesystems like ext4 have no limit on path length/depth? Is it something else I didn't think of? ...because I don't see how (dev, inode) comparison would prevent a TOCTTOU, given you can't ask the kernel to atomically resolve multiple paths to (dev, inode) pairs in the same instant, unless the intent was to imply but not explicitly state that one should open two FDs first, extract the (dev, inode)s from them for comparison, and then use whichever you want to operate on directly without reopening it.

Aside from not stopping to think about those potential flaws in fs::canonicalize and maybe "Resolve Inputs Before Crossing a Trust Boundary" and some nuances of "Match the Original Tool’s Behavior Exactly", all of these look like mistakes my history of burnout-inducing perfectionism would probably lead me to anticipate and avoid unless I was out-of-it enough that I'd have a lapse in judgment no matter what prior training I had.

linkdd

Who knew rewriting code with decades worth of bug fixes would reintroduces those bugs and even new ones.

I still don't get why there was a need to rewrite coreutils.

Rewriting anything in anything is a mistake every engineer must learn the hard way.