Skip to content

Commit

Permalink
ima: fix error handling logic when file measurement failed
Browse files Browse the repository at this point in the history
Restore the error handling logic so that when file measurement fails,
the respective iint entry is not left with the digest data being
populated with zeroes.

Fixes: 54f0391 ("ima: permit fsverity's file digests in the IMA measurement list")
Cc: stable@vger.kernel.org	# 5.19
Signed-off-by: Matt Bobrowski <mattbobrowski@google.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
  • Loading branch information
Matt Bobrowski authored and Mimi Zohar committed Jan 18, 2023
1 parent 5dc4c99 commit 6dc387d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion security/integrity/ima/ima_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ int ima_collect_measurement(struct integrity_iint_cache *iint,
result = ima_calc_file_hash(file, &hash.hdr);
}

if (result == -ENOMEM)
if (result && result != -EBADF && result != -EINVAL)
goto out;

length = sizeof(hash.hdr) + hash.hdr.length;
Expand Down
2 changes: 1 addition & 1 deletion security/integrity/ima/ima_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ static int process_measurement(struct file *file, const struct cred *cred,
hash_algo = ima_get_hash_algo(xattr_value, xattr_len);

rc = ima_collect_measurement(iint, file, buf, size, hash_algo, modsig);
if (rc == -ENOMEM)
if (rc != 0 && rc != -EBADF && rc != -EINVAL)
goto out_locked;

if (!pathbuf) /* ima_rdwr_violation possibly pre-fetched */
Expand Down

0 comments on commit 6dc387d

Please sign in to comment.