From: Ryota Ozaki <ozaki.ryota@gmail.com>
To: KOSAKI Motohiro <kosaki.motohiro@gmail.com>
Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman <gregkh@suse.de>,
linux-mm@kvack.org, stable@kernel.org
Subject: Re: [PATCH][RESEND] mm: Fix off-by-one bug in print_nodes_state
Date: Tue, 20 Dec 2011 13:22:27 +0900 [thread overview]
Message-ID: <CAKrYomjxhXwXdDJUP3ny3oa-wo81LJmsQmG8Emj986BHp+LbNQ@mail.gmail.com> (raw)
In-Reply-To: <4EEE5B08.8010703@gmail.com>
Hi Kosaki-san,
I'm sorry for my late reply.
2011/12/19 KOSAKI Motohiro <kosaki.motohiro@gmail.com>:
> (12/18/11 6:58 AM), Ryota Ozaki wrote:
>> /sys/devices/system/node/{online,possible} involve a garbage byte
>> because print_nodes_state returns content size + 1. To fix the bug,
>> the patch changes the use of cpuset_sprintf_cpulist to follow the
>> use at other places, which is clearer and safer.
>>
>> This bug was introduced since v2.6.24.
>>
>> Signed-off-by: Ryota Ozaki<ozaki.ryota@gmail.com>
>> ---
>> drivers/base/node.c | 8 +++-----
>> 1 files changed, 3 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/base/node.c b/drivers/base/node.c
>> index 5693ece..ef7c1f9 100644
>> --- a/drivers/base/node.c
>> +++ b/drivers/base/node.c
>> @@ -587,11 +587,9 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
>> {
>> int n;
>>
>> - n = nodelist_scnprintf(buf, PAGE_SIZE, node_states[state]);
>> - if (n> 0&& PAGE_SIZE> n + 1) {
>> - *(buf + n++) = '\n';
>> - *(buf + n++) = '\0';
>> - }
>> + n = nodelist_scnprintf(buf, PAGE_SIZE-2, node_states[state]);
>
> PAGE_SIZE-1. This seems another off by one. buf[n++] = '¥n' mean
> override old trailing '¥0' and buf[n] = '¥0' mean to append one byte.
> Then totally, we append one byte.
Thanks for pointing this out, you're right. (nodelist_)scnprintf returns
size-1 at most, thus we need to remain just one byte. I'll fix it in
the next patch.
Actually I bring the code from another and such the flaw can be found in other
functions. So I'll them as well.
ozaki-r
>
>> + buf[n++] = '\n';
>> + buf[n] = '\0';
>> return n;
>> }
>>
>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2011-12-20 4:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-18 11:58 Ryota Ozaki
2011-12-18 21:28 ` KOSAKI Motohiro
2011-12-20 4:22 ` Ryota Ozaki [this message]
2011-12-18 22:44 ` David Rientjes
2011-12-18 22:48 ` KOSAKI Motohiro
2011-12-19 20:53 ` David Rientjes
2011-12-19 21:15 ` KOSAKI Motohiro
2011-12-20 4:43 ` Ryota Ozaki
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=CAKrYomjxhXwXdDJUP3ny3oa-wo81LJmsQmG8Emj986BHp+LbNQ@mail.gmail.com \
--to=ozaki.ryota@gmail.com \
--cc=gregkh@suse.de \
--cc=kosaki.motohiro@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=stable@kernel.org \
/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