From patchwork Tue Sep 2 23:31:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Behan Webster X-Patchwork-Id: 36537 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f200.google.com (mail-ob0-f200.google.com [209.85.214.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 60B0A202E4 for ; Tue, 2 Sep 2014 23:32:08 +0000 (UTC) Received: by mail-ob0-f200.google.com with SMTP id va2sf41609246obc.3 for ; Tue, 02 Sep 2014 16:32:08 -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=gCPrP/+2iw/P1P+m+aYl/5OhZmcbVRdhAV7ymJxxtqc=; b=OLim2hK8OFmDMtKSnLU7AsLSxxq/3ZRnNd9t2HPeUFDygMdJKSvj3WaUYIcAfo/Cvn ad+piuQIYuVhXcavkJPctkHuntYK6OItvdlJ2WSkyEBMu86oefGhhhckovyNvNTsavhB 2WK6ruj9pKzYNLH/WRcj51APsZjkJ25r86dI9CLfEgKjIv6cmrTqK7YXnwk29aM0Z1vK 033hUFt96XABQXSNDUUHrVc8ECDsdxIc29n9ibsIY3ZGT7lbBPCectwoZuoKw0NRhJ63 GbGA+OnXG+9lqlQPTpFI39sqrYxoB2GSOwAOUgwLK7LTFP2Ot/fQVGyas0KIBdAMFrRk UR3A== X-Gm-Message-State: ALoCoQlD4wDeFHKTwUX5ilBHvV2pGbf1bBpm4zOT9OJn49iPidwZFa9eAF/SwDjoDCY/mWt8FXul X-Received: by 10.43.28.197 with SMTP id rv5mr22177192icb.23.1409700727989; Tue, 02 Sep 2014 16:32:07 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.103.74 with SMTP id x68ls2704467qge.28.gmail; Tue, 02 Sep 2014 16:32:07 -0700 (PDT) X-Received: by 10.220.44.136 with SMTP id a8mr2470635vcf.42.1409700727847; Tue, 02 Sep 2014 16:32:07 -0700 (PDT) Received: from mail-vc0-x231.google.com (mail-vc0-x231.google.com [2607:f8b0:400c:c03::231]) by mx.google.com with ESMTPS id cr2si2983200vcb.8.2014.09.02.16.32.07 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 02 Sep 2014 16:32:07 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::231 as permitted sender) client-ip=2607:f8b0:400c:c03::231; Received: by mail-vc0-f177.google.com with SMTP id hq11so7945488vcb.36 for ; Tue, 02 Sep 2014 16:32:07 -0700 (PDT) X-Received: by 10.221.29.5 with SMTP id rw5mr89829vcb.49.1409700727747; Tue, 02 Sep 2014 16:32:07 -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 uj3csp599798vcb; Tue, 2 Sep 2014 16:32:07 -0700 (PDT) X-Received: by 10.66.243.6 with SMTP id wu6mr7299891pac.157.1409700726836; Tue, 02 Sep 2014 16:32:06 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a4si8251552pat.44.2014.09.02.16.32.06 for ; Tue, 02 Sep 2014 16:32:06 -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 S1755798AbaIBXcD (ORCPT + 25 others); Tue, 2 Sep 2014 19:32:03 -0400 Received: from mail-pa0-f54.google.com ([209.85.220.54]:41649 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755771AbaIBXcB (ORCPT ); Tue, 2 Sep 2014 19:32:01 -0400 Received: by mail-pa0-f54.google.com with SMTP id fb1so15855607pad.27 for ; Tue, 02 Sep 2014 16:32:00 -0700 (PDT) X-Received: by 10.70.19.166 with SMTP id g6mr50948706pde.99.1409700720890; Tue, 02 Sep 2014 16:32:00 -0700 (PDT) Received: from galdor.websterwood.com (S0106dc9fdb80cffd.gv.shawcable.net. [96.50.97.138]) by mx.google.com with ESMTPSA id ko5sm7017341pdb.51.2014.09.02.16.31.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Sep 2014 16:31:59 -0700 (PDT) From: behanw@converseincode.com To: john.johansen@canonical.com Cc: james.l.morris@oracle.com, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, serge@hallyn.com, =?UTF-8?q?Vin=C3=ADcius=20Tinti?= , =?UTF-8?q?Jan-Simon=20M=C3=B6ller?= , Behan Webster , Mark Charlebois Subject: [PATCH v2] apparmor: LLVMLinux: Remove VLAIS Date: Tue, 2 Sep 2014 16:31:47 -0700 Message-Id: <1409700707-12853-1-git-send-email-behanw@converseincode.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <54064FD1.6060900@canonical.com> References: <54064FD1.6060900@canonical.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::231 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: Vinícius Tinti Replaced the use of a Variable Length Array In Struct (VLAIS) with a C99 compliant equivalent. This is the original VLAIS struct. struct { struct shash_desc shash; char ctx[crypto_shash_descsize(apparmor_tfm)]; } desc; This patch instead 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: Jan-Simon Möller Signed-off-by: Behan Webster Signed-off-by: Vinícius Tinti Signed-off-by: Mark Charlebois Acked-by: John Johansen --- security/apparmor/crypto.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/security/apparmor/crypto.c b/security/apparmor/crypto.c index 532471d..62b32e7 100644 --- a/security/apparmor/crypto.c +++ b/security/apparmor/crypto.c @@ -32,10 +32,9 @@ unsigned int aa_hash_size(void) int aa_calc_profile_hash(struct aa_profile *profile, u32 version, void *start, size_t len) { - struct { - struct shash_desc shash; - char ctx[crypto_shash_descsize(apparmor_tfm)]; - } desc; + char desc[sizeof(struct shash_desc) + + crypto_shash_descsize(apparmor_tfm)] CRYPTO_MINALIGN_ATTR; + struct shash_desc *shash = (struct shash_desc *)desc; int error = -ENOMEM; u32 le32_version = cpu_to_le32(version); @@ -46,19 +45,19 @@ int aa_calc_profile_hash(struct aa_profile *profile, u32 version, void *start, if (!profile->hash) goto fail; - desc.shash.tfm = apparmor_tfm; - desc.shash.flags = 0; + shash->tfm = apparmor_tfm; + shash->flags = 0; - error = crypto_shash_init(&desc.shash); + error = crypto_shash_init(shash); if (error) goto fail; - error = crypto_shash_update(&desc.shash, (u8 *) &le32_version, 4); + error = crypto_shash_update(shash, (u8 *) &le32_version, 4); if (error) goto fail; - error = crypto_shash_update(&desc.shash, (u8 *) start, len); + error = crypto_shash_update(shash, (u8 *) start, len); if (error) goto fail; - error = crypto_shash_final(&desc.shash, profile->hash); + error = crypto_shash_final(shash, profile->hash); if (error) goto fail;