buildroot: nftables cgroupv2 patch reads the handle with the raw syscall (uClibc has no wrapper)
ci / test (push) Successful in 19s
ci / mcdc (push) Successful in 18s
ci / bench (push) Successful in 5s
ci / qemu-tools (push) Failing after 13s
ci / kernel-symbols (push) Successful in 1m24s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / patches-apply (push) Successful in 17s
ci / quality (push) Successful in 1m2s
ci / badges (push) Skipped
ci / test (push) Successful in 19s
ci / mcdc (push) Successful in 18s
ci / bench (push) Successful in 5s
ci / qemu-tools (push) Failing after 13s
ci / kernel-symbols (push) Successful in 1m24s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / patches-apply (push) Successful in 17s
ci / quality (push) Successful in 1m2s
ci / badges (push) Skipped
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cxh2piVufTWbzKTmUafTkk
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
aa6956f595
commit
469f31c278
+33
-19
@@ -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 <linux/netfilter.h>
|
||||
#include <linux/icmpv6.h>
|
||||
#include <dirent.h>
|
||||
+#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
+#include <sys/syscall.h>
|
||||
+#include <unistd.h>
|
||||
|
||||
#include <nftables.h>
|
||||
@@ -1605,12 +1606,39 @@ const struct datatype policy_type = {
|
||||
#include <datatype.h>
|
||||
@@ -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));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user