Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752044AbdFOUsq (ORCPT ); Thu, 15 Jun 2017 16:48:46 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:35611 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750830AbdFOUso (ORCPT ); Thu, 15 Jun 2017 16:48:44 -0400 Date: Thu, 15 Jun 2017 13:48:41 -0700 From: Eric Biggers To: Michael Halcrow Cc: David Gstir , tytso@mit.edu, jaegeuk@kernel.org, richard@sigma-star.at, herbert@gondor.apana.org.au, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fscrypt@vger.kernel.org, Daniel Walter Subject: Re: [PATCH v4] fscrypt: Add support for AES-128-CBC Message-ID: <20170615204841.GA66403@gmail.com> References: <20170517180850.GA91213@gmail.com> <20170523051120.15698-1-david@sigma-star.at> <20170615204129.GA23647@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170615204129.GA23647@google.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 Content-Length: 954 Lines: 24 On Thu, Jun 15, 2017 at 01:41:29PM -0700, Michael Halcrow wrote: > > static int validate_user_key(struct fscrypt_info *crypt_info, > > struct fscrypt_context *ctx, u8 *raw_key, > > - const char *prefix) > > + const char *prefix, int min_keysize) > > { > > char *description; > > struct key *keyring_key; > > @@ -111,50 +116,60 @@ static int validate_user_key(struct fscrypt_info *crypt_info, > > master_key = (struct fscrypt_key *)ukp->data; > > BUILD_BUG_ON(FS_AES_128_ECB_KEY_SIZE != FS_KEY_DERIVATION_NONCE_SIZE); > > > > - if (master_key->size != FS_AES_256_XTS_KEY_SIZE) { > > + if (master_key->size < min_keysize || master_key->size > FS_MAX_KEY_SIZE > > + || master_key->size % AES_BLOCK_SIZE != 0) { > > I suggest validating the provided key size directly against the mode. > Else, it looks to me that this code will accept a 128-bit key for > AES-256. > It's doing that already; min_keysize depends on the mode. Eric