Skip to contentSkip to conversation

datatype: accept a numeric cgroupsv2 id on input

PATCH In review Avinash Duduskar 2 participants 2 messages Aug 1 – Aug 5 netfilter

lore
Share & tools
lore
#0 lore raw

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 directory

The 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
index 4dbca16e..5025b276 100644
@@ -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
new file mode 100644
index 00000000..546cc597
@@ -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
new file mode 100644
index 00000000..e69de29b

base-commit: 31fb7af1a99d67c87e94b4415e553589b21db2d1

Signature · 1 line
2.55.0
#1 lore raw
Quoted 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 directory

Thanks, I have applied this v3.

I made a few minimal changes to the script, add a .nodump file instead of the empty stubs.