From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27443311C2A for ; Thu, 23 Jul 2026 23:17:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784848632; cv=none; b=I7f0nlzz7z6YnBzf76l7lcmvwGxSzStqb5Uq1Z7MaMSbyBSiHpjIFNKQXlAy19cIoNFLLC8rZ+NFI7JbMtTCdxyZxEUO0VtMnnnGEo0awnSVSFebnJQr5yoyM4Klxda1MCyuhs2LPHE03fDAFqJKloHOwRNTOYmU3/ewx7d7tMo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784848632; c=relaxed/simple; bh=UpPSfJJM275uN1fh8UmsiNbov3gPtRJJt+s0VuqHT0Q=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=mv2PoVa9tBo79FxtUqp9OSiYb/ZvdMu1RQyVrIb+iVpP2erDu3ZIUQHr01xKnwzROZeuD/cq8eP73Rb+c5inWWVPRu6IASPIidOk/+AV0you+21cj6JZyjgXvRomFHs+oGApyyaUBg+ut0lArRaaALwkQQ79AwtbCVIqAV5yAts= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=eMzuriJt; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="eMzuriJt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DE421F00A3A; Thu, 23 Jul 2026 23:17:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1784848630; bh=aZmmqQGdPRFDWUhdN7fLXnfrmAi9O7U5ezry0OTtfCE=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=eMzuriJttL8GdAMq71QZJIoJXHlmJf7LvgTV55fHqGXfzvm3vIF4vZEiMBqUVxsZb 7kULj4lDg0MaO95RytrArXdQhGuBsPe56LTCm8q7PDsEsUp7AiNWNkcHKKdkw2Vq0h yz9hX29/16STq6I0YFcrNqjZZHIA9hvpZKIFBarQ= Date: Thu, 23 Jul 2026 16:17:09 -0700 From: Andrew Morton To: Bradley Morgan Cc: oleg.deomi@gmail.com, bsingharora@gmail.com, linux-kernel@vger.kernel.org Subject: Re: [BUG] taskstats: REGISTER_CPUMASK silently truncates the last byte of the cpumask string Message-Id: <20260723161709.1312af98b9ad71762257a15a@linux-foundation.org> In-Reply-To: References: <5CBDF317-FB8B-4569-8B2F-96D350657054@grrlz.net> <20260723122825.4626f7e9efb30b22e2ac9d9b@linux-foundation.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 23 Jul 2026 22:11:43 +0100 Bradley Morgan wrote: >... > > Hi Andrew, let me be honest, I CBA to do a new thread, here's my suggestion Seems this fooled Sashiko, so no AI review for you! > From: Bradley Morgan > 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 doesnt 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. > > ... > > --- a/kernel/taskstats.c > +++ b/kernel/taskstats.c > @@ -371,10 +371,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; Nice, thanks, There's a nla_strdup(), who knew? (nla_strdup() could use kstrdup(), btw?)