Add kernel_rex_version for kernel parsing#21008
Open
EclipseAditya wants to merge 8 commits into
Open
Conversation
4cbaa69 to
04db2e4
Compare
jvoisin
reviewed
Feb 24, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR centralizes Linux kernel release parsing into a new kernel_rex_version helper (returning Rex::Version or nil) and updates multiple local Linux modules to use it, preventing Rex::Version crashes on distro-specific uname -r suffixes while making “unknown kernel version” checks report CheckCode::Unknown instead of Safe.
Changes:
- Add
Msf::Post::Linux::Kernel#kernel_rex_versionplus RSpec coverage for common distrouname -rformats and failure cases. - Replace ad-hoc
kernel_release.split('-').firstparsing across affected modules withkernel_rex_version, returningCheckCode::Unknownwhen parsing fails. - Adjust a couple of kernel boundary conditions and modernize one execution call to
create_processfor argument-safe process launching.
Impact Analysis:
- Blast radius: Medium — all modules/mixins that include
Msf::Post::Linux::Kernelcan now consumekernel_rex_version, and updated exploit checks will change behavior on previously unparseable releases. - Data and contract effects: No schema/payload changes; behavior change is primarily
CheckCode::Safe→CheckCode::Unknownfor unparseable kernel releases, and standardized parsing to the upstream numeric portion. - Rollback and test focus: Rollback is straightforward (revert helper + module callsites); highest-value validation is running module
checkacross a spread of kernel release strings (Amazon/RHEL/Fedora/SUSE/Ubuntu) and running the new kernel spec.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| spec/lib/msf/core/post/linux/kernel_spec.rb | Adds unit tests for kernel_rex_version across distro release formats and nil/blank/unparseable inputs. |
| lib/msf/core/post/linux/kernel.rb | Introduces kernel_rex_version helper to normalize uname -r into Rex::Version safely. |
| modules/exploits/linux/local/vmwgfx_fd_priv_esc.rb | Switches version parsing to kernel_rex_version and refines vulnerable range checks. |
| modules/exploits/linux/local/sock_sendpage.rb | Uses kernel_rex_version and returns CheckCode::Unknown when parsing fails. |
| modules/exploits/linux/local/rds_rds_page_copy_user_priv_esc.rb | Uses kernel_rex_version with explicit Unknown on parse failure. |
| modules/exploits/linux/local/ptrace_traceme_pkexec_helper.rb | Uses kernel_rex_version with explicit Unknown on parse failure. |
| modules/exploits/linux/local/nested_namespace_idmap_limit_priv_esc.rb | Uses kernel_rex_version with explicit Unknown on parse failure. |
| modules/exploits/linux/local/glibc_realpath_priv_esc.rb | Uses kernel_rex_version with explicit Unknown on parse failure. |
| modules/exploits/linux/local/docker_cgroup_escape.rb | Uses kernel_rex_version for short version parsing; converts extended parse failure to Unknown. |
| modules/exploits/linux/local/cve_2023_0386_overlayfs_priv_esc.rb | Uses kernel_rex_version and returns Unknown when parsing fails. |
| modules/exploits/linux/local/cve_2022_1043_io_uring_priv_esc.rb | Uses kernel_rex_version with explicit Unknown on parse failure. |
| modules/exploits/linux/local/cve_2022_0847_dirtypipe.rb | Uses kernel_rex_version and returns Unknown when parsing fails. |
| modules/exploits/linux/local/cve_2021_3490_ebpf_alu32_bounds_check_lpe.rb | Uses kernel_rex_version, fixes Fedora comparison boundary, and switches to create_process for execution. |
| modules/exploits/linux/local/bpf_sign_extension_priv_esc.rb | Uses kernel_rex_version with explicit Unknown on parse failure. |
| modules/exploits/linux/local/bpf_priv_esc.rb | Uses kernel_rex_version with explicit Unknown on parse failure. |
| modules/exploits/linux/local/apport_abrt_chroot_priv_esc.rb | Uses kernel_rex_version and returns Unknown when parsing fails. |
| modules/exploits/example_linux_priv_esc.rb | Updates example module to use kernel_rex_version and Unknown on parse failure. |
4d9d161 to
43b6cc2
Compare
922c3cb to
c37b28f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
kernel_rex_versiontoMsf::Post::Linux::Kernelthat extracts the upstream kernel version fromuname -rand returns aRex::Version. This replaces thesplit('-').firstpattern duplicated across 15 modules that crashed withArgumentErroron distro-specific suffixes (Amazon Linux, Fedora, RHEL, SUSE, etc.).CheckCode::Unknowninstead ofCheckCode::Safewhen version can't be parsedrescue ArgumentErrorband-aids added in guard Rex::Version.new against crashes on local modules #19813vmwgfx_fd_priv_escboundary (>to>=) that excluded kernel 4.14.0cve_2021_3490Fedora dead code (>=to>for 5.11.20)Fixes #19855
Verification
bundle exec rspec spec/lib/msf/core/post/linux/kernel_spec.rbbundle exec ruby msftidy.rb vmwgfx_fd_priv_esc.rb docker_cgroup_escape.rb modules/exploits/example_linux_priv_esc.rbgrep -rn "Rex::Version.new.*kernel_release" modules/exploits/irbRex::Version.new("4.14.355-275.572.amzn2.x86_64")ArgumentError(the original bug)Rex::Version.new("4.14.355-275.572.amzn2.x86_64".split('-').first)Rex::Version "4.14.355"(whatkernel_rex_versiondoes)use exploit/linux/local/vmwgfx_fd_priv_esc