linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] IMA: Mask O_RDWR if FMODE_READ is set
@ 2018-11-26 16:38 Goldwyn Rodrigues
  2018-11-27 12:05 ` Mimi Zohar
  0 siblings, 1 reply; 4+ messages in thread
From: Goldwyn Rodrigues @ 2018-11-26 16:38 UTC (permalink / raw)
  To: syzbot+ae82084b07d0297e566b
  Cc: Mimi Zohar, syzkaller-bugs, linux-integrity, linux-unionfs,
	amir73il

A file can be opened with open(O_WRONLY | O_RDWR), so a FMORE_READ
will not be set, and overlayfs will consider another copy_up() on the same
file leading to a deadlock on mnt_want_write(). Fix it by masking
O_RDWR while opening the file in read-only mode.


Reported-by: syzbot+ae82084b07d0297e566b@syzkaller.appspotmail.com
Fixes: a408e4a86b36 ("ima: open a new file instance if no read permissions")
Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>

diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c
index d9e7728027c6..2efa04e47ff0 100644
--- a/security/integrity/ima/ima_crypto.c
+++ b/security/integrity/ima/ima_crypto.c
@@ -422,7 +422,7 @@ int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash)
 	/* Open a new file instance in O_RDONLY if we cannot read */
 	if (!(file->f_mode & FMODE_READ)) {
 		int flags = file->f_flags & ~(O_WRONLY | O_APPEND |
-				O_TRUNC | O_CREAT | O_NOCTTY | O_EXCL);
+				O_RDWR | O_TRUNC | O_CREAT | O_NOCTTY | O_EXCL);
 		flags |= O_RDONLY;
 		f = dentry_open(&file->f_path, flags, file->f_cred);
 		if (IS_ERR(f)) {

-- 
Goldwyn

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-11-27 14:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-26 16:38 [PATCH] IMA: Mask O_RDWR if FMODE_READ is set Goldwyn Rodrigues
2018-11-27 12:05 ` Mimi Zohar
2018-11-27 14:06   ` Amir Goldstein
2018-11-27 14:14     ` Dmitry Vyukov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).