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(aya): Fix panic when creating map on custom ubuntu kernel #909

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

belohnung
Copy link

Currently aya::maps::MapData::create panics at this line when it is called on a custom / faulty Ubuntu kernel (tested with Proxmox VE 8.1.4).

The file get_ubuntu_kernel_version accesses contains only a new line on Proxmox VE 8.1.4 thus get_ubuntu_kernel_version returns a ParseError.

This PR changes the behaviour so that it will try the other options if there is a parse error.

Copy link

netlify bot commented Mar 14, 2024

Deploy Preview for aya-rs-docs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit a9753f8
🔍 Latest deploy log https://app.netlify.com/sites/aya-rs-docs/deploys/662fe642316c67000871549b
😎 Deploy Preview https://deploy-preview-909--aya-rs-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mergify mergify bot added the aya This is about aya (userspace) label Mar 14, 2024
aya/src/util.rs Outdated
@@ -130,7 +130,7 @@ impl KernelVersion {
}

fn get_kernel_version() -> Result<Self, CurrentKernelVersionError> {
if let Some(v) = Self::get_ubuntu_kernel_version()? {
if let Some(v) = Self::get_ubuntu_kernel_version().ok().flatten() {
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if we should do the same (ok().flatten()) in line 142 for consistency as well? Debian kernel check probably works similarly.

Copy link
Author

Choose a reason for hiding this comment

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

I think the debian check is less fallible since it relies on the standard kernel version

Copy link
Member

Choose a reason for hiding this comment

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

This needs a test.

Copy link
Author

Choose a reason for hiding this comment

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

Feel free to give suggestions on how to implement such a test, and i'll be happy to add it to the PR

Copy link
Member

Choose a reason for hiding this comment

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

There are existing tests here

Copy link
Member

@vadorovsky vadorovsky Apr 3, 2024

Choose a reason for hiding this comment

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

Unit tests would be awesome, but I guess they would trigger a bigger refactoring of this function.

Instead of retrieving the version by calling Self::get_<distro>_kernel_version inside get_kernel_version, we would rather want to have a function which gets the kernel string as an argument and then parses and processes it. This way we could test it in a straightforward way (by passing a string to get_kernel_version() and asserting the output).

On the side note, I'm not a big fan of get_kernel_version() utility in general. After quick grepping, I don't see it being used internally in Aya at all. The whole version parsing per distro is becoming a mess. And using kernel versions for detecting features is not even reliable - mostly because of distros often backporting quite fresh stuff to completely ancient kernels. In the long term, I think we should probably deprecate get_kernel_version() and instead work on some more reliable feature detection, similar to bpftool feature, based on:

  • parsing kernel config
  • compilation and loading of tiny programs, which just indicate whether a program type X and helper function Y can be used on the currently running system

It would be great to start this effort as an additional crate (outside the monorepo). I have an use-case for this myself, so I'm happy to start it myself, but of course help is welcome.

Copy link
Author

Choose a reason for hiding this comment

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

Can i make the requested changes by @tamird so that we can have tests, and can we merge this for now? I really need this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, a larger refactoring can happen later

Copy link
Collaborator

Choose a reason for hiding this comment

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

@vadorovsky

After quick grepping, I don't see it being used internally in Aya at all.

We use KernelVersion::current() which calls it

Copy link
Member

Choose a reason for hiding this comment

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

Can i make the requested changes by @tamird so that we can have tests, and can we merge this for now? I really need this.

Sorry for late reply. Sure, go ahead just with changes requested by @tamird

@belohnung
Copy link
Author

oof, githubs sync fork button striked, i should stop doing prs on my main branches..., i'll try to fix

@belohnung belohnung requested a review from tamird April 29, 2024 18:27
Copy link
Member

@vadorovsky vadorovsky left a comment

Choose a reason for hiding this comment

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

Looks good. @tamird any objections against merging it?

@tamird
Copy link
Member

tamird commented May 10, 2024

I don't love that this has no test coverage and uses Result::ok. Papering over errors is not a good practice.

@belohnung
Copy link
Author

Test coverage of which function is missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aya This is about aya (userspace)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants