History

ima: Set file->f_mode instead of file->f_flags in ima_calc_file_hash()

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.

Roberto Sassu committed 6 years ago

Commit 0014cc01 parent ae83d0b1 file · +6 −6Browse files

Unified · Split

security/integrity/ima/ima_crypto.c+6−6
@@ -411,7 +411,7 @@ int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash) · 410 unmodified lines
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) · 13 unmodified lines
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) · 11 unmodified lines
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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t