From: David Laight <David.Laight@ACULAB.COM>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-tip-commits@vger.kernel.org"
<linux-tip-commits@vger.kernel.org>
Cc: Miles Chen <miles.chen@mediatek.com>,
"linux-mediatek@lists.infradead.org"
<linux-mediatek@lists.infradead.org>,
"wsd_upstream@mediatek.com" <wsd_upstream@mediatek.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@kernel.org>, Borislav Petkov <bp@alien8.de>
Subject: RE: [tip: sched/core] sched/psi: Correct overly pessimistic size calculation
Date: Mon, 16 Sep 2019 11:49:22 +0000 [thread overview]
Message-ID: <ead094dabae64e6c978e94b617c8d08c@AcuMS.aculab.com> (raw)
In-Reply-To: <156841460535.24167.6273030361884540421.tip-bot2@tip-bot2>
From: Miles Chen
> Sent: 13 September 2019 23:43
> The following commit has been merged into the sched/core branch of tip:
>
> Commit-ID: 4adcdcea717cb2d8436bef00dd689aa5bc76f11b
> Gitweb: https://git.kernel.org/tip/4adcdcea717cb2d8436bef00dd689aa5bc76f11b
> Author: Miles Chen <miles.chen@mediatek.com>
> AuthorDate: Thu, 12 Sep 2019 18:34:52 +08:00
> Committer: Ingo Molnar <mingo@kernel.org>
> CommitterDate: Fri, 13 Sep 2019 07:49:28 +02:00
>
> sched/psi: Correct overly pessimistic size calculation
>
> When passing a equal or more then 32 bytes long string to psi_write(),
> psi_write() copies 31 bytes to its buf and overwrites buf[30]
> with '\0'. Which makes the input string 1 byte shorter than
> it should be.
>
> Fix it by copying sizeof(buf) bytes when nbytes >= sizeof(buf).
>
> This does not cause problems in normal use case like:
> "some 500000 10000000" or "full 500000 10000000" because they
> are less than 32 bytes in length.
>
> /* assuming nbytes == 35 */
> char buf[32];
>
> buf_size = min(nbytes, (sizeof(buf) - 1)); /* buf_size = 31 */
> if (copy_from_user(buf, user_buf, buf_size))
> return -EFAULT;
>
> buf[buf_size - 1] = '\0'; /* buf[30] = '\0' */
Wouldn't it be better to also allow the user to pass
an unterminated string?
So leave the '-1' on the assignment to buf_size, but remove
it from the last line.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
prev parent reply other threads:[~2019-09-16 11:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-12 10:34 [PATCH] psi: put NULL char correctly in psi_write() Miles Chen
2019-09-13 22:43 ` [tip: sched/core] sched/psi: Correct overly pessimistic size calculation tip-bot2 for Miles Chen
2019-09-16 11:49 ` David Laight [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ead094dabae64e6c978e94b617c8d08c@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=bp@alien8.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=miles.chen@mediatek.com \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=wsd_upstream@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).