From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932464AbcILCRi (ORCPT ); Sun, 11 Sep 2016 22:17:38 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:26789 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755307AbcILCRf (ORCPT ); Sun, 11 Sep 2016 22:17:35 -0400 From: liushuoran To: Ard Biesheuvel , Xiakaixu CC: Herbert Xu , "David S. Miller" , "Theodore Ts'o" , Jaegeuk Kim , "nhorman@tuxdriver.com" , "mh1@iki.fi" , "linux-crypto@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Wangbintian , Huxinwei , "zhangzhibin (C)" Subject: RE: Kernel panic - encryption/decryption failed when open file on Arm64 Thread-Topic: Kernel panic - encryption/decryption failed when open file on Arm64 Thread-Index: AQHSCc31Loj40l5ikUibyvXdPHoySKBvBIGAgAFpGwCAAANngIAABuyAgASn8CA= Date: Mon, 12 Sep 2016 02:16:30 +0000 Message-ID: <00B10D30F2BAA743B48953A4D86C96D54C8A8A@SZXEMI506-MBS.china.huawei.com> References: <57D15BD3.40903@huawei.com> <20160908124709.GA26586@gondor.apana.org.au> <57D28CB8.4080904@huawei.com> In-Reply-To: Accept-Language: en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.111.173.166] Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.57D6100D.00FA,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=169.254.6.52, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 4db6f947eab51fe822b6529ec4c94ff5 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id u8C2HiA6009550 Hi Ard, Thanks for the prompt reply. With the patch, there is no panic anymore. But it seems that the encryption/decryption is not successful anyway. As Herbert points out, "If the page allocation fails in blkcipher_walk_next it'll simply switch over to processing it block by block". So does that mean the encryption/decryption should be successful even if the page allocation fails? Please correct me if I misunderstand anything. Thanks in advance. Regards, Shuoran > -----Original Message----- > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] > Sent: Friday, September 09, 2016 6:57 PM > To: Xiakaixu > Cc: Herbert Xu; David S. Miller; Theodore Ts'o; Jaegeuk Kim; > nhorman@tuxdriver.com; mh1@iki.fi; linux-crypto@vger.kernel.org; > linux-kernel@vger.kernel.org; Wangbintian; liushuoran; Huxinwei; zhangzhibin > (C) > Subject: Re: Kernel panic - encryption/decryption failed when open file on > Arm64 > > On 9 September 2016 at 11:31, Ard Biesheuvel > wrote: > > On 9 September 2016 at 11:19, xiakaixu wrote: > >> Hi, > >> > >> After a deeply research about this crash, seems it is a specific > >> bug that only exists in armv8 board. And it occurs in this function > >> in arch/arm64/crypto/aes-glue.c. > >> > >> static int ctr_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, > >> struct scatterlist *src, unsigned int nbytes) > >> { > >> ... > >> > >> desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP; > >> blkcipher_walk_init(&walk, dst, src, nbytes); > >> err = blkcipher_walk_virt_block(desc, &walk, AES_BLOCK_SIZE); > ---> > >> page allocation failed > >> > >> ... > >> > >> while ((blocks = (walk.nbytes / AES_BLOCK_SIZE))) > { ----> > >> walk.nbytes = 0, and skip this loop > >> aes_ctr_encrypt(walk.dst.virt.addr, walk.src.virt.addr, > >> (u8 *)ctx->key_enc, rounds, blocks, > walk.iv, > >> first); > >> ... > >> err = blkcipher_walk_done(desc, &walk, > >> walk.nbytes % > AES_BLOCK_SIZE); > >> } > >> if (nbytes) > { ----> > >> enter this if() statement > >> u8 *tdst = walk.dst.virt.addr + blocks * AES_BLOCK_SIZE; > >> u8 *tsrc = walk.src.virt.addr + blocks * AES_BLOCK_SIZE; > >> ... > >> > >> aes_ctr_encrypt(tail, tsrc, (u8 *)ctx->key_enc, rounds, > >> ----> the the sencond input parameter is NULL, so crash... > >> blocks, walk.iv, first); > >> ... > >> } > >> ... > >> } > >> > >> > >> If the page allocation failed in the function blkcipher_walk_virt_block(), > >> the variable walk.nbytes = 0, so it will skip the while() loop and enter > >> the if(nbytes) statment. But here the varibale tsrc is NULL and it is also > >> the sencond input parameter of the function aes_ctr_encrypt()... Kernel > >> Panic... > >> > >> I have also researched the similar function in other architectures, and > >> there if(walk.nbytes) is used, not this if(nbytes) statement in the armv8. > >> so I think this armv8 function ctr_encrypt() should deal with the page > >> allocation failed situation. > >> > > Does this solve your problem? > > diff --git a/arch/arm64/crypto/aes-glue.c b/arch/arm64/crypto/aes-glue.c > index 5c888049d061..6b2aa0fd6cd0 100644 > --- a/arch/arm64/crypto/aes-glue.c > +++ b/arch/arm64/crypto/aes-glue.c > @@ -216,7 +216,7 @@ static int ctr_encrypt(struct blkcipher_desc > *desc, struct scatterlist *dst, > err = blkcipher_walk_done(desc, &walk, > walk.nbytes % AES_BLOCK_SIZE); > } > - if (nbytes) { > + if (walk.nbytes % AES_BLOCK_SIZE) { > u8 *tdst = walk.dst.virt.addr + blocks * AES_BLOCK_SIZE; > u8 *tsrc = walk.src.virt.addr + blocks * AES_BLOCK_SIZE; > u8 __aligned(8) tail[AES_BLOCK_SIZE];