From patchwork Wed Mar 7 23:07:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10265545 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8ACBB60211 for ; Wed, 7 Mar 2018 23:07:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79B5F28CCD for ; Wed, 7 Mar 2018 23:07:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6DCF128C08; Wed, 7 Mar 2018 23:07:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 7688B28C08 for ; Wed, 7 Mar 2018 23:07:34 +0000 (UTC) Received: (qmail 29905 invoked by uid 550); 7 Mar 2018 23:07:29 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 29861 invoked from network); 7 Mar 2018 23:07:29 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=PcGgUXhytehr9tmh1Agcgit62y1yoNvFyzEBCx+RPfs=; b=jvzr0ykfgkBrXChwRacv2C7fGmB45OpXDTNQfKOnd6bLNkhcXTmYFbqEsj5owAd45K d/y7+BgQMokZ89CXNAjmX+9ZoUQ+3ofKcwYprcjl3lrxKchLscnhLbW4uTM7u6pZ+z2/ zPiMUXtkXMiJ0uSUT3UlGShB+xDWSsQxz8MeE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=PcGgUXhytehr9tmh1Agcgit62y1yoNvFyzEBCx+RPfs=; b=ZKFZNat3k/SJ8Eba8Qrl2tPI5KQ1nzAsZMVWkDt4+GH8Wpb19ecNACF3SbUAmDd0Hh MVdrZK3Gk4EibFvzgfi/ETEGLE76SbaYed3uz+9boeUGy+/Bxz6Bymtri/07glAHdNg0 Mo8ZV+g7R8+qsoegL00MqpTY1yquBjSmnjkfYSQNAdfB4UbtCaxUUdDjcnd4TyPZejPf 7DAFR244x+TU3jB+fam1RPYWYjbWhP4khjcSFZzRcFI3qeTG3cFqbm1pFeiEWaWV55gs On9ph11zjNNlAMlJMbNoeko0OElB2Hj34qy7S0kZInH9BALaaEFwfcGtKW0ZjXg9FQ+M GmQg== X-Gm-Message-State: APf1xPANJZ/0w+nkgXGBed+yulhP2trvoyR/ir3/h4Mv0WZevlxum4oq Awo4RH04aLoTrQpY4G1sEToeow== X-Google-Smtp-Source: AG47ELsfdK99U+MWPzpKeLlMDvl5LgXDLRSuB0beJ5kA2SciOnWC3z4yDAnmdRFwY1P8Fu7aczgg/Q== X-Received: by 2002:a17:902:a705:: with SMTP id w5-v6mr21479591plq.299.1520464036991; Wed, 07 Mar 2018 15:07:16 -0800 (PST) Date: Wed, 7 Mar 2018 15:07:14 -0800 From: Kees Cook To: Andrew Morton Cc: "Tobin C. Harding" , Jonathan Corbet , Pantelis Antoniou , "Steven Rostedt (VMware)" , kernel-hardening@lists.openwall.com, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] vsprintf: Remove accidental VLA usage Message-ID: <20180307230714.GA20797@beast> MIME-Version: 1.0 Content-Disposition: inline X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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;