From patchwork Thu Sep 10 10:11:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Ryabinin X-Patchwork-Id: 7153181 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CF6B89F1D3 for ; Thu, 10 Sep 2015 10:12:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1268620813 for ; Thu, 10 Sep 2015 10:12:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DCB63207FF for ; Thu, 10 Sep 2015 10:12:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753377AbbIJKMH (ORCPT ); Thu, 10 Sep 2015 06:12:07 -0400 Received: from mx2.parallels.com ([199.115.105.18]:59176 "EHLO mx2.parallels.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753335AbbIJKMG (ORCPT ); Thu, 10 Sep 2015 06:12:06 -0400 Received: from [199.115.105.250] (helo=mail.odin.com) by mx2.parallels.com with esmtps (TLSv1.2:AES256-SHA:256) (Exim 4.85) (envelope-from ) id 1Za0g9-0004Xi-QR; Thu, 10 Sep 2015 05:10:13 -0700 Received: from localhost.sw.ru (10.30.25.228) by US-EXCH.sw.swsoft.com (10.255.249.47) with Microsoft SMTP Server (TLS) id 15.0.1104.5; Thu, 10 Sep 2015 03:11:54 -0700 From: Andrey Ryabinin To: Herbert Xu , "David S. Miller" , CC: , Andrey Ryabinin Subject: [PATCH v2] crypto/testmgr: don't copy from source IV too much Date: Thu, 10 Sep 2015 13:11:55 +0300 Message-ID: <1441879915-5362-1-git-send-email-aryabinin@virtuozzo.com> X-Mailer: git-send-email 2.4.6 In-Reply-To: <20150903132057.GA31317@gondor.apana.org.au> References: <20150903132057.GA31317@gondor.apana.org.au> MIME-Version: 1.0 X-ClientProxiedBy: US-EXCH2.sw.swsoft.com (10.255.249.46) To US-EXCH.sw.swsoft.com (10.255.249.47) 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 While the destination buffer 'iv' is MAX_IVLEN size, the source 'template[i].iv' could be smaller, thus memcpy may read read invalid memory. Use crypto_skcipher_ivsize() to get real ivsize and pass it to memcpy. Signed-off-by: Andrey Ryabinin --- crypto/testmgr.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 35c2de1..fa18753 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -940,6 +940,7 @@ static int __test_skcipher(struct crypto_skcipher *tfm, int enc, char *xbuf[XBUFSIZE]; char *xoutbuf[XBUFSIZE]; int ret = -ENOMEM; + unsigned int ivsize = crypto_skcipher_ivsize(tfm); if (testmgr_alloc_buf(xbuf)) goto out_nobuf; @@ -975,7 +976,7 @@ static int __test_skcipher(struct crypto_skcipher *tfm, int enc, continue; if (template[i].iv) - memcpy(iv, template[i].iv, MAX_IVLEN); + memcpy(iv, template[i].iv, ivsize); else memset(iv, 0, MAX_IVLEN); @@ -1051,7 +1052,7 @@ static int __test_skcipher(struct crypto_skcipher *tfm, int enc, continue; if (template[i].iv) - memcpy(iv, template[i].iv, MAX_IVLEN); + memcpy(iv, template[i].iv, ivsize); else memset(iv, 0, MAX_IVLEN);