-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Ensure remote-address
is allowed when creating UDP stream
#7648
Ensure remote-address
is allowed when creating UDP stream
#7648
Conversation
I've addressed the PR feedback:
@alexcrichton I'm not sure what the testing story should look like here. I don't see where the wasi implementations are being tested against non-default |
I wrote up some thoughts here for how this might be tested (in case anyone lands on this PR in the future) |
0be2877
to
ce08758
Compare
crates/wasi/src/preview2/udp.rs
Outdated
/// The pool of allowed address | ||
pub(crate) pool: Arc<Pool>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this start as None
to represent that it's bound-late? That could also help overwriting it by accident by only writing to it if it's None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(same below too)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a change that does this, but I have a question about the exact desired semantics of start-bind
. Take the following_example:
// `bad_addr` is an address that is not permitted
assert!(sock.start_bind(bad_addr).is_err());
// `good_addr` is permitted
sock.start_bind(good_addr);
As currently written the second call to start-bind
will fail with InvalidState
since the pool has already been set on the socket. Is this right? Previously, this would have succeeded. I would imagine that start_bind
should be allowed to be called multiple times as long as the socket has not successfully been bound before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the check that the pool was not previously set as this broke some tests. Once we decide on what the semantics should be, I can adjust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @badeend on this you are probably best-equipped to answer this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the API's perspective, unbound sockets (Default
) never need a pool, and all other states (BindStarted
, Bound
, Connected
) could've only be reached by calling bind
at some point, so they always have access to a pool. A way to codify this could be:
pub(crate) enum UdpState {
Default,
BindStarted(Arc<Pool>),
Bound(Arc<Pool>),
Connected(Arc<Pool>),
}
Also, OutgoingDatagramStream's pool
field doesn't have to be optional, because you can never call stream
on an unbound socket.
As currently written the second call to start-bind will fail with InvalidState since the pool has already been set on the socket. Is this right?
From the caller's perspective, the start-bind
call should preferably succeed or fail atomically. Using the enum layout above would automagically fix that.
84c51e4
to
a9e2dd8
Compare
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
a9e2dd8
to
c33c918
Compare
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
c33c918
to
350c31c
Compare
I'm gonna go ahead and queue this for merge, and @rylev says they're happy to follow-up on semantic changes in a follow-up. |
Until now, the
remote-address
argument towasi:sockets/udp-socket#stream
was not checked against thePool
of allowed IP addresses. Now, we store thePool
fromnetwork
into thesocket
object inwasi:sockets/udp-socket#bind
and later use thatPool
inwasi:sockets/udp-socket#stream
to check thatremote-address
is allowed.The check itself is a bit hacky since
Pool
doesn't seem to expose a way to just check an address so we usePoolExt
to create aUdpConnecter
which we will fail if we don't have permission to connect to the remote address.I can add a test once I figure out the testing story in #7647