Received: by 10.192.165.148 with SMTP id m20csp4216345imm; Mon, 23 Apr 2018 21:55:49 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/ZKhpqNV03UScRP4sFp6XgIJsyc5g3MNCrHz5Hyve9cXNNuZe51J9vw40Rx3bYIfQNbcTx X-Received: by 10.167.129.10 with SMTP id b10mr22600357pfi.186.1524545749586; Mon, 23 Apr 2018 21:55:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524545749; cv=none; d=google.com; s=arc-20160816; b=aGBKOvGu5/3kkkzXUUgiR788yZrruWIp26KouPAzU4mBV2oWTTsOKSUdemm/QDzT+Y PLLUWRKiWuPf2up9T4qMtsiiclykdM4QI/sM5NmRVmVqexhmXndoHiJHM22H509rm+OT m/7yBoSAZThPN9rsnIOflYaynti9XCLQvxIakfbBe4VJgg8tAhWvevDpszMjX3x7b3X9 AC8gziNoP8o1QEf7vy10prdPLUh1I3DXYlygpzjNOx2VljSjKou0lIGEFb98kF3sR/OI sGq/R/CQdvV4f3DmtIPxGNAJQtwGVlv3jQgIRNpWWijLDD0ux6/cFQEbRI1hu4XlsoEr /SSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=f0WDbUWyWUY4pixtq78Efq/RSe+g3NjOSUdppJWV/WI=; b=nyvaPDo5phTqYtYQgHRdbCW8FFrfS7/i5iLk1WlUKMdGj1ptnLeZ+hG1xH9LFHiJ7N SMtQgxXaPrW+/ZUFaqkv6iyhovgd6/EX8daKA14b6JF6z5jPSPUeGGfLJat4DN8pZG2B 6/jVvP1AWfnsI19h4GXTej7z1VIVvYpo0gDgpdX1fwESNuxgyOkT8HcQSolYWxYs65Vh VZb9YromhPRuKNRrHrVvzQgGUVsXMhZwUKtbXqxxoBhr+L8Q969hmAy6C0vaD8unfPLg 9B3pRxf2/YWMtAPfiTveGLhDF/Y9gOUYUTbGpGlVwxRaMfC9VQOnC5GbtFuQ3m/+BRpR ZHcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PzO6ycnY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e66-v6si11956951plb.499.2018.04.23.21.55.04; Mon, 23 Apr 2018 21:55:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PzO6ycnY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755900AbeDXEs6 (ORCPT + 99 others); Tue, 24 Apr 2018 00:48:58 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:39507 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751492AbeDXEs4 (ORCPT ); Tue, 24 Apr 2018 00:48:56 -0400 Received: by mail-pf0-f193.google.com with SMTP id z9so11203559pfe.6; Mon, 23 Apr 2018 21:48:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=f0WDbUWyWUY4pixtq78Efq/RSe+g3NjOSUdppJWV/WI=; b=PzO6ycnYG01gQw1CI12qJ9t3WkTCrEIHnrHCxRxXwoS1RYydKsGma+kXLwxKBkZE7U Tez5ACixtxFYnNjl6yzzXG7n3Elp+jIGrZpZNDV4Odtv8i4nQQTi491ZCKJdM8nOQgVi MUuThZRitowYrd9UEunXJjxe3XKMsXOO87cgF58a2SaOJYD5SMxnm3yd3bKfjrFUke9C 2sTIxC1zOoNqAM+LOefwTN6pr49wkbNRVLAkvlyaw/BmR1HetbgQJeAnuivSf+vedgRI Jl3zs9cTYj7G+5FX67Gg63ymwwv6N0ilNoUbbNOQIZJEvNX+gCckYlVXDQhglaZqdwaE 3ENA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=f0WDbUWyWUY4pixtq78Efq/RSe+g3NjOSUdppJWV/WI=; b=XXWklXxCejkFWslWg1uM2hYcQpVgNdKeYKa4PitC2oldX3Pf6DPiGVoMszNflab5i0 PtEoqkfT2KGA+udYzev3AKLQ9/s/TNk9jI5uhtwpAQ4N1BKxhisp9CKGKVkJPzWebgkN YyE5aMQkLJ8nTkdreHfXYZ5vHmS9EZkGpH1mhTeDF2hYXP0KA4/FFZ0U3oMgAeKhCRtU sPcGrRKIvXuecwRj9zzFBCZ2LC27yiRIeCN6AYlXxgOGKCvdEqe1XuhtAtlEfbq6eNdV Az5pOU12kdrRZ+mURR34KM5evTjl9fI/BxTFznQohRN9+T171fbAJuR1vHIeD3hybr4e Kukw== X-Gm-Message-State: ALQs6tA7Kk0ElDWtVBYFC5StXPaL2pob08Yv+u6Fg0wpnfcD3/P93xV4 BnlaDrKBYfkjydVUMHB7AYTaZ2r3 X-Received: by 10.98.2.72 with SMTP id 69mr22488660pfc.12.1524545336075; Mon, 23 Apr 2018 21:48:56 -0700 (PDT) Received: from sol.localdomain (c-67-185-97-198.hsd1.wa.comcast.net. [67.185.97.198]) by smtp.gmail.com with ESMTPSA id o64sm25377508pfb.62.2018.04.23.21.48.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Apr 2018 21:48:55 -0700 (PDT) Date: Mon, 23 Apr 2018 21:50:15 -0700 From: Eric Biggers To: Tycho Andersen Cc: David Howells , keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, James Morris , "Serge E. Hallyn" , "Jason A . Donenfeld" Subject: Re: [PATCH 1/3] big key: get rid of stack array allocation Message-ID: <20180424045015.GA4281@sol.localdomain> References: <20180424010321.14739-1-tycho@tycho.ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180424010321.14739-1-tycho@tycho.ws> User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Tycho, On Mon, Apr 23, 2018 at 07:03:19PM -0600, Tycho Andersen wrote: > We're interested in getting rid of all of the stack allocated arrays in the > kernel [1]. This patch simply hardcodes the iv length to match that of the > hardcoded cipher. > > [1]: https://lkml.org/lkml/2018/3/7/621 > > v2: hardcode the length of the nonce to be the GCM AES IV length, and do a > sanity check in init(), Eric Biggers > > Signed-off-by: Tycho Andersen > CC: David Howells > CC: James Morris > CC: "Serge E. Hallyn" > CC: Jason A. Donenfeld > CC: Eric Biggers > --- > security/keys/big_key.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/security/keys/big_key.c b/security/keys/big_key.c > index 933623784ccd..75c46786a166 100644 > --- a/security/keys/big_key.c > +++ b/security/keys/big_key.c > @@ -22,6 +22,7 @@ > #include > #include > #include > +#include > > struct big_key_buf { > unsigned int nr_pages; > @@ -109,7 +110,7 @@ static int big_key_crypt(enum big_key_op op, struct big_key_buf *buf, size_t dat > * an .update function, so there's no chance we'll wind up reusing the > * key to encrypt updated data. Simply put: one key, one encryption. > */ > - u8 zero_nonce[crypto_aead_ivsize(big_key_aead)]; > + u8 zero_nonce[GCM_AES_IV_SIZE]; > > aead_req = aead_request_alloc(big_key_aead, GFP_KERNEL); > if (!aead_req) > @@ -425,6 +426,12 @@ static int __init big_key_init(void) > pr_err("Can't alloc crypto: %d\n", ret); > return ret; > } > + > + if (unlikely(crypto_aead_ivsize(big_key_aead) != GCM_AES_IV_SIZE)) { > + WARN(1, "big key algorithm changed?"); > + return -EINVAL; > + } > + 'big_key_aead' needs to be freed on error. err = -EINVAL; goto free_aead; Also how about defining the IV size next to the algorithm name? Then all the algorithm details would be on adjacent lines: static const char big_key_alg_name[] = "gcm(aes)"; #define BIG_KEY_IV_SIZE GCM_AES_IV_SIZE - Eric