coredump - as root not only if euid switched
Subsystems (3)
Quoted 8 lines · Andrew Morton
Quoted 6 lines · Peter Waechtler
But I agree that
sys_unlinkshould be the fast call and dumping core is the exception :)would fastcall
do_unlink()help? I guess the arg is then passed in a register
Quoted 8 lines
I've never been able to measure any size or space benefit for fastcall, and we do it via compiler options kernel-wide nowadays.
The above will work fine. You can probably just open-code it at the place where you're unlinking the file.
(why are you trying to unlink the old file anyway?)
For security measure :O
I tried on solaris: touch the core file as user, open it and wait, dump core as root -> nope, couldn't read the damn core - it was unlinked and created! So do I want.
I will sent the new patch from home.
Quoted 7 lines · Peter Waechtler
Quoted 3 lines
(why are you trying to unlink the old file anyway?)
For security measure :O
I tried on solaris: touch the core file as user, open it and wait, dump core as root -> nope, couldn't read the damn core - it was unlinked and created!
hm, OK. There's a window in which someone can come in and recreate the file, but the open is using O_EXCL|O_CREATE so that seems safe enough.
Am Do, 2004-04-22 um 11.56 schrieb Andrew Morton:
Quoted 11 lines
Quoted 7 lines · Peter Waechtler
Quoted 3 lines
(why are you trying to unlink the old file anyway?)
For security measure :O
I tried on solaris: touch the core file as user, open it and wait, dump core as root -> nope, couldn't read the damn core - it was unlinked and created!hm, OK. There's a window in which someone can come in and recreate the file, but the open is using O_EXCL|O_CREATE so that seems safe enough.
So here is the updated patch with an open coded call to sys_unlink
fs/exec.c +21 -3
@@ -1378,6 +1378,10 @@ goto fail; } mm->dumpable =0 ; +if (mm->dump_as_root){ + current->fsuid =0 ; + current->fsgid =0 ; + }init_completion (&mm->core_done); current->signal->group_exit =1 ; current->signal->group_exit_code = exit_code;
@@ -1387,9 +1391,23 @@ goto fail_unlock;format_corename (corename, core_pattern, signr); - file =filp_open (corename,O_CREAT |2 |O_NOFOLLOW |O_LARGEFILE ,0600 ); -if (IS_ERR (file)) - goto fail_unlock; + file =filp_open (corename,O_CREAT |O_EXCL |2 |O_NOFOLLOW |O_LARGEFILE ,0600 ); +if (IS_ERR (file)){ +long error; +mm_segment_t old_fs =get_fs (); + +set_fs (KERNEL_DS ); + error =sys_unlink (corename); +set_fs (old_fs); +if (error) + goto fail_unlock; + file =filp_open (corename,O_CREAT |O_EXCL |2 |O_NOFOLLOW |O_LARGEFILE ,0600 ); +if (IS_ERR (file)){ +printk (KERN_WARNING "pid %d doesn't dump core to %s because of creation race\n" , + current->pid, corename); + goto fail_unlock; + } + } inode = file->f_dentry->d_inode;if (inode->i_nlink >1 ) goto close_fail;/* multiple links - don't dump */
include/linux/sched.h +1 -0
@@ -211,6 +211,7 @@unsigned long saved_auxv[40 ];/* for /proc/PID/auxv */ unsigned dumpable:1; + unsigned dump_as_root:1;#ifdef CONFIG_HUGETLB_PAGE int used_hugetlb;#endif
kernel/sys.c +10 -10
@@ -573,7 +573,7 @@ }if (new_egid != old_egid) { - current->mm->dumpable =0 ; + current->mm->dump_as_root =1 ;wmb (); } if (rgid != (gid_t) -1 ||
@@ -603,7 +603,7 @@ {if (old_egid != gid) { - current->mm->dumpable=0 ; + current->mm->dump_as_root =1 ;wmb (); } current->gid = current->egid = current->sgid = current->fsgid = gid;
@@ -612,7 +612,7 @@ {if (old_egid != gid) { - current->mm->dumpable=0 ; + current->mm->dump_as_root =1 ;wmb (); } current->egid = current->fsgid = gid;
@@ -641,7 +641,7 @@if (dumpclear) { - current->mm->dumpable =0 ; + current->mm->dump_as_root =1 ;wmb (); } current->uid = new_ruid;
@@ -698,7 +698,7 @@if (new_euid != old_euid) { - current->mm->dumpable=0 ; + current->mm->dump_as_root =1 ;wmb (); } current->fsuid = current->euid = new_euid;
@@ -746,7 +746,7 @@if (old_euid != uid) { - current->mm->dumpable =0 ; + current->mm->dump_as_root =1 ;wmb (); } current->fsuid = current->euid = uid;
@@ -789,7 +789,7 @@if (euid != (uid_t) -1 ) {if (euid != current->euid) { - current->mm->dumpable =0 ; + current->mm->dump_as_root =1 ;wmb (); } current->euid = euid;
@@ -837,7 +837,7 @@if (egid != (gid_t) -1 ) {if (egid != current->egid) { - current->mm->dumpable =0 ; + current->mm->dump_as_root =1 ;wmb (); } current->egid = egid;
@@ -882,7 +882,7 @@ {if (uid != old_fsuid) { - current->mm->dumpable =0 ; + current->mm->dump_as_root =1 ;wmb (); } current->fsuid = uid;
@@ -910,7 +910,7 @@ {if (gid != old_fsgid) { - current->mm->dumpable =0 ; + current->mm->dump_as_root =1 ;wmb (); } current->fsgid = gid;
Quoted 6 lines · * Peter Wächtler ([email protected]) wrote:
Am Do, 2004-04-22 um 11.56 schrieb Andrew Morton:
Quoted 5 lines
Quoted 4 lines · Peter Waechtler
Quoted 3 lines
(why are you trying to unlink the old file anyway?)
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
For security measure :O
I tried on solaris: touch the core file as user, open it and wait, dump core as root -> nope, couldn't read the damn core - it was unlinked and created!hm, OK. There's a window in which someone can come in and recreate the file, but the open is using O_EXCL|O_CREATE so that seems safe enough.
So here is the updated patch with an open coded call to
sys_unlink
This patch breaks various ptrace() checks.
thanks,
-chris
Signature · 1 line
Linux Security Modules http://lsm.immunix.org http://lsm.bkbits.net
Quoted 5 lines · Peter Wächtler
Quoted 3 lines
hm, OK. There's a window in which someone can come in and recreate the file, but the open is using O_EXCL|O_CREATE so that seems safe enough.
So here is the updated patch with an open coded call to
sys_unlink
Aughr.
Wouldn't it be much nicer to just refuse to overwrite files owned by anybody else?
In other words, I'd much rather see a patch that is a much simpler one, which just says: if we opened an existing file, we won't touch it if we weren't the owners of it.
That should be safe for root _and_ it should be safe for people who already had a file descriptor open previously (hey, if the previous root-owned core-file was world readable, then what else is new?)
Tell me why this isn't simpler?
Linus
---
fs/exec.c +2 -0
@@ -1378,6 +1378,8 @@ inode = file->f_dentry->d_inode;if (inode->i_nlink >1 ) goto close_fail;/* multiple links - don't dump */ +if (inode->i_uid != current->euid || inode->i_gid != current->egid) + goto close_fail;if (d_unhashed (file->f_dentry)) goto close_fail;