linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: David Rientjes <rientjes@google.com>,
	Fengguang Wu <fengguang.wu@intel.com>,
	KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
	Rik van Riel <riel@redhat.com>,
	linux-mm@kvack.org
Subject: Re: [patch -mm] mm, mempolicy: silence gcc warning
Date: Wed, 20 Nov 2013 14:19:17 -0800	[thread overview]
Message-ID: <CAGXu5jLeRL7wgi+_TvCDQAOmKDBczpN=dZ=Mby-O46iRU9jCWA@mail.gmail.com> (raw)
In-Reply-To: <20131120141534.06ea091ca53b1dec60ace63d@linux-foundation.org>

On Wed, Nov 20, 2013 at 2:15 PM, Andrew Morton
<akpm@linux-foundation.org> wrote:
> On Tue, 12 Nov 2013 18:12:32 -0800 (PST) David Rientjes <rientjes@google.com> wrote:
>
>> Fengguang Wu reports that compiling mm/mempolicy.c results in a warning:
>>
>>       mm/mempolicy.c: In function 'mpol_to_str':
>>       mm/mempolicy.c:2878:2: error: format not a string literal and no format arguments
>>
>> Kees says this is because he is using -Wformat-security.
>>
>> Silence the warning.
>>
>> ...
>>
>> --- 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.

Yeah, I had offered to just whitelist this in my checker, since it's
the type of const char array that gcc doesn't realize is harmless as
an arg-less format string. Fengguang's reports are way faster than me,
though. :)

> mpol_to_str() would be simpler (and slower) if it was switched to use
> strncat().
>
> 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...

-Kees

-- 
Kees Cook
Chrome OS Security

--
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>

  reply	other threads:[~2013-11-20 22:19 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 [this message]
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       ` [patch -mm] mm, mempolicy: silence gcc warning KOSAKI Motohiro
2013-11-26  0:20         ` 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='CAGXu5jLeRL7wgi+_TvCDQAOmKDBczpN=dZ=Mby-O46iRU9jCWA@mail.gmail.com' \
    --to=keescook@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=fengguang.wu@intel.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --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