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: 4829101 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 267E6C0338 for ; Tue, 2 Sep 2014 22:34:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 46D65201DC for ; Tue, 2 Sep 2014 22:34:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6C1B6201BF for ; Tue, 2 Sep 2014 22:34:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755433AbaIBWd2 (ORCPT ); Tue, 2 Sep 2014 18:33:28 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:48626 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755413AbaIBWdO (ORCPT ); Tue, 2 Sep 2014 18:33:14 -0400 Received: by mail-pa0-f49.google.com with SMTP id kq14so15633578pab.22 for ; Tue, 02 Sep 2014 15:33:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=converseincode.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=BoXn9FG1nJi9k+m1F/teVSrB66Ndm1zvkfwyEcH0i60=; b=rI9Nu3bucsnVTYAgvK42MsX9Q3GtdB72BjgNtE7gXPfY97jMdDNPgb8Ds7qPWUctyQ rVRt1xKuZj0l722w1FSgJ5OqNkIdbBKHKq2E+YtNLHzD2IhtUcVsO+WxKF+TGwmUNuZ8 BaeBBhn3fU3uSiLZwi6r7DpJQQC7hMnaiQrng= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=BoXn9FG1nJi9k+m1F/teVSrB66Ndm1zvkfwyEcH0i60=; b=TjUMt7ep/awshtGFmkhBkMf/AOgJYPbvvdFoaNriOxgeQSiqtKMAbpAZ8/6ajCyNYW 8C11kkI8GWVHOm0CwVzSfyuU4xnUou5b6lND0Rg6JpIuqTAUX30OW9u0l9hzz76FYBXP DIh42xpjA4U+BdLggqsSwkxTJnyxs3c5vYdNfNBBNLhO0U27n7oY5mHTKYCbIvw9oBm5 4nHk7whFXMc7w5ffe6mi6AcvlRtF2bIIiOrUik8qXtnanr2kPC7b5sMHy/GY9ZlpuqFg V5a4a/oEZSgFn/f5uQPs6Cwrh7+deYJ2yI9AcL5ZRrA8qF3Dcexc8QKf2tYgTN2Kp81U Ustg== X-Gm-Message-State: ALoCoQn3zPKemzAjD8+6P/PS5OVKmBYzN/rAo5lVqiZiqncqvKURWHN89ozVsEflCgiFaAadWr1+ 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-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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)