]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pidfd/cgroup-util: use fully-sized filehandle buffers
authorJeff Layton <jlayton@kernel.org>
Wed, 28 Jan 2026 13:25:10 +0000 (08:25 -0500)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 28 Jan 2026 15:57:03 +0000 (00:57 +0900)
The current code assumes that FILEID_KERNFS filehandles will never grow
in size. This is not a safe assumption and userland shouldn't be trying
to guess the size of the filehandle it'll get.

We have a macro for that: MAX_HANDLE_SZ.

src/basic/cgroup-util.c
src/basic/pidfd-util.c

index 2a7bfb3a019e912a3ed6a1a911d84d194c9e7e4b..6fb4d559589838e48cd0c47b53f1df0ee2c7f191 100644 (file)
@@ -38,7 +38,7 @@
 /* The structure to pass to name_to_handle_at() on cgroupfs2 */
 typedef union {
         struct file_handle file_handle;
-        uint8_t space[offsetof(struct file_handle, f_handle) + sizeof(uint64_t)];
+        uint8_t space[MAX_HANDLE_SZ];
 } cg_file_handle;
 
 #define CG_FILE_HANDLE_INIT                                     \
index d1ae1c5893d3319ddc60e75ff17374423caa4aae..8c4c8324529d1e22f718d26ccc35fba87dbadfbb 100644 (file)
@@ -239,7 +239,7 @@ int pidfd_get_inode_id_impl(int fd, uint64_t *ret) {
         if (file_handle_supported) {
                 union {
                         struct file_handle file_handle;
-                        uint8_t space[offsetof(struct file_handle, f_handle) + sizeof(uint64_t)];
+                        uint8_t space[MAX_HANDLE_SZ];
                 } fh = {
                         .file_handle.handle_bytes = sizeof(uint64_t),
                         .file_handle.handle_type = FILEID_KERNFS,