[PATCH 1/2] taskstats: return -EBADF when cgroupstats receives an invalid fd
From: Yiyang Chen
Date: Fri Jul 10 2026 - 16:08:57 EST
cgroupstats_user_cmd() returns 0 without sending a reply or a netlink
error when the fd passed via CGROUPSTATS_CMD_ATTR_FD does not resolve
to an open file in the caller's table. As a result:
- clients that did not set NLM_F_ACK block on recv() indefinitely
waiting for a CGROUPSTATS_CMD_NEW message that is never emitted;
- clients that set NLM_F_ACK receive a misleading "success" ACK
(errno == 0) with no statistics payload.
Return -EBADF instead so the netlink layer propagates the error to
userspace as expected.
Signed-off-by: Yiyang Chen <cyyzero16@xxxxxxxxx>
---
kernel/taskstats.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/taskstats.c b/kernel/taskstats.c
index 2cd0172d0516..8d115670a3ca 100644
--- a/kernel/taskstats.c
+++ b/kernel/taskstats.c
@@ -423,7 +423,7 @@ static int cgroupstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
fd = nla_get_u32(info->attrs[CGROUPSTATS_CMD_ATTR_FD]);
CLASS(fd, f)(fd);
if (fd_empty(f))
- return 0;
+ return -EBADF;
size = nla_total_size(sizeof(struct cgroupstats));
--
2.43.0