Skip to content

linux: fix regression in libcrun_configure_network #1829

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

eriksjolund
Copy link
Contributor

@eriksjolund eriksjolund commented Jul 18, 2025

commit ab64a5c introduced the regression.

Closes: #1828

Summary by Sourcery

Fix regression in libcrun_configure_network by properly handling netlink NLMSG_ERROR messages using struct nlmsgerr and ignoring success acknowledgements.

Bug Fixes:

  • Use struct nlmsgerr to parse netlink error codes instead of manually reading bytes
  • Avoid treating successful NLM_F_ACK messages as errors

Copy link

sourcery-ai bot commented Jul 18, 2025

Reviewer's Guide

This patch corrects a regression in libcrun_configure_network by replacing manual parsing of netlink error messages with use of the standard nlmsgerr structure and properly distinguishing between error and acknowledgment responses.

Sequence diagram for revised netlink error handling in libcrun_configure_network

sequenceDiagram
    participant libcrun_configure_network
    participant kernel
    libcrun_configure_network->>kernel: send netlink request
    kernel-->>libcrun_configure_network: receive netlink response
    alt NLMSG_ERROR
        libcrun_configure_network->>libcrun_configure_network: parse nlmsgerr from response
        alt err_data->error < 0
            libcrun_configure_network->>libcrun_configure_network: call crun_make_error
        else err_data->error == 0
            libcrun_configure_network->>libcrun_configure_network: treat as success (ack)
        end
    end
Loading

Class diagram for updated error handling in libcrun_configure_network

classDiagram
    class libcrun_configure_network {
        +int libcrun_configure_network(libcrun_container_t *container, libcrun_error_t *err)
    }
    class nlmsghdr {
        +int nlmsg_type
    }
    class nlmsgerr {
        +int error
    }
    libcrun_configure_network --> nlmsghdr : uses
    libcrun_configure_network --> nlmsgerr : uses
Loading

File-Level Changes

Change Details Files
Refactor netlink error handling to use struct nlmsgerr
  • Replace manual buffer cast and errno assignment with NLMSG_DATA macro
  • Introduce err_data->error < 0 check to detect real errors
  • Omit error return when err_data->error == 0 (success ack)
  • Remove deprecated int32_t casting logic
src/libcrun/linux.c

Possibly linked issues

  • #26662: The PR fixes the exact regression in crun's network configuration, specifically an error handling bug with PF_NETLINK, that caused the issue.
  • #26662: The PR fixes a crun network config error, resolving the device access regression on WSL2.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @eriksjolund - I've reviewed your changes - here's some feedback:

  • Before casting NLMSG_DATA to struct nlmsgerr, verify that the netlink message payload length is at least sizeof(struct nlmsgerr) to avoid potential invalid memory access.
  • Make the zero-error acknowledgment path (err_data->error == 0) explicit—either return success immediately or clearly continue—so the intent is obvious and we don’t fall through accidentally.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Before casting NLMSG_DATA to struct nlmsgerr, verify that the netlink message payload length is at least sizeof(struct nlmsgerr) to avoid potential invalid memory access.
- Make the zero-error acknowledgment path (err_data->error == 0) explicit—either return success immediately or clearly continue—so the intent is obvious and we don’t fall through accidentally.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@eriksjolund
Copy link
Contributor Author

Please take an extra look when doing the review. I haven't used netlink before.

@eriksjolund eriksjolund force-pushed the fix-libcrun_configure_network branch from 6d5b033 to eabc488 Compare July 18, 2025 12:30
commit ab64a5c introduced the
regression.

Closes: containers#1828

Signed-off-by: Erik Sjölund <[email protected]>
@eriksjolund eriksjolund force-pushed the fix-libcrun_configure_network branch from eabc488 to d30d151 Compare July 18, 2025 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RestrictAddressFamilies=AF_UNIX AF_NETLINK causes crun to fail due to a regression
1 participant