Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SockaddrLike::from_raw with unaligned inputs #1770

Merged
merged 2 commits into from
Jul 23, 2022

Conversation

asomers
Copy link
Member

@asomers asomers commented Jul 23, 2022

The major users of this function are functions like gethostname, which
will always properly align their buffers. But out-of-crate consumers
could manually construct an unaligned buffer. Handle that correctly.

Enable Clippy's cast_ptr_alignment lint. It's disabled by default as it
reports many false positives, but it would've caught this problem.

Reported-by: Miri
Fixes: 1769

@asomers asomers requested a review from rtzoeller July 23, 2022 19:41
asomers added 2 commits July 23, 2022 14:46
The major users of this function are functions like gethostname, which
will always properly align their buffers.  But out-of-crate consumers
could manually construct an unaligned buffer.  Handle that correctly.

Enable Clippy's cast_ptr_alignment lint.  It's disabled by default as it
reports many false positives, but it would've caught this problem.

Reported-by:	Miri
Fixes:		1769
Newer versions of cargo-hack require a newer toolchain to install
@asomers asomers force-pushed the sockaddr-from_raw-unaligned branch from 97b5d24 to ca2c920 Compare July 23, 2022 20:47
@asomers
Copy link
Member Author

asomers commented Jul 23, 2022

bors r=rtzoeller

@rtzoeller
Copy link
Collaborator

@asomers I think this is worth considering for a future 0.24.3 patch.

@asomers
Copy link
Member Author

asomers commented Jul 23, 2022

@asomers I think this is worth considering for a future 0.24.3 patch.

Can you think of any way that it might be exposed to a user? The main use for this method is in functions like getsockname, which already aligned the pointer correctly. And the test that revealed the problem was doing something that few ordinary users would.

@bors bors bot merged commit 7cc33c1 into nix-rust:master Jul 23, 2022
@asomers asomers deleted the sockaddr-from_raw-unaligned branch July 23, 2022 21:44
@rtzoeller
Copy link
Collaborator

rtzoeller commented Aug 4, 2022

Sorry, I could have been clearer. I don't think this justifies a patch, just that if we're already patching in the future for some reason, I'd consider pulling this in. Mostly just to keep miri happy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants