FAILED: patch "[PATCH] taskstats: fix cpumask parsing cutting off the last character" failed to apply to 5.10-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x 1f58a5335cdd14b3fb5f2a5d3763dee1f5cba1d3
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090426-survival-bush-ee14@gregkh' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 1f58a5335cdd14b3fb5f2a5d3763dee1f5cba1d3 Mon Sep 17 00:00:00 2001
From: Bradley Morgan <[email protected]>
Date: Thu, 23 Jul 2026 21:09:22 +0000
Subject: [PATCH] taskstats: fix cpumask parsing cutting off the last character
parse() hands nla_strscpy() len as dstsize, and nla_strscpy() copies at most dstsize - 1 bytes. When the attr payload comes in without a trailing NUL, srclen == len >= dstsize and the last character of the cpumask string gets cut off. Register "0-15" and you are silently listening on "0-1", exit data for the rest never shows up.
The bug only bites when the sender doesn't NUL terminate the payload; senders that include the NUL were always fine (srclen gets decremented for the trailing NUL, so srclen < dstsize). Thats probably why this survived 20 years. And the policy is NLA_STRING, not NLA_NUL_STRING, so a payload without the trailing NUL is legit input here.
Skip the kmalloc/nla_strscpy dance entirely and use nla_strdup(), which already allocates srclen + 1 and terminates. The nla_len() bounds checks stay as they were.
kernel/taskstats.c +1 -2
@@ -368,10 +368,9 @@ static int parse(struct nlattr *na, struct cpumask *mask)return -E2BIG ;if (len <1 )return -EINVAL ; - data =kmalloc (len,GFP_KERNEL ); + data =nla_strdup (na,GFP_KERNEL );if (!data)return -ENOMEM ; -nla_strscpy (data, na, len); ret =cpulist_parse (data, mask);kfree (data);return ret;
Sasha Levin
maintainerPATCH 1/2 Fix unefficient call to memset before memcpu in nla_strlcpy.
From: Francis Laniel <[email protected]>
[ Upstream commit 8eeb99bc81bc1cb3d5e5323d9a82d8392e3a27b4 ]
Before this commit, nla_strlcpy first memseted dst to 0 then wrote src into it. This is inefficient because bytes whom number is less than src length are written twice.
This patch solves this issue by first writing src into dst then fill dst with 0's.
Note that, in the case where src length is higher than dst, only 0 is written. Otherwise there are as many 0's written to fill dst.
For example, if src is "foo\0" and dst is 5 bytes long, the result will be:
1. "fooGG" after memcpy (G means garbage).
2. "foo\0\0" after memset.
Stable-dep-of: 1f58a5335cdd ("taskstats: fix cpumask parsing cutting off the last character")
--- lib/nlattr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/nlattr.c +2 -1
@@ -756,8 +756,9 @@ size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dstsize)if (dstsize >0 ) {size_t len = (srclen >= dstsize) ? dstsize -1 : srclen; -memset (dst,0 , dstsize);memcpy (dst, src, len); +/* Zero pad end of dst. */ +memset (dst + len,0 , dstsize - len); }return srclen;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 taskstats: fix cpumask parsing cutting off the last character
From: Bradley Morgan <[email protected]>
[ Upstream commit 1f58a5335cdd14b3fb5f2a5d3763dee1f5cba1d3 ]
parse() hands nla_strscpy() len as dstsize, and nla_strscpy() copies at most dstsize - 1 bytes. When the attr payload comes in without a trailing NUL, srclen == len >= dstsize and the last character of the cpumask string gets cut off. Register "0-15" and you are silently listening on "0-1", exit data for the rest never shows up.
The bug only bites when the sender doesn't NUL terminate the payload; senders that include the NUL were always fine (srclen gets decremented for the trailing NUL, so srclen < dstsize). Thats probably why this survived 20 years. And the policy is NLA_STRING, not NLA_NUL_STRING, so a payload without the trailing NUL is legit input here.
Skip the kmalloc/nla_strscpy dance entirely and use nla_strdup(), which already allocates srclen + 1 and terminates. The nla_len() bounds checks stay as they were.
--- kernel/taskstats.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/taskstats.c +1 -2
@@ -346,10 +346,9 @@ static int parse(struct nlattr *na, struct cpumask *mask)return -E2BIG ;if (len <1 )return -EINVAL ; - data =kmalloc (len,GFP_KERNEL ); + data =nla_strdup (na,GFP_KERNEL );if (!data)return -ENOMEM ; -nla_strlcpy (data, na, len); ret =cpulist_parse (data, mask);kfree (data);return ret;
Signature · 1 line
2.53.0