From: Kees Cook <keescook@chromium.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Tobin C. Harding" <me@tobin.cc>,
Jonathan Corbet <corbet@lwn.net>,
Pantelis Antoniou <pantelis.antoniou@konsulko.com>,
"Steven Rostedt (VMware)" <rostedt@goodmis.org>,
kernel-hardening@lists.openwall.com,
linux-kernel@vger.kernel.org,
"Gustavo A. R. Silva" <gustavo@embeddedor.com>
Subject: [PATCH] vsprintf: Remove accidental VLA usage
Date: Wed, 7 Mar 2018 15:07:14 -0800 [thread overview]
Message-ID: <20180307230714.GA20797@beast> (raw)
The "sym" calculation is actually a fixed size, but since the max()
macro uses some extensive tricks for safety, it ends up looking like a
variable size. This replaces max() with a simple max macro which is
sufficient for the calculation of the array size.
Seen with -Wvla. Fixed as part of the directive to remove all VLAs from
the kernel: https://lkml.org/lkml/2018/3/7/621
Signed-off-by: Kees Cook <keescook@chromium.org>
---
lib/vsprintf.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index d7a708f82559..f420ab1477cb 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -744,8 +744,9 @@ char *resource_string(char *buf, char *end, struct resource *res,
#define FLAG_BUF_SIZE (2 * sizeof(res->flags))
#define DECODED_BUF_SIZE sizeof("[mem - 64bit pref window disabled]")
#define RAW_BUF_SIZE sizeof("[mem - flags 0x]")
- char sym[max(2*RSRC_BUF_SIZE + DECODED_BUF_SIZE,
- 2*RSRC_BUF_SIZE + FLAG_BUF_SIZE + RAW_BUF_SIZE)];
+#define SIMPLE_MAX(x, y) ((x) > (y) ? (x) : (y))
+ char sym[SIMPLE_MAX(2*RSRC_BUF_SIZE + DECODED_BUF_SIZE,
+ 2*RSRC_BUF_SIZE + FLAG_BUF_SIZE + RAW_BUF_SIZE)];
char *p = sym, *pend = sym + sizeof(sym);
int decode = (fmt[0] == 'R') ? 1 : 0;
--
2.7.4
--
Kees Cook
Pixel Security
next reply other threads:[~2018-03-07 23:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-07 23:07 Kees Cook [this message]
2018-03-07 23:40 ` [PATCH] vsprintf: Remove accidental VLA usage Andrew Morton
2018-03-07 23:56 ` Kees Cook
2018-03-07 23:42 ` Tycho Andersen
2018-03-07 23:59 ` Kees Cook
2018-03-08 0:03 ` Andrew Morton
2018-03-08 0:36 ` Kees Cook
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=20180307230714.GA20797@beast \
--to=keescook@chromium.org \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=gustavo@embeddedor.com \
--cc=kernel-hardening@lists.openwall.com \
--cc=linux-kernel@vger.kernel.org \
--cc=me@tobin.cc \
--cc=pantelis.antoniou@konsulko.com \
--cc=rostedt@goodmis.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.