From: Greg Kroah-Hartman Date: Fri, 1 May 2026 12:06:56 +0000 (+0200) Subject: 6.1-stable patches X-Git-Tag: v6.12.86~49 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=359f3d83d7a37a853566898be7e9472093106f4c;p=thirdparty%2Fkernel%2Fstable-queue.git 6.1-stable patches added patches: tools-accounting-handle-truncated-taskstats-netlink-messages.patch --- diff --git a/queue-6.1/series b/queue-6.1/series index 03346b56e9..4fb35c594f 100644 --- a/queue-6.1/series +++ b/queue-6.1/series @@ -210,3 +210,4 @@ alsa-caiaq-fix-control_put-result-and-cache-rollback.patch alsa-caiaq-handle-probe-errors-properly.patch alsa-6fire-fix-input-volume-change-detection.patch iio-adc-ad7768-1-fix-one-shot-mode-data-acquisition.patch +tools-accounting-handle-truncated-taskstats-netlink-messages.patch diff --git a/queue-6.1/tools-accounting-handle-truncated-taskstats-netlink-messages.patch b/queue-6.1/tools-accounting-handle-truncated-taskstats-netlink-messages.patch new file mode 100644 index 0000000000..a5658a9e6d --- /dev/null +++ b/queue-6.1/tools-accounting-handle-truncated-taskstats-netlink-messages.patch @@ -0,0 +1,181 @@ +From cc82b3dcc6a8fa259fbda12ab00d6fc00908a49e Mon Sep 17 00:00:00 2001 +From: Yiyang Chen +Date: Mon, 30 Mar 2026 03:00:41 +0800 +Subject: tools/accounting: handle truncated taskstats netlink messages + +From: Yiyang Chen + +commit cc82b3dcc6a8fa259fbda12ab00d6fc00908a49e upstream. + +procacct and getdelays use a fixed receive buffer for taskstats generic +netlink messages. A multi-threaded process exit can emit a single +PID+TGID notification large enough to exceed that buffer on newer kernels. + +Switch to recvmsg() so MSG_TRUNC is detected explicitly, increase the +message buffer size, and report truncated datagrams clearly instead of +misparsing them as fatal netlink errors. + +Also print the taskstats version in debug output to make version +mismatches easier to diagnose while inspecting taskstats traffic. + +Link: https://lkml.kernel.org/r/520308bb4cbbaf8dc2c7296b5f60f11e12fb30a5.1774810498.git.cyyzero16@gmail.com +Signed-off-by: Yiyang Chen +Cc: Balbir Singh +Cc: Dr. Thomas Orgis +Cc: Fan Yu +Cc: Wang Yaxin +Cc: +Signed-off-by: Andrew Morton +Signed-off-by: Greg Kroah-Hartman +--- + tools/accounting/getdelays.c | 41 +++++++++++++++++++++++++++++++++++++---- + tools/accounting/procacct.c | 40 ++++++++++++++++++++++++++++++++++++---- + 2 files changed, 73 insertions(+), 8 deletions(-) + +--- a/tools/accounting/getdelays.c ++++ b/tools/accounting/getdelays.c +@@ -59,7 +59,7 @@ int print_task_context_switch_counts; + } + + /* Maximum size of response requested or message sent */ +-#define MAX_MSG_SIZE 1024 ++#define MAX_MSG_SIZE 2048 + /* Maximum number of cpus expected to be specified in a cpumask */ + #define MAX_CPUS 32 + +@@ -114,6 +114,32 @@ error: + return -1; + } + ++static int recv_taskstats_msg(int sd, struct msgtemplate *msg) ++{ ++ struct sockaddr_nl nladdr; ++ struct iovec iov = { ++ .iov_base = msg, ++ .iov_len = sizeof(*msg), ++ }; ++ struct msghdr hdr = { ++ .msg_name = &nladdr, ++ .msg_namelen = sizeof(nladdr), ++ .msg_iov = &iov, ++ .msg_iovlen = 1, ++ }; ++ int ret; ++ ++ ret = recvmsg(sd, &hdr, 0); ++ if (ret < 0) ++ return -1; ++ if (hdr.msg_flags & MSG_TRUNC) { ++ errno = EMSGSIZE; ++ return -1; ++ } ++ ++ return ret; ++} ++ + + static int send_cmd(int sd, __u16 nlmsg_type, __u32 nlmsg_pid, + __u8 genl_cmd, __u16 nla_type, +@@ -459,12 +485,16 @@ int main(int argc, char *argv[]) + } + + do { +- rep_len = recv(nl_sd, &msg, sizeof(msg), 0); ++ rep_len = recv_taskstats_msg(nl_sd, &msg); + PRINTF("received %d bytes\n", rep_len); + + if (rep_len < 0) { +- fprintf(stderr, "nonfatal reply error: errno %d\n", +- errno); ++ if (errno == EMSGSIZE) ++ fprintf(stderr, ++ "dropped truncated taskstats netlink message, please increase MAX_MSG_SIZE\n"); ++ else ++ fprintf(stderr, "nonfatal reply error: errno %d\n", ++ errno); + continue; + } + if (msg.n.nlmsg_type == NLMSG_ERROR || +@@ -506,6 +536,9 @@ int main(int argc, char *argv[]) + printf("TGID\t%d\n", rtid); + break; + case TASKSTATS_TYPE_STATS: ++ PRINTF("version %u\n", ++ ((struct taskstats *) ++ NLA_DATA(na))->version); + if (print_delays) + print_delayacct((struct taskstats *) NLA_DATA(na)); + if (print_io_accounting) +--- a/tools/accounting/procacct.c ++++ b/tools/accounting/procacct.c +@@ -71,7 +71,7 @@ int print_task_context_switch_counts; + } + + /* Maximum size of response requested or message sent */ +-#define MAX_MSG_SIZE 1024 ++#define MAX_MSG_SIZE 2048 + /* Maximum number of cpus expected to be specified in a cpumask */ + #define MAX_CPUS 32 + +@@ -121,6 +121,32 @@ error: + return -1; + } + ++static int recv_taskstats_msg(int sd, struct msgtemplate *msg) ++{ ++ struct sockaddr_nl nladdr; ++ struct iovec iov = { ++ .iov_base = msg, ++ .iov_len = sizeof(*msg), ++ }; ++ struct msghdr hdr = { ++ .msg_name = &nladdr, ++ .msg_namelen = sizeof(nladdr), ++ .msg_iov = &iov, ++ .msg_iovlen = 1, ++ }; ++ int ret; ++ ++ ret = recvmsg(sd, &hdr, 0); ++ if (ret < 0) ++ return -1; ++ if (hdr.msg_flags & MSG_TRUNC) { ++ errno = EMSGSIZE; ++ return -1; ++ } ++ ++ return ret; ++} ++ + + static int send_cmd(int sd, __u16 nlmsg_type, __u32 nlmsg_pid, + __u8 genl_cmd, __u16 nla_type, +@@ -239,6 +265,8 @@ void handle_aggr(int mother, struct nlat + PRINTF("TGID\t%d\n", rtid); + break; + case TASKSTATS_TYPE_STATS: ++ PRINTF("version %u\n", ++ ((struct taskstats *)NLA_DATA(na))->version); + if (mother == TASKSTATS_TYPE_AGGR_PID) + print_procacct((struct taskstats *) NLA_DATA(na)); + if (fd) { +@@ -353,12 +381,16 @@ int main(int argc, char *argv[]) + } + + do { +- rep_len = recv(nl_sd, &msg, sizeof(msg), 0); ++ rep_len = recv_taskstats_msg(nl_sd, &msg); + PRINTF("received %d bytes\n", rep_len); + + if (rep_len < 0) { +- fprintf(stderr, "nonfatal reply error: errno %d\n", +- errno); ++ if (errno == EMSGSIZE) ++ fprintf(stderr, ++ "dropped truncated taskstats netlink message, please increase MAX_MSG_SIZE\n"); ++ else ++ fprintf(stderr, "nonfatal reply error: errno %d\n", ++ errno); + continue; + } + if (msg.n.nlmsg_type == NLMSG_ERROR ||