Skip to content

Commit 0014cc0

Browse files
robertosassumimizohar
authored andcommitted
ima: Set file->f_mode instead of file->f_flags in ima_calc_file_hash()
Commit a408e4a ("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: [email protected] # 4.20.x Fixes: a408e4a ("ima: open a new file instance if no read permissions") Signed-off-by: Roberto Sassu <[email protected]> Reviewed-by: Goldwyn Rodrigues <[email protected]> Signed-off-by: Mimi Zohar <[email protected]>
1 parent ae83d0b commit 0014cc0

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

security/integrity/ima/ima_crypto.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash)
411411
loff_t i_size;
412412
int rc;
413413
struct file *f = file;
414-
bool new_file_instance = false, modified_flags = false;
414+
bool new_file_instance = false, modified_mode = false;
415415

416416
/*
417417
* For consistency, fail file's opened with the O_DIRECT flag on
@@ -431,13 +431,13 @@ int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash)
431431
f = dentry_open(&file->f_path, flags, file->f_cred);
432432
if (IS_ERR(f)) {
433433
/*
434-
* Cannot open the file again, lets modify f_flags
434+
* Cannot open the file again, lets modify f_mode
435435
* of original and continue
436436
*/
437437
pr_info_ratelimited("Unable to reopen file for reading.\n");
438438
f = file;
439-
f->f_flags |= FMODE_READ;
440-
modified_flags = true;
439+
f->f_mode |= FMODE_READ;
440+
modified_mode = true;
441441
} else {
442442
new_file_instance = true;
443443
}
@@ -455,8 +455,8 @@ int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash)
455455
out:
456456
if (new_file_instance)
457457
fput(f);
458-
else if (modified_flags)
459-
f->f_flags &= ~FMODE_READ;
458+
else if (modified_mode)
459+
f->f_mode &= ~FMODE_READ;
460460
return rc;
461461
}
462462

0 commit comments

Comments
 (0)