From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751172AbdK2F1L (ORCPT ); Wed, 29 Nov 2017 00:27:11 -0500 Received: from [128.1.224.119] ([128.1.224.119]:40524 "EHLO ringil.hmeau.com" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1750770AbdK2F1J (ORCPT ); Wed, 29 Nov 2017 00:27:09 -0500 Date: Wed, 29 Nov 2017 16:26:37 +1100 From: Herbert Xu To: Eric Biggers Cc: linux-crypto@vger.kernel.org, "David S . Miller" , linux-kernel@vger.kernel.org, Eric Biggers , stable@vger.kernel.org Subject: Re: [PATCH] crypto: salsa20 - fix blkcipher_walk API usage Message-ID: <20171129052637.GA20154@gondor.apana.org.au> References: <20171129045659.16372-1-ebiggers3@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171129045659.16372-1-ebiggers3@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 28, 2017 at 08:56:59PM -0800, Eric Biggers wrote: > From: Eric Biggers > > When asked to encrypt or decrypt 0 bytes, both the generic and x86 > implementations of Salsa20 crash in blkcipher_walk_done(), either when > doing 'kfree(walk->buffer)' or 'free_page((unsigned long)walk->page)', > because walk->buffer and walk->page have not been initialized. > > The bug is that Salsa20 is calling blkcipher_walk_done() even when > nothing is in 'walk.nbytes'. But blkcipher_walk_done() is only meant to > be called when a nonzero number of bytes have been provided. > > The broken code is part of an optimization that tries to make only one > call to salsa20_encrypt_bytes() to process inputs that are not evenly > divisible by 64 bytes. To fix the bug, just remove this "optimization" > and use the blkcipher_walk API the same way all the other users do. > > Reproducer: > > #include > #include > #include > > int main() > { > int algfd, reqfd; > struct sockaddr_alg addr = { > .salg_type = "skcipher", > .salg_name = "salsa20", > }; > char key[16] = { 0 }; > > algfd = socket(AF_ALG, SOCK_SEQPACKET, 0); > bind(algfd, (void *)&addr, sizeof(addr)); > reqfd = accept(algfd, 0, 0); > setsockopt(algfd, SOL_ALG, ALG_SET_KEY, key, sizeof(key)); > read(reqfd, key, sizeof(key)); > } > > Reported-by: syzbot > Fixes: eb6f13eb9f81 ("[CRYPTO] salsa20_generic: Fix multi-page processing") > Cc: # v2.6.25+ > Signed-off-by: Eric Biggers Patch applied. Thanks. -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt