From patchwork Tue Oct 13 13:29:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sowmini Varadhan X-Patchwork-Id: 7385411 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0BDBABEEA4 for ; Tue, 13 Oct 2015 13:29:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3811F207C2 for ; Tue, 13 Oct 2015 13:29:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3368A207BE for ; Tue, 13 Oct 2015 13:29:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752592AbbJMN3j (ORCPT ); Tue, 13 Oct 2015 09:29:39 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:26781 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752559AbbJMN3i (ORCPT ); Tue, 13 Oct 2015 09:29:38 -0400 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t9DDTUs0015234 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 13 Oct 2015 13:29:31 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id t9DDTUYi015732 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Tue, 13 Oct 2015 13:29:30 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id t9DDTUBh013027; Tue, 13 Oct 2015 13:29:30 GMT Received: from oracle.com (/10.154.184.204) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 13 Oct 2015 06:29:30 -0700 Date: Tue, 13 Oct 2015 09:29:28 -0400 From: Sowmini Varadhan To: Herbert Xu Cc: dhowells@redhat.com, linux-crypto@vger.kernel.org, "David S. Miller" Subject: Re: unaligned access in pkcs7_verify Message-ID: <20151013132928.GK20800@oracle.com> References: <20151002140014.GI18263@oracle.com> <20151008131519.GA24362@gondor.apana.org.au> <20151008144343.GE19655@oracle.com> <20151012133209.GA27746@gondor.apana.org.au> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20151012133209.GA27746@gondor.apana.org.au> User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 On (10/12/15 21:32), Herbert Xu wrote: > > .. pkcs7_verify definitely > shouldn't place the structure after the digest without aligning the > pointer. So something like your patch is needed (but please use > alignof instead of sizeof). Also don't put in digest_size but > instead align the pointer like > > desc = PTR_ALIGN(digest + digest_size, ...) I tried the patch below for 24+ hours, and it ran without mishaps. But given that the panics I saw earlier (page faults typically triggered by openswan's pluto) occurred unpredictably, it would be useful to have an expert-review of this code. Thanks, --Sowmini --- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/crypto/asymmetric_keys/pkcs7_verify.c b/crypto/asymmetric_keys/pkcs7_verify.c index d20c0b4..958ac01 100644 --- a/crypto/asymmetric_keys/pkcs7_verify.c +++ b/crypto/asymmetric_keys/pkcs7_verify.c @@ -46,14 +46,15 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, return (PTR_ERR(tfm) == -ENOENT) ? -ENOPKG : PTR_ERR(tfm); desc_size = crypto_shash_descsize(tfm) + sizeof(*desc); - sinfo->sig.digest_size = digest_size = crypto_shash_digestsize(tfm); - + sinfo->sig.digest_size = crypto_shash_digestsize(tfm); + digest_size = crypto_shash_digestsize(tfm) + + ALIGN(crypto_shash_digestsize(tfm), __alignof__(*desc)); ret = -ENOMEM; digest = kzalloc(digest_size + desc_size, GFP_KERNEL); if (!digest) goto error_no_desc; - desc = digest + digest_size; + desc = PTR_ALIGN(digest + digest_size, __alignof__(*desc)); desc->tfm = tfm; desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP;