evm: Fix a small race in init_desc()
authorDan Carpenter <dan.carpenter@oracle.com>
Tue, 12 May 2020 13:19:17 +0000 (16:19 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 27 May 2020 15:46:17 +0000 (17:46 +0200)
commitdd540f2d7c2d7f34b00161fce00f1e05a352f4f3
tree7db35cea873810e4bbbb0847fabb557ed5f5cd73
parentf96ab0d1f3ec59f5e608a0869d9169ae0a53971d
evm: Fix a small race in init_desc()

[ Upstream commit 8433856947217ebb5697a8ff9c4c9cad4639a2cf ]

The IS_ERR_OR_NULL() function has two conditions and if we got really
unlucky we could hit a race where "ptr" started as an error pointer and
then was set to NULL.  Both conditions would be false even though the
pointer at the end was NULL.

This patch fixes the problem by ensuring that "*tfm" can only be NULL
or valid.  I have introduced a "tmp_tfm" variable to make that work.  I
also reversed a condition and pulled the code in one tab.

Reported-by: Roberto Sassu <roberto.sassu@huawei.com>
Fixes: 53de3b080d5e ("evm: Check also if *tfm is an error pointer in init_desc()")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Roberto Sassu <roberto.sassu@huawei.com>
Acked-by: Krzysztof Struczynski <krzysztof.struczynski@huawei.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
security/integrity/evm/evm_crypto.c