Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

pidfd: add a new supported_mask field

Some of the future fields in struct pidfd_info can be optional. If the
kernel has nothing to emit in that field, then it doesn't set the flag
in the reply. This presents a problem: There is currently no way to know
what mask flags the kernel supports since one can't always count on them
being in the reply.

Add a new PIDFD_INFO_SUPPORTED_MASK flag and field that the kernel can
set in the reply. Userspace can use this to determine if the fields it
requires from the kernel are supported. This also gives us a way to
deprecate fields in the future, if that should become necessary.

Link: https://patch.msgid.link/20251028-work-coredump-signal-v1-5-ca449b7b7aa0@kernel.org
Reviewed-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>

+19 -1
+16 -1
fs/pidfs.c
··· 293 293 return 0; 294 294 } 295 295 296 + /* This must be updated whenever a new flag is added */ 297 + #define PIDFD_INFO_SUPPORTED (PIDFD_INFO_PID | \ 298 + PIDFD_INFO_CREDS | \ 299 + PIDFD_INFO_CGROUPID | \ 300 + PIDFD_INFO_EXIT | \ 301 + PIDFD_INFO_COREDUMP | \ 302 + PIDFD_INFO_SUPPORTED_MASK) 303 + 296 304 static long pidfd_info(struct file *file, unsigned int cmd, unsigned long arg) 297 305 { 298 306 struct pidfd_info __user *uinfo = (struct pidfd_info __user *)arg; ··· 314 306 const struct cred *c; 315 307 __u64 mask; 316 308 317 - BUILD_BUG_ON(sizeof(struct pidfd_info) != PIDFD_INFO_SIZE_VER1); 309 + BUILD_BUG_ON(sizeof(struct pidfd_info) != PIDFD_INFO_SIZE_VER2); 318 310 319 311 if (!uinfo) 320 312 return -EINVAL; ··· 420 412 return -ESRCH; 421 413 422 414 copy_out: 415 + if (mask & PIDFD_INFO_SUPPORTED_MASK) { 416 + kinfo.mask |= PIDFD_INFO_SUPPORTED_MASK; 417 + kinfo.supported_mask = PIDFD_INFO_SUPPORTED; 418 + } 419 + 420 + /* Are there bits in the return mask not present in PIDFD_INFO_SUPPORTED? */ 421 + WARN_ON_ONCE(~PIDFD_INFO_SUPPORTED & kinfo.mask); 423 422 /* 424 423 * If userspace and the kernel have the same struct size it can just 425 424 * be copied. If userspace provides an older struct, only the bits that
+3
include/uapi/linux/pidfd.h
··· 26 26 #define PIDFD_INFO_CGROUPID (1UL << 2) /* Always returned if available, even if not requested */ 27 27 #define PIDFD_INFO_EXIT (1UL << 3) /* Only returned if requested. */ 28 28 #define PIDFD_INFO_COREDUMP (1UL << 4) /* Only returned if requested. */ 29 + #define PIDFD_INFO_SUPPORTED_MASK (1UL << 5) /* Want/got supported mask flags */ 29 30 30 31 #define PIDFD_INFO_SIZE_VER0 64 /* sizeof first published struct */ 31 32 #define PIDFD_INFO_SIZE_VER1 72 /* sizeof second published struct */ 33 + #define PIDFD_INFO_SIZE_VER2 80 /* sizeof third published struct */ 32 34 33 35 /* 34 36 * Values for @coredump_mask in pidfd_info. ··· 96 94 __s32 exit_code; 97 95 __u32 coredump_mask; 98 96 __u32 __spare1; 97 + __u64 supported_mask; /* Mask flags that this kernel supports */ 99 98 }; 100 99 101 100 #define PIDFS_IOCTL_MAGIC 0xFF