datatype: accept a numeric cgroupsv2 id on input
PATCH v3 1/1 datatype: accept a numeric cgroupsv2 id on input
nft prints non-existent cgroup names as the raw id using PRIu64, but cgroupv2_type_parse() only stats /sys/fs/cgroup/<identifier>, so the listing does not load back:
# nft list set ip t s
table ip t {
set s {
type cgroupsv2
elements = { 50834 }
}
}
# nft delete element ip t s { 50834 }
Error: cgroupv2 path fails: No such file or directoryThe element cannot be deleted by key once its cgroup is gone, only flushed with the set, and a dump does not restore. The json dump has the same problem, and the stale id has been visible in the wild since 2022 (see Link). tests/shell/testcases/packetpath/cgroupv2 already works around this in cleanup().
Fall back to integer_type_parse() when the path does not resolve, as boolean_type_parse() already does. The path lookup stays first, so a cgroup named as a number still resolves as a path. Improving the integer parser is left for a follow-up as discussed in v1.
---
Changes since v2 (https://lore.kernel.org/netfilter-devel/[email protected]/):
- return the error from integer_type_parse() instead of discarding it (Pablo)
Changes since v1 (https://lore.kernel.org/netfilter-devel/[email protected]/):
- drop the strict decimal parser, delegate to integer_type_parse()
(Pablo, Phil)
- json test arm uses a here-string instead of a tempfile (Phil)
- shorter commit message and test
src/datatype.c | 4 +- .../shell/testcases/parsing/cgroupv2_stale_id | 128 ++++++++++++++++++ .../parsing/dumps/cgroupv2_stale_id.json-nft | 11 ++ .../parsing/dumps/cgroupv2_stale_id.nft | 0 4 files changed, 141 insertions(+), 2 deletions(-) create mode 100755 tests/shell/testcases/parsing/cgroupv2_stale_id create mode 100644 tests/shell/testcases/parsing/dumps/cgroupv2_stale_id.json-nft create mode 100644 tests/shell/testcases/parsing/dumps/cgroupv2_stale_id.nft
src/datatype.c +2 -2
@@ -1665,9 +1665,9 @@ static struct error_record *cgroupv2_type_parse(struct parse_ctx *ctx, SYSFS_CGROUPSV2_PATH, sym->identifier); cgroupv2_path[sizeof (cgroupv2_path) -1 ] ='\0' ; +/* the listing prints a raw id once the path is gone */ if (stat (cgroupv2_path, &st) <0 ) -return error (&sym->location,"cgroupv2 path fails: %s" , -strerror (errno)); +return integer_type_parse (ctx, sym, res); ino = st.st_ino; *res = constant_expr_alloc(&sym->location, &cgroupv2_type,
tests/shell/testcases/parsing/cgroupv2_stale_id new file +128 -0
128 lines not on this page · raw message
tests/shell/testcases/parsing/dumps/cgroupv2_stale_id.json-nft new file +11 -0
@@ -0,0 +1,11 @@ +{ + "nftables": [ + { + "metainfo": { + "version": "VERSION", + "release_name": "RELEASE_NAME", + "json_schema_version": 1 + } + } + ] +}
tests/shell/testcases/parsing/dumps/cgroupv2_stale_id.nft new file +0 -0
base-commit: 31fb7af1a99d67c87e94b4415e553589b21db2d1
Signature · 1 line
2.55.0
Pablo Neira Ayuso
maintainerQuoted 4 lines · Avinash Duduskar
nft prints non-existent cgroup names as the raw id using PRIu64, but
cgroupv2_type_parse()only stats /sys/fs/cgroup/<identifier>, so the listing does not load back:
Quoted 9 lines
# nft list set ip t s
table ip t {
set s {
type cgroupsv2
elements = { 50834 }
}
}
# nft delete element ip t s { 50834 }
Error: cgroupv2 path fails: No such file or directoryThanks, I have applied this v3.
I made a few minimal changes to the script, add a .nodump file instead of the empty stubs.