Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751535AbdFHAbY (ORCPT ); Wed, 7 Jun 2017 20:31:24 -0400 Received: from imap.thunk.org ([74.207.234.97]:57512 "EHLO imap.thunk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751049AbdFHAbX (ORCPT ); Wed, 7 Jun 2017 20:31:23 -0400 Date: Wed, 7 Jun 2017 20:31:16 -0400 From: "Theodore Ts'o" To: "Jason A. Donenfeld" Cc: Linux Crypto Mailing List , LKML , kernel-hardening@lists.openwall.com, Greg Kroah-Hartman , David Miller , Eric Biggers , David Howells , Mimi Zohar , David Safford Subject: Re: [PATCH v4 04/13] security/keys: ensure RNG is seeded before use Message-ID: <20170608003116.zgznzb37ms7wj4vl@thunk.org> Mail-Followup-To: Theodore Ts'o , "Jason A. Donenfeld" , Linux Crypto Mailing List , LKML , kernel-hardening@lists.openwall.com, Greg Kroah-Hartman , David Miller , Eric Biggers , David Howells , Mimi Zohar , David Safford References: <20170606174804.31124-1-Jason@zx2c4.com> <20170606174804.31124-5-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170606174804.31124-5-Jason@zx2c4.com> User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: tytso@thunk.org X-SA-Exim-Scanned: No (on imap.thunk.org); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1365 Lines: 38 On Tue, Jun 06, 2017 at 07:47:55PM +0200, Jason A. Donenfeld wrote: > -static inline void key_alloc_serial(struct key *key) > +static inline int key_alloc_serial(struct key *key) > @@ -170,7 +168,7 @@ static inline void key_alloc_serial(struct key *key) > rb_insert_color(&key->serial_node, &key_serial_tree); > > spin_unlock(&key_serial_lock); > - return; > + return 0; > > /* we found a key with the proposed serial number - walk the tree from > * that point looking for the next unused serial number */ > @@ -314,7 +312,9 @@ struct key *key_alloc(struct key_type *type, const char *desc, > > /* publish the key by giving it a serial number */ > atomic_inc(&user->nkeys); > - key_alloc_serial(key); > + ret = key_alloc_serial(key); > + if (ret < 0) > + goto security_error; > > error: > return key; I'm guessing you changed key_alloc_serial() to return an int back when you were thinking that you might use get_random_bytes_wait(), which could return -ERESTARTSYS. Now that you're not doing this, but using get_random_u32() instead, there's no point to change the function signature of key_alloc_serial() and add an error check in key_alloc() that will never fail, right? That's just adding a dead code path. Which the compiler can probably optimize away, but why make the code slightly harder to read than necessasry? - Ted