From patchwork Wed Apr 27 17:43:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sowmini Varadhan X-Patchwork-Id: 8964481 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 2A8E2BF29F for ; Thu, 28 Apr 2016 01:07:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 55E88201F5 for ; Thu, 28 Apr 2016 01:07:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 669EA200B4 for ; Thu, 28 Apr 2016 01:07:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753763AbcD1BHa (ORCPT ); Wed, 27 Apr 2016 21:07:30 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:47462 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753759AbcD1BH2 (ORCPT ); Wed, 27 Apr 2016 21:07:28 -0400 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u3S17QWF030963 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 28 Apr 2016 01:07:26 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u3S17PXI011384 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 28 Apr 2016 01:07:25 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u3S17OCt023978 for ; Thu, 28 Apr 2016 01:07:24 GMT Received: from oracle.com (/10.154.179.9) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 27 Apr 2016 18:07:24 -0700 Received: from oracle.com (/10.154.179.9) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 27 Apr 2016 10:44:05 -0700 Date: Wed, 27 Apr 2016 13:43:56 -0400 From: Sowmini Varadhan To: sowmini.varadhan@oracle.com, tadeusz.struk@intel.com, linux-kernel@vger.kernel.org Cc: herbert@gondor.apana.org.au, smueller@chronox.de, mmarek@suse.com, arnd@arndb.de, andrew.zaborowski@intel.com Subject: [PATCH v2] lib/mpi: Fix kernel unaligned access in mpi_write_to_sgl Message-ID: <20160427174338.GA15460@oracle.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 Commit 2d4d1eea540b ("lib/mpi: Add mpi sgl helpers") added mpi_write_to_sgl() which generates traps due to unaligned access on some platforms like sparc. Fix this by using the get_unaligned* and put_unaligned* functions. Fixes: 2d4d1eea540b ("lib/mpi: Add mpi sgl helpers") Signed-off-by: Sowmini Varadhan --- v2: tadeusz.struk comments: Predicate on BYTES_PER_MPI_LIMB. lib/mpi/mpicoder.c | 21 +++++++++++++++++---- 1 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/mpi/mpicoder.c b/lib/mpi/mpicoder.c index eb15e7d..b61eb6b 100644 --- a/lib/mpi/mpicoder.c +++ b/lib/mpi/mpicoder.c @@ -21,6 +21,7 @@ #include #include #include "mpi-internal.h" +#include #define MAX_EXTERN_MPI_BITS 16384 @@ -405,10 +406,22 @@ int mpi_write_to_sgl(MPI a, struct scatterlist *sgl, unsigned *nbytes, p -= sizeof(alimb); continue; } else { - mpi_limb_t *limb1 = (void *)p - sizeof(alimb); - mpi_limb_t *limb2 = (void *)p - sizeof(alimb) - + lzeros; - *limb1 = *limb2; + mpi_limb_t tmp; +#if BYTES_PER_MPI_LIMB == 4 + tmp = get_unaligned_be32((void *)p - + sizeof(alimb) + + lzeros); + put_unaligned_be32(tmp, (void *)p - + sizeof(alimb)); +#elif BYTES_PER_MPI_LIMB == 8 + tmp = get_unaligned_be64((void *)p - + sizeof(alimb) + + lzeros); + put_unaligned_be64(tmp, (void *)p - + sizeof(alimb)); +#else +#error please implement for this limb size. +#endif p -= lzeros; y = lzeros; }