Skip to content

patches: Bring back address structure length checks #56

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

Merged
merged 1 commit into from
May 31, 2024

Conversation

mogasergiu
Copy link
Member

Commit 560e66e ("patches: Add patches for Musl compatibility") added the src/api: Make sockets.c compatible with Musl patch to fix the incompatibility issued build errors when building with Musl. Precisely, Musl does not define the address length fields of socket address structures: sin_len/sa_len. These structures were added with 4.3BSD-Reno, however POSIX does not require this field and therefore it is not standardized.

Unfortunately, the aforementioned patch also removes some important address family length checks. For example, in the accept() syscall case, the address length passed as application provided argument is documented as meant to be overwritten by the kernel with the actual length of the filled-in address structure and not be relied upon by the kernel. A case where an application would pass a nonsense value for this argument can be seen in the case of perl 5.38, whose strace output contains the following:

accept4(3, {sa_family=AF_INET, sin_port=htons(45754), sin_addr=inet_addr("127.0.0.1")}, [4096 => 16], SOCK_CLOEXEC) = 4

where the size of the address structure is passed as 4096 and then overwritten to 16, the correct value.

In order to handle such cases properly, add back those checks.

Commit 560e66e ("patches: Add patches for Musl compatibility")
added the `src/api: Make sockets.c compatible with Musl` patch to
fix the incompatibility issued build errors when building with Musl.
Precisely, Musl does not define the address length fields of socket
address structures: `sin_len`/`sa_len`. These structures were added
with 4.3BSD-Reno, however POSIX does not require this field and
therefore it is not standardized.

Unfortunately, the aforementioned patch also removes some important
address family length checks. For example, in the `accept()` syscall
case, the address length passed as application provided argument is
documented as meant to be overwritten by the kernel with the actual
length of the filled-in address structure and not be relied upon by
the kernel. A case where an application would pass a nonsense value
for this argument can be seen in the case of `perl 5.38`, whose
`strace` output contains the following:
```
accept4(3, {sa_family=AF_INET, sin_port=htons(45754), sin_addr=inet_addr("127.0.0.1")}, [4096 => 16], SOCK_CLOEXEC) = 4
```
where the size of the address structure is passed as `4096` and then
overwritten to `16`, the correct value.

In order to handle such cases properly, add back those checks.

Signed-off-by: Sergiu Moga <[email protected]>
@razvand razvand self-assigned this May 31, 2024
@razvand razvand added the enhancement New feature or request label May 31, 2024
@razvand razvand added this to the v0.17.0 (Calypso) milestone May 31, 2024
@razvand razvand requested a review from csvancea May 31, 2024 10:28
Copy link
Member

@eduardvintila eduardvintila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thanks!

Reviewed-by: Eduard Vintilă [email protected]

Copy link

@mariapana mariapana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good!

Reviewed-by: Maria Pană [email protected]

Copy link
Contributor

@razvand razvand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved-by: Razvan Deaconescu [email protected]

@razvand razvand changed the base branch from staging to staging-56 May 31, 2024 18:05
@razvand razvand merged commit be68c06 into unikraft:staging-56 May 31, 2024
razvand pushed a commit that referenced this pull request May 31, 2024
Commit 560e66e ("patches: Add patches for Musl compatibility")
added the `src/api: Make sockets.c compatible with Musl` patch to
fix the incompatibility issued build errors when building with Musl.
Precisely, Musl does not define the address length fields of socket
address structures: `sin_len`/`sa_len`. These structures were added
with 4.3BSD-Reno, however POSIX does not require this field and
therefore it is not standardized.

Unfortunately, the aforementioned patch also removes some important
address family length checks. For example, in the `accept()` syscall
case, the address length passed as application provided argument is
documented as meant to be overwritten by the kernel with the actual
length of the filled-in address structure and not be relied upon by
the kernel. A case where an application would pass a nonsense value
for this argument can be seen in the case of `perl 5.38`, whose
`strace` output contains the following:
```
accept4(3, {sa_family=AF_INET, sin_port=htons(45754), sin_addr=inet_addr("127.0.0.1")}, [4096 => 16], SOCK_CLOEXEC) = 4
```
where the size of the address structure is passed as `4096` and then
overwritten to `16`, the correct value.

In order to handle such cases properly, add back those checks.

Signed-off-by: Sergiu Moga <[email protected]>
Reviewed-by: Eduard Vintilă <[email protected]>
Reviewed-by: Maria Pană <[email protected]>
Approved-by: Razvan Deaconescu <[email protected]>
GitHub-Closes: #56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done!
Development

Successfully merging this pull request may close these issues.

4 participants