Repository navigation
fix(bep): refuse a tpm authorization file that other users can read - #3510
Conversation
BEP-088 says the proxy reads a TPM key's authorization value from a file only its user can read. The store wrote the file at mode 0600 but loaded it at any mode and owner. At start, the store now opens the authorization file once and checks the open file: it must belong to this user and give no permission to group or others. Otherwise the start is refused, the key is kept, and the message names the file, its mode, and the chmod that fixes it, or says that the file belongs to another user. Tests: a 0600 or 0400 file loads; modes that let other users read or write the file are refused through find and through the start, and the files are left unchanged; the message for another owner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
Approved: no findings at Nothing to do. Clobber: none seen. |
norrietaylor
left a comment
There was a problem hiding this comment.
Approving. The check and the read share one open handle, find is the only place that reads an authorization file, and every existing writer (write_private, and the integration test that overwrites an existing 0600 file) keeps the mode the new check needs. Two small points inline.
| // only as root. | ||
| // SAFETY: `geteuid` takes no argument, reads process state and | ||
| // cannot fail. | ||
| if unsafe { libc::geteuid() } != 0 { |
There was a problem hiding this comment.
[low] The OtherOwner branch of read_auth only runs through find when the tests run as root, and CI does not run them as root, so the owner check itself is never exercised there. If the uid comparison were dropped, every test would still pass. One way to test it without root: split the check into a function that takes the metadata's uid and mode plus the expected uid, and pass it a uid that differs from geteuid().
There was a problem hiding this comment.
Agreed, the uid comparison could be dropped and every test would pass. The follow-up splits the check into a function over the uid, the mode and the expected uid, and tests it with a uid that differs from the caller, so it runs in CI without root.
| } | ||
| // Sized up front, so the value is not left behind in a smaller buffer | ||
| // that a growing read gives back unzeroed. | ||
| let mut auth = Zeroizing::new(Vec::with_capacity( |
There was a problem hiding this comment.
[nit] The capacity comes from the file's size, and nothing bounds it. An oversized or corrupt authorization file of a few GiB makes the start abort on allocation, with no message. Capping it, for example meta.len().min(4 * AUTH_LEN as u64), keeps the up-front sizing for the real 32-byte file.
There was a problem hiding this comment.
Agreed. The follow-up caps the capacity at 4 * AUTH_LEN, as you suggest; a larger file is still refused by the length check after the read.
What
The proxy reads the authorization value of a TPM-held key from a file. Spec 24 says that file is one "only its user can read" (BEP-088). Nothing checked that: a file with mode 0644 loaded like any other.
The proxy now opens the file once, checks on that open file that it belongs to the running user and has no group or other permission bits, and then reads from the same handle, so there is no gap between the check and the read. If the check fails the proxy does not start, keeps the key, and says what to run:
A file owned by another user gets its own message.
Is this safe for existing installs
The only writer of this file creates it at mode 0600 in a 0700 directory, and nothing in the repository creates it any other way. So no setup the product itself produces is refused. A file that was copied or restored with wider permissions will now stop the proxy with the message above.
For the spec owner
The spec names the property and does not say what to do when it does not hold. This follows the neighbouring rule for a file the user cannot read (refuse to start, keep the key). The message text is ours; change it freely. One open point: a file that was readable by others may already have been copied, and
chmoddoes not change the value. Whether the message should also point at replacing the key is a call the spec does not make.Testing
chmod 600the key loads.chownruns only as root.🤖 Generated with Claude Code
Summary by CodeRabbit