From patchwork Fri Sep 5 23:06:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Behan Webster X-Patchwork-Id: 36910 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f71.google.com (mail-pa0-f71.google.com [209.85.220.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CED81202E4 for ; Fri, 5 Sep 2014 23:06:27 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id bj1sf161938pad.10 for ; Fri, 05 Sep 2014 16:06:27 -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 :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=jokXmInZB5TNsHT4U0EIS1ATMH5qw+EmbDCps4QTJB8=; b=OjmRH8cKgCCUQjAwsP41EnVo7aFktG3rjDAZ/6SCoQ8EZUYrjSLRdR/GQ2bCQZsjCP 5wyS07j3EzU1TpxzeyKNKxtI2ynUUUUyqJhQBMp5P+tNiCcRDmmEupQd3S6h14YTf2AT rX0xhqkyj7ItZGRBguk0P0XHYePWgW4dIi30NH0+h3yW9xFHITmh4Fm61dhCvFikvvfU UHhVGII3zPszBOk2YpQ6xztoDRovbocwXFHcnjB7xMpZ341Qp4+HdA/xRiWICl+uYiT3 7gw9/Dt21nkA6NxPDe8dtu5IrHBPFcsAxxMfMxs8Fo/4lLXan24JaF7SNFe14VnsVgWk ODZQ== X-Gm-Message-State: ALoCoQkbPPjX/3KRXANH/EDQUojQuz1sqM2I0L4nUqU8p1ujJup2VyIvzUZlSyXqfZ47tEQenaBp X-Received: by 10.70.34.195 with SMTP id b3mr8755498pdj.7.1409958387147; Fri, 05 Sep 2014 16:06:27 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.90.51 with SMTP id w48ls584843qgd.49.gmail; Fri, 05 Sep 2014 16:06:27 -0700 (PDT) X-Received: by 10.52.228.67 with SMTP id sg3mr10886248vdc.6.1409958387017; Fri, 05 Sep 2014 16:06:27 -0700 (PDT) Received: from mail-vc0-x22e.google.com (mail-vc0-x22e.google.com [2607:f8b0:400c:c03::22e]) by mx.google.com with ESMTPS id fj7si1556090vcb.13.2014.09.05.16.06.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 05 Sep 2014 16:06:26 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22e as permitted sender) client-ip=2607:f8b0:400c:c03::22e; Received: by mail-vc0-f174.google.com with SMTP id hy4so13216067vcb.33 for ; Fri, 05 Sep 2014 16:06:26 -0700 (PDT) X-Received: by 10.220.114.5 with SMTP id c5mr12873182vcq.28.1409958386875; Fri, 05 Sep 2014 16:06:26 -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 uj3csp148785vcb; Fri, 5 Sep 2014 16:06:26 -0700 (PDT) X-Received: by 10.66.236.38 with SMTP id ur6mr26366713pac.49.1409958386234; Fri, 05 Sep 2014 16:06:26 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qo10si6154168pab.190.2014.09.05.16.06.25 for ; Fri, 05 Sep 2014 16:06:26 -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 S1753831AbaIEXGY (ORCPT + 26 others); Fri, 5 Sep 2014 19:06:24 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:34408 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752059AbaIEXGW (ORCPT ); Fri, 5 Sep 2014 19:06:22 -0400 Received: by mail-pa0-f50.google.com with SMTP id kq14so23246904pab.9 for ; Fri, 05 Sep 2014 16:06:22 -0700 (PDT) X-Received: by 10.70.50.170 with SMTP id d10mr24625713pdo.33.1409958382112; Fri, 05 Sep 2014 16:06:22 -0700 (PDT) Received: from galdor.websterwood.com (S0106dc9fdb80cffd.gv.shawcable.net. [96.50.97.138]) by mx.google.com with ESMTPSA id ro7sm2793950pab.25.2014.09.05.16.06.19 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 05 Sep 2014 16:06:20 -0700 (PDT) From: behanw@converseincode.com To: zohar@linux.vnet.ibm.com Cc: d.kasatkin@samsung.com, james.l.morris@oracle.com, linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, serge@hallyn.com, torvalds@linux-foundation.org, Behan Webster , Mark Charlebois , =?UTF-8?q?Jan-Simon=20M=C3=B6ller?= Subject: [PATCH] security, crypto: LLVMLinux: Remove VLAIS from ima_crypto.c Date: Fri, 5 Sep 2014 16:06:00 -0700 Message-Id: <1409958360-8061-1-git-send-email-behanw@converseincode.com> X-Mailer: git-send-email 1.9.1 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::22e 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: Behan Webster Replaced the use of a Variable Length Array In Struct (VLAIS) with a C99 compliant equivalent. This patch allocates the appropriate amount of memory using an char array. The new code can be compiled with both gcc and clang. 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: Behan Webster Signed-off-by: Mark Charlebois Signed-off-by: Jan-Simon Möller --- security/integrity/ima/ima_crypto.c | 53 +++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c index 0bd7328..a6aa2b0 100644 --- a/security/integrity/ima/ima_crypto.c +++ b/security/integrity/ima/ima_crypto.c @@ -380,17 +380,16 @@ static int ima_calc_file_hash_tfm(struct file *file, loff_t i_size, offset = 0; char *rbuf; int rc, read = 0; - struct { - struct shash_desc shash; - char ctx[crypto_shash_descsize(tfm)]; - } desc; + char desc[sizeof(struct shash_desc) + + crypto_shash_descsize(tfm)] CRYPTO_MINALIGN_ATTR; + struct shash_desc *shash = (struct shash_desc *)desc; - desc.shash.tfm = tfm; - desc.shash.flags = 0; + shash->tfm = tfm; + shash->flags = 0; hash->length = crypto_shash_digestsize(tfm); - rc = crypto_shash_init(&desc.shash); + rc = crypto_shash_init(shash); if (rc != 0) return rc; @@ -420,7 +419,7 @@ static int ima_calc_file_hash_tfm(struct file *file, break; offset += rbuf_len; - rc = crypto_shash_update(&desc.shash, rbuf, rbuf_len); + rc = crypto_shash_update(shash, rbuf, rbuf_len); if (rc) break; } @@ -429,7 +428,7 @@ static int ima_calc_file_hash_tfm(struct file *file, kfree(rbuf); out: if (!rc) - rc = crypto_shash_final(&desc.shash, hash->digest); + rc = crypto_shash_final(shash, hash->digest); return rc; } @@ -487,18 +486,17 @@ static int ima_calc_field_array_hash_tfm(struct ima_field_data *field_data, struct ima_digest_data *hash, struct crypto_shash *tfm) { - struct { - struct shash_desc shash; - char ctx[crypto_shash_descsize(tfm)]; - } desc; + char desc[sizeof(struct shash_desc) + + crypto_shash_descsize(tfm)] CRYPTO_MINALIGN_ATTR; + struct shash_desc *shash = (struct shash_desc *)desc; int rc, i; - desc.shash.tfm = tfm; - desc.shash.flags = 0; + shash->tfm = tfm; + shash->flags = 0; hash->length = crypto_shash_digestsize(tfm); - rc = crypto_shash_init(&desc.shash); + rc = crypto_shash_init(shash); if (rc != 0) return rc; @@ -508,7 +506,7 @@ static int ima_calc_field_array_hash_tfm(struct ima_field_data *field_data, u32 datalen = field_data[i].len; if (strcmp(td->name, IMA_TEMPLATE_IMA_NAME) != 0) { - rc = crypto_shash_update(&desc.shash, + rc = crypto_shash_update(shash, (const u8 *) &field_data[i].len, sizeof(field_data[i].len)); if (rc) @@ -518,13 +516,13 @@ static int ima_calc_field_array_hash_tfm(struct ima_field_data *field_data, data_to_hash = buffer; datalen = IMA_EVENT_NAME_LEN_MAX + 1; } - rc = crypto_shash_update(&desc.shash, data_to_hash, datalen); + rc = crypto_shash_update(shash, data_to_hash, datalen); if (rc) break; } if (!rc) - rc = crypto_shash_final(&desc.shash, hash->digest); + rc = crypto_shash_final(shash, hash->digest); return rc; } @@ -565,15 +563,14 @@ static int __init ima_calc_boot_aggregate_tfm(char *digest, { u8 pcr_i[TPM_DIGEST_SIZE]; int rc, i; - struct { - struct shash_desc shash; - char ctx[crypto_shash_descsize(tfm)]; - } desc; + char desc[sizeof(struct shash_desc) + + crypto_shash_descsize(tfm)] CRYPTO_MINALIGN_ATTR; + struct shash_desc *shash = (struct shash_desc *)desc; - desc.shash.tfm = tfm; - desc.shash.flags = 0; + shash->tfm = tfm; + shash->flags = 0; - rc = crypto_shash_init(&desc.shash); + rc = crypto_shash_init(shash); if (rc != 0) return rc; @@ -581,10 +578,10 @@ static int __init ima_calc_boot_aggregate_tfm(char *digest, for (i = TPM_PCR0; i < TPM_PCR8; i++) { ima_pcrread(i, pcr_i); /* now accumulate with current aggregate */ - rc = crypto_shash_update(&desc.shash, pcr_i, TPM_DIGEST_SIZE); + rc = crypto_shash_update(shash, pcr_i, TPM_DIGEST_SIZE); } if (!rc) - crypto_shash_final(&desc.shash, digest); + crypto_shash_final(shash, digest); return rc; }