Message ID | 20030809011116.GB10487@gondor.apana.org.au |
---|---|
State | New, archived |
Headers | show |
Series |
|
Related | show |
On Sat, 9 Aug 2003, Herbert Xu wrote: > Hi: > > The unshare_files patch to flush_old_exec() did not restore the original > state when exec_mmap fails. This patch fixes that. Indeed. This is still needed. > At this point, I believe the unshare_files stuff should be fine from > a correctness point of view. However, there is still a performance > problem as every ELF exec call ends up dupliating the files structure > as well as walking through all file locks. Cheers, Andreas. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
On Sat, Aug 09, 2003 at 11:11:16AM +1000, herbert wrote: > > At this point, I believe the unshare_files stuff should be fine from > a correctness point of view. However, there is still a performance > problem as every ELF exec call ends up dupliating the files structure > as well as walking through all file locks. Here is the patch that ensures files is only duplicated when necessary.
On Sat, 9 Aug 2003, Herbert Xu wrote: > On Sat, Aug 09, 2003 at 11:11:16AM +1000, herbert wrote: > > > > At this point, I believe the unshare_files stuff should be fine from > > a correctness point of view. However, there is still a performance > > problem as every ELF exec call ends up dupliating the files structure > > as well as walking through all file locks. > > Here is the patch that ensures files is only duplicated when necessary. This patch is correct but unnecessary: steal_locks already tests for this condition. Cheers, Andreas. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
On Sat, Aug 09, 2003 at 04:20:38AM +0200, Andreas Gruenbacher wrote: > On Sat, 9 Aug 2003, Herbert Xu wrote: > > > On Sat, Aug 09, 2003 at 11:11:16AM +1000, herbert wrote: > > > > > > At this point, I believe the unshare_files stuff should be fine from > > > a correctness point of view. However, there is still a performance > > > problem as every ELF exec call ends up dupliating the files structure > > > as well as walking through all file locks. > > > > Here is the patch that ensures files is only duplicated when necessary. > > This patch is correct but unnecessary: steal_locks already tests for this > condition. Yes but when you call unshare_files twice one of them will have to copy.
On Sat, 9 Aug 2003, Herbert Xu wrote: > On Sat, Aug 09, 2003 at 04:20:38AM +0200, Andreas Gruenbacher wrote: > > On Sat, 9 Aug 2003, Herbert Xu wrote: > > > > > On Sat, Aug 09, 2003 at 11:11:16AM +1000, herbert wrote: > > > > > > > > At this point, I believe the unshare_files stuff should be fine from > > > > a correctness point of view. However, there is still a performance > > > > problem as every ELF exec call ends up dupliating the files structure > > > > as well as walking through all file locks. > > > > > > Here is the patch that ensures files is only duplicated when necessary. > > > > This patch is correct but unnecessary: steal_locks already tests for this > > condition. > > Yes but when you call unshare_files twice one of them will have to > copy. I see---that happens through flush_old_exec. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Here is an update ... > On Sat, 9 Aug 2003, Herbert Xu wrote: > > Yes but when you call unshare_files twice one of them will have to > > copy. Index: linux-2.4.22-rc2.orig/fs/exec.c =================================================================== --- linux-2.4.22-rc2.orig.orig/fs/exec.c 2003-08-09 04:44:07.000000000 +0200 +++ linux-2.4.22-rc2.orig/fs/exec.c 2003-08-09 05:04:35.000000000 +0200 @@ -582,8 +582,6 @@ int flush_old_exec(struct linux_binprm * retval = unshare_files(); if(retval) goto flush_failed; - steal_locks(files, current->files); - put_files_struct(files); /* * Release all of the old mmap stuff @@ -592,6 +590,8 @@ int flush_old_exec(struct linux_binprm * if (retval) goto mmap_failed; /* This is the point of no return */ + steal_locks(files); + put_files_struct(files); release_old_signals(oldsig); current->sas_ss_sp = current->sas_ss_size = 0; @@ -629,6 +629,8 @@ int flush_old_exec(struct linux_binprm * return 0; mmap_failed: + put_files_struct(current->files); + current->files = files; flush_failed: spin_lock_irq(¤t->sigmask_lock); if (current->sig != oldsig) { Index: linux-2.4.22-rc2.orig/include/linux/fs.h =================================================================== --- linux-2.4.22-rc2.orig.orig/include/linux/fs.h 2003-08-09 04:44:07.000000000 +0200 +++ linux-2.4.22-rc2.orig/include/linux/fs.h 2003-08-09 05:04:35.000000000 +0200 @@ -674,7 +674,7 @@ extern int __get_lease(struct inode *ino extern time_t lease_get_mtime(struct inode *); extern int lock_may_read(struct inode *, loff_t start, unsigned long count); extern int lock_may_write(struct inode *, loff_t start, unsigned long count); -extern void steal_locks(fl_owner_t from, fl_owner_t to); +extern void steal_locks(fl_owner_t from); struct fasync_struct { int magic; Index: linux-2.4.22-rc2.orig/fs/binfmt_elf.c =================================================================== --- linux-2.4.22-rc2.orig.orig/fs/binfmt_elf.c 2003-08-09 04:44:07.000000000 +0200 +++ linux-2.4.22-rc2.orig/fs/binfmt_elf.c 2003-08-09 05:06:05.000000000 +0200 @@ -444,7 +444,7 @@ static int load_elf_binary(struct linux_ struct elfhdr interp_elf_ex; struct exec interp_ex; char passed_fileno[6]; - struct files_struct *files, *ftmp; + struct files_struct *files; /* Get the exec-header */ elf_ex = *((struct elfhdr *) bprm->buf); @@ -480,7 +480,10 @@ static int load_elf_binary(struct linux_ files = current->files; /* Refcounted so ok */ if(unshare_files() < 0) goto out_free_ph; - steal_locks(files, current->files); + if (files == current->files) { + put_files_struct(files); + files = NULL; + } /* exec will make our files private anyway, but for the a.out loader stuff we need to do it earlier */ @@ -603,7 +606,11 @@ static int load_elf_binary(struct linux_ goto out_free_dentry; /* Discard our unneeded old files struct */ - put_files_struct(files); + if (files) { + steal_locks(files); + put_files_struct(files); + files = NULL; + } /* OK, This is the point of no return */ current->mm->start_data = 0; @@ -714,18 +721,16 @@ static int load_elf_binary(struct linux_ elf_entry = load_elf_interp(&interp_elf_ex, interpreter, &interp_load_addr); - - allow_write_access(interpreter); - fput(interpreter); - kfree(elf_interpreter); - if (BAD_ADDR(elf_entry)) { printk(KERN_ERR "Unable to load interpreter\n"); - kfree(elf_phdata); send_sig(SIGSEGV, current, 0); retval = -ENOEXEC; /* Nobody gets to see this, but.. */ - goto out; + goto out_free_dentry; } + + allow_write_access(interpreter); + fput(interpreter); + kfree(elf_interpreter); } kfree(elf_phdata); @@ -811,10 +816,10 @@ out_free_interp: out_free_file: sys_close(elf_exec_fileno); out_free_fh: - ftmp = current->files; - current->files = files; - steal_locks(ftmp, current->files); - put_files_struct(ftmp); + if (files) { + put_files_struct(current->files); + current->files = files; + } out_free_ph: kfree(elf_phdata); goto out; Index: linux-2.4.22-rc2.orig/fs/locks.c =================================================================== --- linux-2.4.22-rc2.orig.orig/fs/locks.c 2003-08-09 04:44:07.000000000 +0200 +++ linux-2.4.22-rc2.orig/fs/locks.c 2003-08-09 05:04:35.000000000 +0200 @@ -1937,11 +1937,11 @@ done: return length; } -void steal_locks(fl_owner_t from, fl_owner_t to) +void steal_locks(fl_owner_t from) { struct list_head *tmp; - if (from == to) + if (from == current->files) return; lock_kernel(); @@ -1949,7 +1949,7 @@ void steal_locks(fl_owner_t from, fl_own struct file_lock *fl = list_entry(tmp, struct file_lock, fl_link); if (fl->fl_owner == from) - fl->fl_owner = to; + fl->fl_owner = current->files; } unlock_kernel(); }
Hi, On Sat, 2003-08-09 at 12:05, Herbert Xu wrote: > On Sat, Aug 09, 2003 at 05:54:32AM +0200, Andreas Gruenbacher wrote: > > On Sat, 9 Aug 2003, Andreas Gruenbacher wrote: > > > > > Here is an update ... > > Do you agree that this is correct? > > It looks OK to me. However, I still think the BAD_ADDR change is > unnecessary. Very good, thanks. The BAD_ADDR change is indeed not required. It saves a funtion call so I think we should keep it, but I don't mind so much. Cheers,
Index: kernel-source-2.4/fs/exec.c =================================================================== RCS file: /home/gondolin/herbert/src/CVS/debian/kernel-source-2.4/fs/exec.c,v retrieving revision 1.5 diff -u -r1.5 exec.c --- kernel-source-2.4/fs/exec.c 26 Jul 2003 02:54:45 -0000 1.5 +++ kernel-source-2.4/fs/exec.c 9 Aug 2003 01:00:28 -0000 @@ -557,7 +557,7 @@ char * name; int i, ch, retval; struct signal_struct * oldsig; - struct files_struct * files; + struct files_struct *files, *ftmp; /* * Make sure we have a private signal table @@ -576,8 +576,6 @@ retval = unshare_files(); if(retval) goto flush_failed; - steal_locks(files, current->files); - put_files_struct(files); /* * Release all of the old mmap stuff @@ -586,6 +584,8 @@ if (retval) goto mmap_failed; /* This is the point of no return */ + steal_locks(files, current->files); + put_files_struct(files); release_old_signals(oldsig); current->sas_ss_sp = current->sas_ss_size = 0; @@ -623,6 +623,9 @@ return 0; mmap_failed: + ftmp = current->files; + current->files = files; + put_files_struct(ftmp); flush_failed: spin_lock_irq(¤t->sigmask_lock); if (current->sig != oldsig) {