From patchwork Tue Sep 2 22:32:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Behan Webster X-Patchwork-Id: 36521 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f199.google.com (mail-pd0-f199.google.com [209.85.192.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6DFDD20C87 for ; Tue, 2 Sep 2014 22:34:14 +0000 (UTC) Received: by mail-pd0-f199.google.com with SMTP id ft15sf798648pdb.6 for ; Tue, 02 Sep 2014 15:34:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type :content-transfer-encoding; bh=tKxfaIc7Xw5jFODuKcRfCi648nsqxOKGPzUqOaf+7x8=; b=YK4Y8XAJFX59FzRw++QRgRD2rDFiFZN0lXD51y/vfJPnUpJDcqCu4zDxpZqv0Kf+dN s/PQmFghXB9sV10BXIk94CBZ6hQAzJ7mktUpIJ+a6LyFyY/zG6zoIRNtIjZ4g4BQR330 +ugq90BJcpnszJvLQeb9sybKAREzElT+A3jVHs8kVtCelSiTLUEw9us3YUJ/imPvWwxc F17VVZPO13JeC7r2/Y2+QKhNHiXIRPU3p4mYQ8TOvZoyBV0EUeKOVCpeA0vB/3zuN4Q3 yRtfSrbbLWgTdo9Q1A7iu0iSxTnYKkCui4YKwUsFo+/Oi3IRq+fvJucgFLvgkJIUEQ+d ho3Q== X-Gm-Message-State: ALoCoQm7NDYeGtXjCHa6TVjP7su3QoqBgbey6DImBktPoGY7hjDv+OZZCL5+CA/axSc+9qPT4T3q X-Received: by 10.66.245.197 with SMTP id xq5mr2374313pac.42.1409697253552; Tue, 02 Sep 2014 15:34:13 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.18.193 with SMTP id 59ls2678549qgf.7.gmail; Tue, 02 Sep 2014 15:34:13 -0700 (PDT) X-Received: by 10.220.167.9 with SMTP id o9mr32191821vcy.8.1409697253426; Tue, 02 Sep 2014 15:34:13 -0700 (PDT) Received: from mail-vc0-x22a.google.com (mail-vc0-x22a.google.com [2607:f8b0:400c:c03::22a]) by mx.google.com with ESMTPS id n3si2900961vcj.92.2014.09.02.15.34.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 02 Sep 2014 15:34:13 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22a as permitted sender) client-ip=2607:f8b0:400c:c03::22a; Received: by mail-vc0-f170.google.com with SMTP id la4so8009805vcb.1 for ; Tue, 02 Sep 2014 15:34:13 -0700 (PDT) X-Received: by 10.221.21.201 with SMTP id qt9mr2725602vcb.39.1409697253302; Tue, 02 Sep 2014 15:34:13 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp594432vcb; Tue, 2 Sep 2014 15:34:12 -0700 (PDT) X-Received: by 10.69.12.33 with SMTP id en1mr51606486pbd.66.1409697252440; Tue, 02 Sep 2014 15:34:12 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id tm10si7935044pac.134.2014.09.02.15.34.11 for ; Tue, 02 Sep 2014 15:34:12 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755514AbaIBWd0 (ORCPT + 25 others); Tue, 2 Sep 2014 18:33:26 -0400 Received: from mail-pa0-f52.google.com ([209.85.220.52]:50527 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755424AbaIBWdP (ORCPT ); Tue, 2 Sep 2014 18:33:15 -0400 Received: by mail-pa0-f52.google.com with SMTP id eu11so15751577pac.25 for ; Tue, 02 Sep 2014 15:33:14 -0700 (PDT) X-Received: by 10.70.126.194 with SMTP id na2mr23936708pdb.124.1409697194153; Tue, 02 Sep 2014 15:33:14 -0700 (PDT) Received: from galdor.websterwood.com (S0106dc9fdb80cffd.gv.shawcable.net. [96.50.97.138]) by mx.google.com with ESMTPSA id c2sm6945161pds.32.2014.09.02.15.33.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Sep 2014 15:33:12 -0700 (PDT) From: behanw@converseincode.com To: agk@redhat.com, clm@fb.com, davem@davemloft.net, dm-devel@redhat.com, fabf@skynet.be, herbert@gondor.apana.org.au, jbacik@fb.com, snitzer@redhat.com Cc: akpm@linux-foundation.org, james.l.morris@oracle.com, john.johansen@canonical.com, linux-btrfs@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, linux-security-module@vger.kernel.org, neilb@suse.de, serge@hallyn.com, torvalds@linux-foundation.org, =?UTF-8?q?Jan-Simon=20M=C3=B6ller?= , Behan Webster , pageexec@freemail.hu Subject: [PATCH RFC 2/6] crypto: LLVMLinux: Remove VLAIS usage from crypto/hmac.c Date: Tue, 2 Sep 2014 15:32:29 -0700 Message-Id: <1409697153-7006-3-git-send-email-behanw@converseincode.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1409697153-7006-1-git-send-email-behanw@converseincode.com> References: <1409697153-7006-1-git-send-email-behanw@converseincode.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Original-Sender: behanw@converseincode.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22a as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@ Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Jan-Simon Möller The use of variable length arrays in structs (VLAIS) in the Linux Kernel code precludes the use of compilers which don't implement VLAIS (for instance the Clang compiler). This patch instead allocates the appropriate amount of memory using an char array. struct shash_desc contains a flexible array member member ctx declared with CRYPTO_MINALIGN_ATTR, so sizeof(struct shash_desc) aligns the beginning of the array declared after struct shash_desc with long long. No trailing padding is required because it is not a struct type that can be used in an array. The CRYPTO_MINALIGN_ATTR is required so that desc is aligned with long long as would be the case for a struct containing a member with CRYPTO_MINALIGN_ATTR. Signed-off-by: Jan-Simon Möller Signed-off-by: Behan Webster Cc: pageexec@freemail.hu --- crypto/hmac.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/crypto/hmac.c b/crypto/hmac.c index 8d9544c..00ce204 100644 --- a/crypto/hmac.c +++ b/crypto/hmac.c @@ -52,20 +52,19 @@ static int hmac_setkey(struct crypto_shash *parent, struct hmac_ctx *ctx = align_ptr(opad + ss, crypto_tfm_ctx_alignment()); struct crypto_shash *hash = ctx->hash; - struct { - struct shash_desc shash; - char ctx[crypto_shash_descsize(hash)]; - } desc; + char desc[sizeof(struct shash_desc) + + crypto_shash_descsize(hash)] CRYPTO_MINALIGN_ATTR; + struct shash_desc *shash = (struct shash_desc *)desc; unsigned int i; - desc.shash.tfm = hash; - desc.shash.flags = crypto_shash_get_flags(parent) & - CRYPTO_TFM_REQ_MAY_SLEEP; + shash->tfm = hash; + shash->flags = crypto_shash_get_flags(parent) + & CRYPTO_TFM_REQ_MAY_SLEEP; if (keylen > bs) { int err; - err = crypto_shash_digest(&desc.shash, inkey, keylen, ipad); + err = crypto_shash_digest(shash, inkey, keylen, ipad); if (err) return err; @@ -81,12 +80,12 @@ static int hmac_setkey(struct crypto_shash *parent, opad[i] ^= 0x5c; } - return crypto_shash_init(&desc.shash) ?: - crypto_shash_update(&desc.shash, ipad, bs) ?: - crypto_shash_export(&desc.shash, ipad) ?: - crypto_shash_init(&desc.shash) ?: - crypto_shash_update(&desc.shash, opad, bs) ?: - crypto_shash_export(&desc.shash, opad); + return crypto_shash_init(shash) ?: + crypto_shash_update(shash, ipad, bs) ?: + crypto_shash_export(shash, ipad) ?: + crypto_shash_init(shash) ?: + crypto_shash_update(shash, opad, bs) ?: + crypto_shash_export(shash, opad); } static int hmac_export(struct shash_desc *pdesc, void *out)