Skip to content

Commit 40f705a

Browse files
thejhtorvalds
authored andcommitted
fs: Don't dump core if the corefile would become world-readable.
On a filesystem like vfat, all files are created with the same owner and mode independent of who created the file. When a vfat filesystem is mounted with root as owner of all files and read access for everyone, root's processes left world-readable coredumps on it (but other users' processes only left empty corefiles when given write access because of the uid mismatch). Given that the old behavior was inconsistent and insecure, I don't see a problem with changing it. Now, all processes refuse to dump core unless the resulting corefile will only be readable by their owner. Signed-off-by: Jann Horn <jann@thejh.net> Acked-by: Kees Cook <keescook@chromium.org> Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent fbb1816 commit 40f705a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

fs/coredump.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,11 +685,15 @@ void do_coredump(const siginfo_t *siginfo)
685685
if (!S_ISREG(inode->i_mode))
686686
goto close_fail;
687687
/*
688-
* Dont allow local users get cute and trick others to coredump
689-
* into their pre-created files.
688+
* Don't dump core if the filesystem changed owner or mode
689+
* of the file during file creation. This is an issue when
690+
* a process dumps core while its cwd is e.g. on a vfat
691+
* filesystem.
690692
*/
691693
if (!uid_eq(inode->i_uid, current_fsuid()))
692694
goto close_fail;
695+
if ((inode->i_mode & 0677) != 0600)
696+
goto close_fail;
693697
if (!(cprm.file->f_mode & FMODE_CAN_WRITE))
694698
goto close_fail;
695699
if (do_truncate(cprm.file->f_path.dentry, 0, 0, cprm.file))

0 commit comments

Comments
 (0)