From 469f31c27876fcbc475fbdf27f94c7783a198ea6 Mon Sep 17 00:00:00 2001 From: Noah Date: Fri, 9 Oct 2026 11:21:17 -0600 Subject: [PATCH] buildroot: nftables cgroupv2 patch reads the handle with the raw syscall (uClibc has no wrapper) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Cxh2piVufTWbzKTmUafTkk --- ...pe-cgroupv2-use-the-64-bit-kernfs-id.patch | 52 ++++++++++++------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/luckfox-sdk-patches/buildroot/files/package/nftables/0001-datatype-cgroupv2-use-the-64-bit-kernfs-id.patch b/luckfox-sdk-patches/buildroot/files/package/nftables/0001-datatype-cgroupv2-use-the-64-bit-kernfs-id.patch index f3de1fc..3ea0401 100644 --- a/luckfox-sdk-patches/buildroot/files/package/nftables/0001-datatype-cgroupv2-use-the-64-bit-kernfs-id.patch +++ b/luckfox-sdk-patches/buildroot/files/package/nftables/0001-datatype-cgroupv2-use-the-64-bit-kernfs-id.patch @@ -5,24 +5,30 @@ Subject: [PATCH] datatype: take the cgroupv2 id from the directory's file handle nft built it from st_ino, which equals the id only on 64-bit kernels. On a 32-bit kernel (armv7) the id is (generation << 32) | ino and st_ino carries the low half, so every rule built from a path compared against the wrong value and -never matched: nothing was counted per service. name_to_handle_at() returns the -whole id on both. The listing path (id back to a name) uses the same helper. +never matched: nothing was counted per service. + +The directory's file handle holds the whole id on both. It is read with the raw +name_to_handle_at syscall because uClibc has no wrapper. The listing path (id +back to a name) uses the same helper. Found on the WardenOS panel kernel (6.18.46, armv7) with nftables 1.1.0. diff --git a/src/datatype.c b/src/datatype.c -index d398a9c..c6502ec 100644 +index d398a9c..289f930 100644 --- a/src/datatype.c +++ b/src/datatype.c -@@ -19,6 +19,7 @@ +@@ -19,7 +19,10 @@ #include #include #include +#include #include ++#include ++#include #include -@@ -1605,12 +1606,39 @@ const struct datatype policy_type = { + #include +@@ -1605,12 +1608,47 @@ const struct datatype policy_type = { #define SYSFS_CGROUPSV2_PATH "/sys/fs/cgroup" @@ -30,26 +36,34 @@ index d398a9c..c6502ec 100644 + * the cgroup directory. On 64-bit kernels that is st_ino, but on 32-bit kernels + * it is (generation << 32) | ino and st_ino carries only the low half, so a + * rule built from st_ino never matches. The file handle of the directory holds -+ * the full id on both. Fall back to st_ino where handles are not available. */ ++ * the full id on both. The handle is read with the raw syscall: uClibc has no ++ * name_to_handle_at() or struct file_handle. Fall back to st_ino where the ++ * syscall is missing. */ +static bool cgroupv2_path_id(const char *path, uint64_t *id) +{ ++#ifdef __NR_name_to_handle_at + struct { -+ struct file_handle fh; -+ unsigned char buf[sizeof(uint64_t)]; ++ unsigned int handle_bytes; ++ int handle_type; ++ unsigned char f_handle[sizeof(uint64_t)]; + } h; -+ struct stat st; + int mount_id; + -+ h.fh.handle_bytes = sizeof(h.buf); -+ if (name_to_handle_at(AT_FDCWD, path, &h.fh, &mount_id, 0) == 0 && -+ h.fh.handle_bytes == sizeof(*id)) { -+ memcpy(id, h.fh.f_handle, sizeof(*id)); ++ h.handle_bytes = sizeof(h.f_handle); ++ if (syscall(__NR_name_to_handle_at, AT_FDCWD, path, &h, &mount_id, 0) == 0 && ++ h.handle_bytes == sizeof(*id)) { ++ memcpy(id, h.f_handle, sizeof(*id)); ++ return true; ++ } ++#endif ++ { ++ struct stat st; ++ ++ if (stat(path, &st) < 0) ++ return false; ++ *id = st.st_ino; + return true; + } -+ if (stat(path, &st) < 0) -+ return false; -+ *id = st.st_ino; -+ return true; +} + static char *cgroupv2_get_path(const char *path, uint64_t id) @@ -62,7 +76,7 @@ index d398a9c..c6502ec 100644 DIR *d; d = opendir(path); -@@ -1626,7 +1654,7 @@ static char *cgroupv2_get_path(const char *path, uint64_t id) +@@ -1626,7 +1664,7 @@ static char *cgroupv2_get_path(const char *path, uint64_t id) path, dent->d_name); dent_name[sizeof(dent_name) - 1] = '\0'; @@ -71,7 +85,7 @@ index d398a9c..c6502ec 100644 cgroup_path = xstrdup(dent_name); break; } -@@ -1674,7 +1702,9 @@ static struct error_record *cgroupv2_type_parse(struct parse_ctx *ctx, +@@ -1674,7 +1712,9 @@ static struct error_record *cgroupv2_type_parse(struct parse_ctx *ctx, return error(&sym->location, "cgroupv2 path fails: %s", strerror(errno));