From patchwork Fri Mar 9 03:35:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tycho Andersen X-Patchwork-Id: 10269621 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 764D060236 for ; Fri, 9 Mar 2018 03:36:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6659F29C6F for ; Fri, 9 Mar 2018 03:36:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5AB2A29C75; Fri, 9 Mar 2018 03:36:19 +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.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 7A04229C6F for ; Fri, 9 Mar 2018 03:36:17 +0000 (UTC) Received: (qmail 3709 invoked by uid 550); 9 Mar 2018 03:36:15 -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 3688 invoked from network); 9 Mar 2018 03:36:14 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tycho-ws.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=bFGq9LT97zGditzQAX1mbCyj5hIYwXl8ey6GfgUfr/U=; b=nUAYBCtBUWRcj/HcmbISiDHhM0A6d04FXhwQE6qhksYUPa2fVYF0u1ZsjIo/FcCQiX lk5mt03l9Z9ArpmIYvaMZRinHK8FvJjTi/MkAcR2w8fD4jxcWyRIapiAJPxPjMb3ebC3 H9H+Xf53KhL2Cx9qzZ+ob2yxo1sppLBPvcROQfPX4z4yhRB69Og3Pp06CYr5eTT5oJ88 foJfpvwtDx1EJCsRl3X3y8McUt6LZ4U0vl+ajG9AiK1Rc8wp+YbpenfToOLYZ/7L90uU jQRB3fuDAwvEqQH4boRlwEIPOIFLf6HQbk0npUvEIvIeedvpe9PaB9cgRtNoz2HYtxh3 JQVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=bFGq9LT97zGditzQAX1mbCyj5hIYwXl8ey6GfgUfr/U=; b=n0BYmJJ1Y9otCZRO9fKf0cWMmH38LpcvGy7FmxR8fa9gAfEwLfI/7neH+dONDcdc1Z Bnr9dB+a1Bp5dm/17iB0dDpaku+7d07i0FhVVgOh9cf7yDF9Z9aP02Rz4ouF0aVIOCym tlcn3XOluXQ6xbzczb0sHFbAHuQNdIb5dTaCxE98A+/ZkrUEuXiTLTiHGVXROeDAcZ3E RWvm/5+3oz3tANilG0ZwE7T0NFC5KaebYFO+LWHhRBdvspTu7OazyYeLvmA2El95rQW2 OM64m1Js1pqTyiXma0mLhEL1kxcG6zZj12W8lceUTHklNcK/oKYcbiiYmNfd7CrNJppt OWhg== X-Gm-Message-State: APf1xPDB+oCs6GUIzuJKUewNcsZZ8jdhKBZCFT0THqp+t5XHyiJNlr/B dUBAdHzwpORuINpoDuq5EXXcMQ== X-Google-Smtp-Source: AG47ELtat6uCbYx/3RruR0uMzV8blgUHZx/2URuKSiFt2489y6fgLwu6WHDz4GQUezxv8IiIbdKVbA== X-Received: by 10.101.101.206 with SMTP id y14mr22407765pgv.297.1520566562455; Thu, 08 Mar 2018 19:36:02 -0800 (PST) From: Tycho Andersen To: Alasdair Kergon , Mike Snitzer Cc: linux-kernel@vger.kernel.org, dm-devel@redhat.com, kernel-hardening@lists.openwall.com, "Tobin C . Harding" , Tycho Andersen Subject: [PATCH] md: get rid of a VLA Date: Thu, 8 Mar 2018 20:35:44 -0700 Message-Id: <20180309033544.22509-1-tycho@tycho.ws> X-Mailer: git-send-email 2.14.1 X-Virus-Scanned: ClamAV using ClamSMTP Ideally, we'd like to get rid of all VLAs in the kernel and add -Wvla to the build args: https://lkml.org/lkml/2018/3/7/621 This one is a simple case, since we don't actually need the VLA at all: we can just iterate over the stripes twice, once to emit their names, and the second time to emit status (i.e. trade memory for time). Since the number of stripes is probably low, this is hopefully not that expensive. Signed-off-by: Tycho Andersen CC: Alasdair Kergon CC: Mike Snitzer Reviewed-by: Kees Cook --- drivers/md/dm-stripe.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c index b5e892149c54..cd209e8902a6 100644 --- a/drivers/md/dm-stripe.c +++ b/drivers/md/dm-stripe.c @@ -368,7 +368,6 @@ static void stripe_status(struct dm_target *ti, status_type_t type, unsigned status_flags, char *result, unsigned maxlen) { struct stripe_c *sc = (struct stripe_c *) ti->private; - char buffer[sc->stripes + 1]; unsigned int sz = 0; unsigned int i; @@ -377,11 +376,12 @@ static void stripe_status(struct dm_target *ti, status_type_t type, DMEMIT("%d ", sc->stripes); for (i = 0; i < sc->stripes; i++) { DMEMIT("%s ", sc->stripe[i].dev->name); - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ? - 'D' : 'A'; } - buffer[i] = '\0'; - DMEMIT("1 %s", buffer); + DMEMIT("1 "); + for (i = 0; i < sc->stripes; i++) { + DMEMIT("%c", atomic_read(&(sc->stripe[i].error_count)) ? + 'D' : 'A'); + } break; case STATUSTYPE_TABLE: