From: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
To: akpm@linux-foundation.org
Cc: kosaki.motohiro@jp.fujitsu.com, rientjes@google.com,
fengguang.wu@intel.com, keescook@chromium.org, riel@redhat.com,
linux-mm@kvack.org
Subject: Re: [patch -mm] mm, mempolicy: silence gcc warning
Date: Mon, 25 Nov 2013 19:08:15 -0500 [thread overview]
Message-ID: <5293E66F.8090000@jp.fujitsu.com> (raw)
In-Reply-To: <20131125123108.79c80eb59c2b1bc41c879d9e@linux-foundation.org>
(11/25/2013 3:31 PM), Andrew Morton wrote:
> On Sat, 23 Nov 2013 15:49:08 -0500 KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> wrote:
>
>>>> --- a/mm/mempolicy.c
>>>> +++ b/mm/mempolicy.c
>>>> @@ -2950,7 +2950,7 @@ void mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol)
>>>> return;
>>>> }
>>>>
>>>> - p += snprintf(p, maxlen, policy_modes[mode]);
>>>> + p += snprintf(p, maxlen, "%s", policy_modes[mode]);
>>>>
>>>> if (flags & MPOL_MODE_FLAGS) {
>>>> p += snprintf(p, buffer + maxlen - p, "=");
>>>
>>> mutter. There are no '%'s in policy_modes[]. Maybe we should only do
>>> this #ifdef CONFIG_KEES.
>>>
>>> mpol_to_str() would be simpler (and slower) if it was switched to use
>>> strncat().
>>
>> IMHO, you should queue this patch. mpol_to_str() is not fast path at all and
>> I don't want worry about false positive warning.
>
> Yup, it's in mainline.
Thanks.
>
>>> It worries me that the CONFIG_NUMA=n version of mpol_to_str() doesn't
>>> stick a '\0' into *buffer. Hopefully it never gets called...
>>
>> Don't worry. It never happens. Currently, all of caller depend on CONFIG_NUMA.
>> However it would be nice if CONFIG_NUMA=n version of mpol_to_str() is
>> implemented
>> more carefully. I don't know who's mistake.
>
> Put a BUG() in there?
I think this is enough. What do you think?
commit 5691f7f336c511d39fc05821d204a8f7ba18c0cf
Author: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Date: Mon Nov 25 18:38:25 2013 -0500
mempolicy: implement mpol_to_str() fallback implementation when !CONFIG_NUMA
Andrew Morton pointed out mpol_to_str() has no fallback implementation
for !CONFIG_NUMA and it could be dangerous because callers might assume
buffer is filled zero terminated string. Fortunately there is no such
caller. But it would be nice to provide default safe implementation.
Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
index 9fe426b..eee0597 100644
--- a/include/linux/mempolicy.h
+++ b/include/linux/mempolicy.h
@@ -309,6 +309,8 @@ static inline int mpol_parse_str(char *str, struct mempolicy **mpol)
static inline void mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol)
{
+ strncpy(buffer, "default", maxlen-1);
+ buffer[maxlen-1] = '\0';
}
static inline int mpol_misplaced(struct page *page, struct vm_area_struct *vma,
--
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/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2013-11-26 0:08 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-13 2:12 David Rientjes
2013-11-13 19:20 ` Kees Cook
2013-11-20 22:15 ` Andrew Morton
2013-11-20 22:19 ` Kees Cook
2013-11-23 20:49 ` KOSAKI Motohiro
2013-11-25 20:31 ` Andrew Morton
2013-11-25 23:30 ` David Rientjes
2013-11-25 23:33 ` [patch] mm, mempolicy: remove unneeded functions for UMA configs David Rientjes
2013-11-26 0:08 ` KOSAKI Motohiro [this message]
2013-11-26 0:20 ` [patch -mm] mm, mempolicy: silence gcc warning Andrew Morton
2013-11-26 18:40 ` KOSAKI Motohiro
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=5293E66F.8090000@jp.fujitsu.com \
--to=kosaki.motohiro@jp.fujitsu.com \
--cc=akpm@linux-foundation.org \
--cc=fengguang.wu@intel.com \
--cc=keescook@chromium.org \
--cc=linux-mm@kvack.org \
--cc=riel@redhat.com \
--cc=rientjes@google.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