From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jarkko Sakkinen Date: Thu, 23 Jul 2020 01:32:35 +0000 Subject: Re: [PATCH] keys: asymmetric: fix error return code in software_key_query() Message-Id: <20200723013223.GA45081@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit List-Id: References: <159485211858.2340757.9890754969922775496.stgit@warthog.procyon.org.uk> In-Reply-To: <159485211858.2340757.9890754969922775496.stgit@warthog.procyon.org.uk> To: David Howells Cc: torvalds@linux-foundation.org, Wei Yongjun , keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org On Wed, Jul 15, 2020 at 11:28:38PM +0100, David Howells wrote: > From: Wei Yongjun > > Fix to return negative error code -ENOMEM from kmalloc() error handling > case instead of 0, as done elsewhere in this function. > > Fixes: f1774cb8956a ("X.509: parse public key parameters from x509 for akcipher") > Signed-off-by: Wei Yongjun > Signed-off-by: David Howells Why f1774cb8956a lacked any possible testing? It extends ABI anyway. I think it is a kind of change that would require more screening before getting applied. > --- > > crypto/asymmetric_keys/public_key.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c > index d7f43d4ea925..e5fae4e838c0 100644 > --- a/crypto/asymmetric_keys/public_key.c > +++ b/crypto/asymmetric_keys/public_key.c > @@ -119,6 +119,7 @@ static int software_key_query(const struct kernel_pkey_params *params, > if (IS_ERR(tfm)) > return PTR_ERR(tfm); > > + ret = -ENOMEM; This is extremely confusing to read way to handle 'ret'. Would be way more cleaner to be just simple and stupid: if (!key) { ret = -ENOMEM; goto error_free_tfm; } > key = kmalloc(pkey->keylen + sizeof(u32) * 2 + pkey->paramlen, > GFP_KERNEL); > if (!key) /Jarkko