Conversation
|
One of the issues with using third-party libraries for handling kernel data structures that we've continually run into in Shadow is that they're always designed for sending data to the kernel, whereas in Shadow we need to receive data from applications. Most rust libraries are not designed to handle edge cases like this. This is common in the networking syscalls (especially socket addresses). I think there are a few other syscalls too where we need to be able to handle fewer bytes than the size of the struct. In general, I think we try not to add "fake zero bytes" since they may have some unintended meaning. Instead it's usually better to only use the fields if they're given (if they're within the bounds given by shadow/src/main/host/syscall/handler/sched.rs Lines 164 to 167 in 79e9fd6 (We have a test using this with shadow/src/main/utility/macros.rs Lines 348 to 358 in 79e9fd6 But I don't think neli gives us this option. Enough bytes need to be given to fill the entire |
|
@sporksmith Do you agree with my comments here? We've discussed this topic (fewer bytes than the size of the struct) before I think, but I don't remember what your thoughts were. |
Yup, what you wrote makes sense to me |
stevenengler
left a comment
There was a problem hiding this comment.
Looks good, thanks for the tests! I have one last change request in the comments, then I think it's ready. Then you can rebase on main, squash, and I'll merge it.
|
@stevenengler Can you confirm that it's looking good? and then I will rebase and squash it. |
Yep looks good! Thanks for the changes. It's ready for rebase and squash. |
When you get the interfaces in Go using `net.Interfaces()`, it uses netlink sockets to do so. However, the messages sent by Go sometimes are too short and just ignore some fields. For example, the RTM_GETLINK message sent by Go looks like this: [17, 0, 0, 0, 18, 0, 1, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0] You can see that `nlmsghdr` took 16 bytes already and it left one byte at the end as a payload. In fact, the length should be at least 32 not 17 (16 bytes for `nlmsghdr` and 16 bytes for `ifinfomsg`). This PR pads the message with zeroes until it reaches the minimum length. I'm not sure how Linux handles it, but I think it's not worth spending time to investigate more.
When you get the interfaces in Go using
net.Interfaces(), it uses netlink sockets to do so.However, the messages sent by Go sometimes are too short and just ignore some fields.
For example, the RTM_GETLINK message sent by Go looks like this: [17, 0, 0, 0, 18, 0, 1, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0]
You can see that
nlmsghdrtook 16 bytes already and it left one byte at the end as a payload.In fact, the length should be at least 32 not 17 (16 bytes for
nlmsghdrand 16 bytes forifinfomsg).This PR pads the message with zeroes until it reaches the minimum length.
I'm not sure how Linux handles it, but I think it's not worth spending time to investigate more.
Before submitting your pull request, please see our documentation about contributing to Shadow:
https://shadow.github.io/docs/guide/contributing.html