ima: Set file->f_mode instead of file->f_flags in ima_calc_file_hash()
authorRoberto Sassu <roberto.sassu@huawei.com>
Mon, 27 Apr 2020 10:28:55 +0000 (12:28 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 27 May 2020 14:42:50 +0000 (16:42 +0200)
commit7bc138000e3be603190af6641f04f4f91011fe95
treeca450c1acc5099a91eb38688753db09f8d4ae9b5
parent0a9ac7ce3927b135390faaa27398d5932a70c3b7
ima: Set file->f_mode instead of file->f_flags in ima_calc_file_hash()

[ Upstream commit 0014cc04e8ec077dc482f00c87dfd949cfe2b98f ]

Commit a408e4a86b36 ("ima: open a new file instance if no read
permissions") tries to create a new file descriptor to calculate a file
digest if the file has not been opened with O_RDONLY flag. However, if a
new file descriptor cannot be obtained, it sets the FMODE_READ flag to
file->f_flags instead of file->f_mode.

This patch fixes this issue by replacing f_flags with f_mode as it was
before that commit.

Cc: stable@vger.kernel.org # 4.20.x
Fixes: a408e4a86b36 ("ima: open a new file instance if no read permissions")
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
security/integrity/ima/ima_crypto.c