fix(netlink): harden route segment parsing and accept short GET payloads#1781
Conversation
Prevent kernel panics on malformed netlink route messages by adding strict length validation before reading segment body CType bytes. Add compatibility handling for short RTM_GETLINK/RTM_GETADDR/RTM_GETROUTE payloads (rtgenmsg-sized) and keep parsing bounded by nlmsg_len. Add a c_unitest regression test that covers truncated and rtgen-sized netlink route requests. Signed-off-by: longjin <longjin@DragonOS.org>
|
@claude review |
|
Claude finished @fslongjin's task in 5m 48s —— View job Code Review for PR #1781: fix(netlink): harden route segment parsing and accept short GET payloadsI've completed my review of the changes to harden route segment parsing and add compatibility for short GET payloads. Overall, the changes look good and address the kernel panic issue. Here's my detailed feedback: Todo List:
Summary of Changes
Positive Aspects✅ Good defensive programming with comprehensive length checks Issues Found1. Potential Alignment Issues (Security Risk)File: let c_type = unsafe { *(c_type_bytes.as_ptr() as *const Self::CType) };The buffer Recommendation: Use let c_type = unsafe { core::ptr::read_unaligned(c_type_bytes.as_ptr() as *const Self::CType) };2. Redundant Length CheckFile: Recommendation: Simplify to 3. Missing Safety CommentsIssue: Recommendation: Add safety comments documenting alignment assumptions and buffer size guarantees. 4. Hardcoded Interface TypeFile: Recommendation: Consider using Suggestions for Improvement
Minor Nitpicks
ConclusionThe PR effectively addresses kernel panic vulnerabilities and improves robustness. With the alignment fixes and minor improvements suggested above, this will be a solid contribution. CI Status: Tests are currently running (3 passed, 3 in progress). Build check is in progress. |
Update netlink segment parsing to use `core::ptr::read_unaligned` for reading CType and header structures. This change ensures proper handling of potentially unaligned memory, improving robustness against malformed netlink messages. Signed-off-by: longjin <longjin@DragonOS.org>
Prevent kernel panics on malformed netlink route messages by adding strict length validation before reading segment body CType bytes. Add compatibility handling for short RTM_GETLINK/RTM_GETADDR/RTM_GETROUTE payloads (rtgenmsg-sized) and keep parsing bounded by nlmsg_len. Add a c_unitest regression test that covers truncated and rtgen-sized netlink route requests.
FIXED: #1780