From patchwork Mon Mar 12 04:27:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobin Harding X-Patchwork-Id: 10275447 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 CCC926038F for ; Mon, 12 Mar 2018 04:27:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE46C28BB8 for ; Mon, 12 Mar 2018 04:27:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2E9B28BE8; Mon, 12 Mar 2018 04:27:52 +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 E139428BB8 for ; Mon, 12 Mar 2018 04:27:51 +0000 (UTC) Received: (qmail 5396 invoked by uid 550); 12 Mar 2018 04:27:49 -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 5354 invoked from network); 12 Mar 2018 04:27:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tobin.cc; h=cc :date:from:message-id:subject:to:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=VpjFo8u6KOeUvTmN6GDsZxaVQ85RQKupAr0HUwUmv Xo=; b=WJ1t/ou7sY4K3jAbfQXO5Ho1yQQ6ttdtBZY0FeFIFCnjmbGlt9syo2mAQ hYAHqhCTCxwtQBfRMEQvdFCDzOtqnVByUwudaHnXOaBwNV5eDx7hbag01wEvZGa+ IJv3JEvCRyHEL9SdFF1OV/EHdkbfeDqP26QSKLan+0+FCxpe5w3AbIOzD1qas+Lw mbzpwpluTJ97W3XG2JyEqBoVAVeSOTiR66Vla262ciExLt/GbY+R5ZJzAFn6/mU/ cWgvF9QSfEmQsMnbkNrtM2rNAnNM7tjLWXkbg6qvS1N4aWQJPipOgQg/Wz30/nq/ gENReAdOqOjLw0jazn5Y+9J6+as/Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:message-id:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=VpjFo8u6KOeUvTmN6 GDsZxaVQ85RQKupAr0HUwUmvXo=; b=fKwuEN/e/iCby8F630HDVN655nQqB5XO7 fd+2wk90Rwp+8cETKWQvcPJrN7rgd7YpOpFnBMCAGwj0CQ0Na1OvV8+15gq4WBpd UPipcHKzmWDejg/8GGKLoQgmPPIcc8hlJMc24yXHhDmn1JqwGPmHaTTIbxORBaJC RQ55OJxdFv39PSQlCHxGQ2ydpSSjmtoi/MDmWPjJpvxYXFFT9XW4DCVsyEnVi8qT KRCxDChm6N6zO+5rlfRY7QzIc3h9PSEBjGT3FYuuXgeqUeVuNsEIQum//cwxM8WR 0hWzxjLm1Ixo5yM391F9qLmosZ42ZYqO6jKuoaVH+GDTZ5Nagf5RA== X-ME-Sender: From: "Tobin C. Harding" To: Rob Herring , Frank Rowand Cc: "Tobin C. Harding" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, Tycho Andersen , Kees Cook Subject: [PATCH] of: unittest: Remove VLA stack usage Date: Mon, 12 Mar 2018 15:27:23 +1100 Message-Id: <1520828843-22289-1-git-send-email-me@tobin.cc> X-Mailer: git-send-email 2.7.4 X-Virus-Scanned: ClamAV using ClamSMTP The kernel would like to have all stack VLA usage removed[1]. This is a test function so the execution speed is not critical. We can allocate memory for this buffer instead of using a VLA. If kmalloc() fails just return. Allocate buffer with kmalloc(). [1]: https://lkml.org/lkml/2018/3/7/621 Signed-off-by: Tobin C. Harding --- Kees is this annoying you, CC'ing you an all my VLA patches? drivers/of/unittest.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 1991fe4319f5..38cbc343b7da 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -254,12 +254,18 @@ static void __init of_unittest_check_tree_linkage(void) static void __init of_unittest_printf_one(struct device_node *np, const char *fmt, const char *expected) { - unsigned char buf[strlen(expected)+10]; + unsigned char *buf; + int buf_size; int size, i; + buf_size = strlen(expected) + 10; + buf = kmalloc(buf_size, GFP_KERNEL); + if (!buf) + return; + /* Baseline; check conversion with a large size limit */ - memset(buf, 0xff, sizeof(buf)); - size = snprintf(buf, sizeof(buf) - 2, fmt, np); + memset(buf, 0xff, buf_size); + size = snprintf(buf, buf_size - 2, fmt, np); /* use strcmp() instead of strncmp() here to be absolutely sure strings match */ unittest((strcmp(buf, expected) == 0) && (buf[size+1] == 0xff), @@ -270,12 +276,13 @@ static void __init of_unittest_printf_one(struct device_node *np, const char *fm size++; for (i = 0; i < 2; i++, size--) { /* Clear the buffer, and make sure it works correctly still */ - memset(buf, 0xff, sizeof(buf)); + memset(buf, 0xff, buf_size); snprintf(buf, size+1, fmt, np); unittest(strncmp(buf, expected, size) == 0 && (buf[size+1] == 0xff), "snprintf failed; size=%i fmt='%s' expected='%s' rslt='%s'\n", size, fmt, expected, buf); } + kfree(buf); } static void __init of_unittest_printf(void)