Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp11743imm; Tue, 3 Jul 2018 12:56:21 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfmboA4gSGdnaOIcVXbDBiYOALHv4V/KlYJmM0sfj3TRO3dLFhpTobGlr6EEyNGLDtAWKTu X-Received: by 2002:aa7:818b:: with SMTP id g11-v6mr31055446pfi.50.1530647781006; Tue, 03 Jul 2018 12:56:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530647780; cv=none; d=google.com; s=arc-20160816; b=taPw1T002Ap9hSwOlBj5R4yU//ou8kZ4L8ZALRfD0ae93iaBjV5w0vBGj07XS6/szU oF9tJ8nZ2l4gTjsd2jAvrbLTec2ivwmoJ64pUfmnxrBKeZpMDpUFWuPlWRWpcKGgh+ft hlPsPWoe/UPQtFYAfpR9fqsAHRpBU+NNnjf1g4CAkx6rBNICIwuLyNGQBV4B9EbTXNHU sY8U3/G8LKqrHbMh+dPEAU9RiBRKgEgmZdZOTWDi/kG/8GusBxek8gcUnMsmrWtNrlds 7eTq9dVaMo4dM/sDLzaztDqu8crEsMHo/zHnP2BUR2eaTQSPtMITbfDYTsodbAo5Kt+D H2Ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=v6ZpNerl9EQJMOOMYOxMbHrmgDCVLx18mqFWGIweoXw=; b=iGsKGv2g7lecXXd5hSHrig1WH5EaKPPQawrO0FGSuC85M5GKuoY0qF/icCWcxhoY5I 1eUqJdlB6HBGYP8PsRpmPEy5vCqJcFaHMRd640pVuLR9neXq/zbkquo25eGzaggY8dfG vDSFwporFwF3X2rCQqf6LZ8vBjudj+luBtmP50op6SckFMfjL8wFc+cKx7vEmLaDH/Ui 5k2JQumZ8Y4HKJQ320d8hkzQ616PN1sZRbJ7NVQ5ORjnYTMOqi2ZCvWe/tssyD5XN21U J3xHzu+38n/NJjDkWA7nu3yjIj1rjBeWxdVqgtsHv4qYwahU+bJAEPo2Id8byxm9DL/a G9Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ijvGxj9s; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n4-v6si1645355pgs.362.2018.07.03.12.56.06; Tue, 03 Jul 2018 12:56:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ijvGxj9s; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753000AbeGCTzE (ORCPT + 99 others); Tue, 3 Jul 2018 15:55:04 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:34542 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752958AbeGCTzC (ORCPT ); Tue, 3 Jul 2018 15:55:02 -0400 Received: by mail-pg0-f65.google.com with SMTP id y5-v6so1438084pgv.1 for ; Tue, 03 Jul 2018 12:55:01 -0700 (PDT) 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=v6ZpNerl9EQJMOOMYOxMbHrmgDCVLx18mqFWGIweoXw=; b=ijvGxj9s9Dl4jRKHyZluqzir7cb2WLfHYFEf/+7QjWZo71IUdgVHERXw1P7SCTAIaw 4gRAnB9UvMCGpFM4ntI82mhea060AR/cMJG14hwtTsC0rh7h0QLTyB5zsuojxK9NWeYe wcJ49Vf3g3nEpi+H+E5swfLDOnEZMV1Kl1I98= 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=v6ZpNerl9EQJMOOMYOxMbHrmgDCVLx18mqFWGIweoXw=; b=LQuKJ1ExUdaHmVG2aDDyi8h3cj7vyz/4mxx8fGwS8bnghnMRKrfQBCh8fr6iFFyhG7 aIyjDFhVSyJtBDEiZ6jJT9w/YoJPmh5UuBxf/UC/mMe81pEbBA7+8XcPgkGolyd9zSqq c1fPRegYAwZEy4hAjYyBWh6adnepyPeqqTJigc8EsNHjQ/f17v0I7FPRDfAA2DOcgteA kYyg/SMbz8fsq4NCLlRqr6uccD4lO3ASIzVowpeODGF6nGUgjHiMVj5Km1ubaFzo22BN H4pVotwIAFr/oQY3sWzDxuBYd8oFb3gUdgR3u9wMt/vCpvritZmGLaGcqbxlqy52xBNK a2vw== X-Gm-Message-State: APt69E1GH798HPrOXvbpOsC8/h6lltbRnSoZMyIX42kPl5TAzttKexwQ pF7Bu+MdFaKYOYVY3sX+ZG/E0w== X-Received: by 2002:a65:4acd:: with SMTP id c13-v6mr21968686pgu.436.1530647701682; Tue, 03 Jul 2018 12:55:01 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id a25-v6sm3202754pgv.51.2018.07.03.12.55.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Jul 2018 12:55:00 -0700 (PDT) Date: Tue, 3 Jul 2018 12:54:59 -0700 From: Kees Cook To: Martin Schwidefsky Cc: linux-kernel@vger.kernel.org, Philippe Ombredanne Subject: [PATCH] RAID/s390: Remove VLA usage Message-ID: <20180703195459.GA11107@beast> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the quest to remove all stack VLA usage from the kernel[1], this moves the "$#" replacement from being an argument to being inside the function, which avoids generating VLAs. [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Cc: Martin Schwidefsky Cc: Philippe Ombredanne Signed-off-by: Kees Cook --- Resend due to typo in To/Cc --- lib/raid6/s390vx.uc | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/raid6/s390vx.uc b/lib/raid6/s390vx.uc index 140fa8bb5c23..914ebe98fc21 100644 --- a/lib/raid6/s390vx.uc +++ b/lib/raid6/s390vx.uc @@ -55,22 +55,24 @@ static inline void XOR(int x, int y, int z) asm volatile ("VX %0,%1,%2" : : "i" (x), "i" (y), "i" (z)); } -static inline void LOAD_DATA(int x, int n, u8 *ptr) +static inline void LOAD_DATA(int x, u8 *ptr) { - typedef struct { u8 _[16*n]; } addrtype; + typedef struct { u8 _[16 * $#]; } addrtype; register addrtype *__ptr asm("1") = (addrtype *) ptr; asm volatile ("VLM %2,%3,0,%r1" - : : "m" (*__ptr), "a" (__ptr), "i" (x), "i" (x + n - 1)); + : : "m" (*__ptr), "a" (__ptr), "i" (x), + "i" (x + $# - 1)); } -static inline void STORE_DATA(int x, int n, u8 *ptr) +static inline void STORE_DATA(int x, u8 *ptr) { - typedef struct { u8 _[16*n]; } addrtype; + typedef struct { u8 _[16 * $#]; } addrtype; register addrtype *__ptr asm("1") = (addrtype *) ptr; asm volatile ("VSTM %2,%3,0,1" - : "=m" (*__ptr) : "a" (__ptr), "i" (x), "i" (x + n - 1)); + : "=m" (*__ptr) : "a" (__ptr), "i" (x), + "i" (x + $# - 1)); } static inline void COPY_VEC(int x, int y) @@ -93,19 +95,19 @@ static void raid6_s390vx$#_gen_syndrome(int disks, size_t bytes, void **ptrs) q = dptr[z0 + 2]; /* RS syndrome */ for (d = 0; d < bytes; d += $#*NSIZE) { - LOAD_DATA(0,$#,&dptr[z0][d]); + LOAD_DATA(0,&dptr[z0][d]); COPY_VEC(8+$$,0+$$); for (z = z0 - 1; z >= 0; z--) { MASK(16+$$,8+$$); AND(16+$$,16+$$,25); SHLBYTE(8+$$,8+$$); XOR(8+$$,8+$$,16+$$); - LOAD_DATA(16,$#,&dptr[z][d]); + LOAD_DATA(16,&dptr[z][d]); XOR(0+$$,0+$$,16+$$); XOR(8+$$,8+$$,16+$$); } - STORE_DATA(0,$#,&p[d]); - STORE_DATA(8,$#,&q[d]); + STORE_DATA(0,&p[d]); + STORE_DATA(8,&q[d]); } kernel_fpu_end(&vxstate, KERNEL_VXR); } @@ -127,14 +129,14 @@ static void raid6_s390vx$#_xor_syndrome(int disks, int start, int stop, for (d = 0; d < bytes; d += $#*NSIZE) { /* P/Q data pages */ - LOAD_DATA(0,$#,&dptr[z0][d]); + LOAD_DATA(0,&dptr[z0][d]); COPY_VEC(8+$$,0+$$); for (z = z0 - 1; z >= start; z--) { MASK(16+$$,8+$$); AND(16+$$,16+$$,25); SHLBYTE(8+$$,8+$$); XOR(8+$$,8+$$,16+$$); - LOAD_DATA(16,$#,&dptr[z][d]); + LOAD_DATA(16,&dptr[z][d]); XOR(0+$$,0+$$,16+$$); XOR(8+$$,8+$$,16+$$); } @@ -145,12 +147,12 @@ static void raid6_s390vx$#_xor_syndrome(int disks, int start, int stop, SHLBYTE(8+$$,8+$$); XOR(8+$$,8+$$,16+$$); } - LOAD_DATA(16,$#,&p[d]); + LOAD_DATA(16,&p[d]); XOR(16+$$,16+$$,0+$$); - STORE_DATA(16,$#,&p[d]); - LOAD_DATA(16,$#,&q[d]); + STORE_DATA(16,&p[d]); + LOAD_DATA(16,&q[d]); XOR(16+$$,16+$$,8+$$); - STORE_DATA(16,$#,&q[d]); + STORE_DATA(16,&q[d]); } kernel_fpu_end(&vxstate, KERNEL_VXR); } -- 2.17.1 -- Kees Cook Pixel Security