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

UDP Client does not get the correct address using getsockname #262

Closed
sudharkrish opened this issue Sep 21, 2021 · 2 comments · Fixed by #579
Closed

UDP Client does not get the correct address using getsockname #262

sudharkrish opened this issue Sep 21, 2021 · 2 comments · Fixed by #579

Comments

@sudharkrish
Copy link

Description of the problem

UDP Client does not get the correct address using getsockname.
When UDP client connects to a server address, kernel assigns the IP-address:port-number for
the client's end-point. After call to connect system call, the client IP address:port-number can be retrieved using
getsockname system call.
I am using a golang program, that calls a Go library api-> net.DialUDP(which invokes system call connect).
Inside golang's net.DialUDP function, after call to connect system call, they call getsockname to retreive
the client end-points IP-address:port-number, and store it in their handle(as LocalAddress).
When go application code retrieves LocalAddress, it is NOT getting the correct address/port.

Steps to reproduce

Issue reproduced on -> commit fb71e4376a1fa797697832ca5cbd7731dc7f8793
in gramine-project.
If you run the attached go program, you can notice the LocalAddress
retreived by the UDP client is same as RemoteAddress(to which client is connecting to).
Details on how to reproduce are in additional info section below.

Expected results

LocalAddress of client is expected to be different from the server address it is connecting to.

Actual results

LocalAddress of client is same as server address it is connecting to.

From the logs:
Remote UDP address : 127.0.0.1:6000
Local UDP client address : 127.0.0.1:6000

Additional information -->

Attaching zip file, that has the sources to reproduce issue-> go_udp_client.zip

The Go source code is in a sub-folder inside the zip file-> gopro_udp_client/main.go

In graphene repo, under your /home->/graphene/Examples directory, copy this zip file-> , and then unzip it,
to create go_xx directory under /graphene/Examples/go_xx.

Under /graphene/Examples/go_xx$
Run the script -> ./launch_in_graphene_locally.sh
This will build the sample Go program(in a docker container), and then do a graphene-sgx build, and
then it will launch it locally on your host system.

Graphene debug logs, are in the zip file, titled as -> udp_graphene_connect_issue_debug_logs

@sudharkrish
Copy link
Author

Debugged this issue.
When graphene gets a call to getsockname, it does NOT make a system call, instead it returns previously saved value
of socket-address in LibOS socket handle(sock->addr.in.bind) in shim_do_getsockname.
But in this case, the value saved is incorrect(since it is the value of the server address client connected-to, and NOT the address assigned to client by kernel).

When application invokes golang library call-> net.DialUDP-> invokes socket syscall, and then connect system call-> shim_do_connect-> ocall_connect-> sgx_ocall_connect.

In sgx_ocall_connect, after Untrusted-PAL invokes connect syscall, it invokes getsockname to retrieve the caller's IP-address:port-num, ONLY IF bind-addr parameter is passed to ocall_connect, which is NOT the case in this use-case.

So bind-addr is NOT set to output from getsockname in sgx_ocall_connect, and gets set incorrectly to server's address(that client is connecting to).

@boryspoplawski
Copy link
Contributor

@sudharkrish could you verify that #579 fixes this issue?

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

Successfully merging a pull request may close this issue.

3 participants