config: avoid NULL dereference on network-lock in RPC config parsing#3051
Merged
rst0git merged 1 commit intoJun 16, 2026
Merged
Conversation
eba835b to
489051d
Compare
adrianreber
approved these changes
Jun 16, 2026
adrianreber
left a comment
Member
There was a problem hiding this comment.
Thanks. Looks good. I restarted the failing CI runs. They do not seem related to this change.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## criu-dev #3051 +/- ##
=========================================
Coverage 57.05% 57.06%
=========================================
Files 154 154
Lines 40534 40535 +1
Branches 8881 8881
=========================================
+ Hits 23128 23130 +2
+ Misses 17052 17051 -1
Partials 354 354 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Commit 2e30db5 added --network-lock handling and a CLI restore warning that checks argv[optind] after option parsing. However, CRIU can also call parse_options() from the RPC config parsing path with argc == 0 and argv == NULL. This path was added by 99d52ec for req->config_file handling. If an RPC configuration file contains "network-lock iptables", has_network_lock_opt is set and the restore warning dereferences argv[optind], crashing criu swrk. Guard the restore warning with argv && optind < argc before accessing argv[optind]. Fixes: 2e30db5 ("criu: add --network-lock option to allow nftables alternative") Signed-off-by: Zhang Xuedong <2190206983@qq.com>
489051d to
8aa144e
Compare
Member
|
@sidneychang Thank you for fixing this! I've updated the order to start with most-selective predicate first ( |
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.
Description
CRIU can re-read a configuration file while running in RPC mode. In this
path,
cr-service.ccallsparse_options()without CLI arguments:This is used by flows such as
runc checkpoint, where runc can pass/etc/criu/runc.confto CRIU as the RPC config file.Commit
2e30db5c3d46added--network-lockhandling and a restorewarning that checks
argv[optind]after option parsing. If the RPCconfig file contains
network-lock iptables,parse_options()setshas_network_lock_optand then reaches that warning. In the RPC configparsing path, however,
argvisNULL, so dereferencingargv[optind]crashes
criu swrk.Guard the restore warning with
argv && optind < argcbefore readingargv[optind]. This keeps the existing CLI behavior unchanged, whileskipping a CLI-only check when no CLI subcommand exists.
Reproducer
From the CRIU source tree, generate the Python RPC bindings:
protoc --proto_path=test/others/rpc \ --python_out=/tmp \ test/others/rpc/rpc.protoCreate a minimal config file containing network-lock:
Create a minimal RPC reproducer:
Run it against an unpatched CRIU binary:
On an unpatched CRIU 4.2 binary, this crashes the service worker:
Run the same reproducer against the patched binary:
With this patch applied, the same RPC flow no longer crashes. For
example, I observed:
The RPC error above is expected for this minimal reproducer because it
does not provide a valid dump target PID. The purpose here is only to
verify that re-parsing a config_file containing network-lock no longer crashes
criu swrk.
Why this is safe
The guarded block only emits a warning for the CLI
restorecommandwhen
--network-lockis provided. In RPC config parsing there is no CLIsubcommand in
argv, so the check cannot make a valid restore/dumpdecision there.
With this patch:
criu restore --network-lock ...;argv == NULL;network-lockcan be parsed from an RPC config file without crashingthe service worker.
Tests
make -j$(nproc)make lintNo ZDTM test is added because this crash depends on the RPC config-file
parsing path. The code change is limited to guarding a CLI-only
argv[optind]access.Related
This is related to earlier RPC/config handling issues such as #1029.
Fixes: 2e30db5 ("criu: add --network-lock option to allow nftables alternative")