* bug report: mem_write @ 2006-08-24 8:25 Amnon Shiloh 2006-08-24 10:35 ` Gerard J Snitselaar 2006-08-24 14:00 ` [2.6.18 patch] fix mem_write return value (was: Re: bug report: mem_write) Frederik Deweerdt 0 siblings, 2 replies; 6+ messages in thread From: Amnon Shiloh @ 2006-08-24 8:25 UTC (permalink / raw) To: linux-kernel Hi, Alright, I know that "mem_write" (fs/proc/base.c) is a "security hazard", but I need to use it anyway (as super-user only), and find it broken, somewhere between Linux-2.6.17 and Linux-2.6.18-rc4. The point is that in the beginning of the routine, "copied" is set to 0, but it is no good because in lines 805 and 812 it is set to other values. Finally, the routine returns as if it copied 12 (=ENOMEM) bytes less than it actually did. Amnon. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: bug report: mem_write 2006-08-24 8:25 bug report: mem_write Amnon Shiloh @ 2006-08-24 10:35 ` Gerard J Snitselaar 2006-08-24 14:00 ` [2.6.18 patch] fix mem_write return value (was: Re: bug report: mem_write) Frederik Deweerdt 1 sibling, 0 replies; 6+ messages in thread From: Gerard J Snitselaar @ 2006-08-24 10:35 UTC (permalink / raw) To: Amnon Shiloh; +Cc: linux-kernel On 0, Amnon Shiloh <amnons@cs.huji.ac.il> wrote: > Hi, > > Alright, I know that "mem_write" (fs/proc/base.c) is a "security hazard", > but I need to use it anyway (as super-user only), and find it broken, > somewhere between Linux-2.6.17 and Linux-2.6.18-rc4. > > The point is that in the beginning of the routine, "copied" is set to 0, > but it is no good because in lines 805 and 812 it is set to other values. > Finally, the routine returns as if it copied 12 (=ENOMEM) bytes less than > it actually did. > Is there any reason copied shouldn't get set to 0 just prior to entering the while loop? > Amnon. > > - > 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/ ^ permalink raw reply [flat|nested] 6+ messages in thread
* [2.6.18 patch] fix mem_write return value (was: Re: bug report: mem_write) 2006-08-24 8:25 bug report: mem_write Amnon Shiloh 2006-08-24 10:35 ` Gerard J Snitselaar @ 2006-08-24 14:00 ` Frederik Deweerdt 2006-08-24 16:33 ` Eric W. Biederman 1 sibling, 1 reply; 6+ messages in thread From: Frederik Deweerdt @ 2006-08-24 14:00 UTC (permalink / raw) To: Amnon Shiloh; +Cc: linux-kernel, ebiederm, akpm, gregkh On Thu, Aug 24, 2006 at 11:25:37AM +0300, Amnon Shiloh wrote: > Hi, > > Alright, I know that "mem_write" (fs/proc/base.c) is a "security hazard", > but I need to use it anyway (as super-user only), and find it broken, > somewhere between Linux-2.6.17 and Linux-2.6.18-rc4. > > The point is that in the beginning of the routine, "copied" is set to 0, > but it is no good because in lines 805 and 812 it is set to other values. > Finally, the routine returns as if it copied 12 (=ENOMEM) bytes less than > it actually did. True, it looks like the faulty commit is: de7587343bfebc186995ad294e3de0da382eb9bc http://www.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff_plain;h=99f895518368252ba862cc15ce4eb98ebbe1bec6;hp=8578cea7509cbdec25b31d08b48a92fcc3b1a9e3 The attached patch should fix it. Maybe that should go to 2.6.18. Thanks for the bug report, Frederik Signed-off-by: Frederik Deweerdt <frederik.deweerdt@gmail.com> --- fs/proc/base.c.orig 2006-08-24 13:57:22.000000000 +0200 +++ fs/proc/base.c 2006-08-24 13:57:10.000000000 +0200 @@ -797,7 +797,7 @@ static ssize_t mem_write(struct file * file, const char * buf, size_t count, loff_t *ppos) { - int copied = 0; + int copied; char *page; struct task_struct *task = get_proc_task(file->f_dentry->d_inode); unsigned long dst = *ppos; @@ -814,6 +814,7 @@ if (!page) goto out; + copied = 0; while (count > 0) { int this_len, retval; ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [2.6.18 patch] fix mem_write return value (was: Re: bug report: mem_write) 2006-08-24 14:00 ` [2.6.18 patch] fix mem_write return value (was: Re: bug report: mem_write) Frederik Deweerdt @ 2006-08-24 16:33 ` Eric W. Biederman 2006-08-24 22:07 ` Frederik Deweerdt 0 siblings, 1 reply; 6+ messages in thread From: Eric W. Biederman @ 2006-08-24 16:33 UTC (permalink / raw) To: Frederik Deweerdt; +Cc: Amnon Shiloh, linux-kernel, akpm, gregkh Frederik Deweerdt <deweerdt@free.fr> writes: > On Thu, Aug 24, 2006 at 11:25:37AM +0300, Amnon Shiloh wrote: >> Hi, >> >> Alright, I know that "mem_write" (fs/proc/base.c) is a "security hazard", >> but I need to use it anyway (as super-user only), and find it broken, >> somewhere between Linux-2.6.17 and Linux-2.6.18-rc4. >> >> The point is that in the beginning of the routine, "copied" is set to 0, >> but it is no good because in lines 805 and 812 it is set to other values. >> Finally, the routine returns as if it copied 12 (=ENOMEM) bytes less than >> it actually did. > True, it looks like the faulty commit is: > de7587343bfebc186995ad294e3de0da382eb9bc Actually it was: 99f895518368252ba862cc15ce4eb98ebbe1bec6 Which is what you url points to, odd. > http://www.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff_plain;h=99f895518368252ba862cc15ce4eb98ebbe1bec6;hp=8578cea7509cbdec25b31d08b48a92fcc3b1a9e3 > > The attached patch should fix it. Maybe that should go to 2.6.18. > Thanks for the bug report, The patch looks correct. Although this won't cause anyone problems as the code is disabled. Signed-off-by: Eric Biederman <ebiederm@xmission.com> As for enabling this. I believe we need an extra permission check just before we copy the data from our temporary buffer to the target task, to ensure nothing has changed. The history does not really capture why this code was disabled, but before this gets enabled I would like to understand more than just the comment. I believe with a little care this can be safely enabled as it doesn't let you do anything ptrace wouldn't do, and it should let you do it anytime except when ptrace would allow it. Thus not introducing any new security holes. > Frederik > > Signed-off-by: Frederik Deweerdt <frederik.deweerdt@gmail.com> > > --- fs/proc/base.c.orig 2006-08-24 13:57:22.000000000 +0200 > +++ fs/proc/base.c 2006-08-24 13:57:10.000000000 +0200 > @@ -797,7 +797,7 @@ > static ssize_t mem_write(struct file * file, const char * buf, > size_t count, loff_t *ppos) > { > - int copied = 0; > + int copied; > char *page; > struct task_struct *task = get_proc_task(file->f_dentry->d_inode); > unsigned long dst = *ppos; > @@ -814,6 +814,7 @@ > if (!page) > goto out; > > + copied = 0; > while (count > 0) { > int this_len, retval; > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [2.6.18 patch] fix mem_write return value (was: Re: bug report: mem_write) 2006-08-24 16:33 ` Eric W. Biederman @ 2006-08-24 22:07 ` Frederik Deweerdt 2006-08-25 1:05 ` Amnon Shiloh 0 siblings, 1 reply; 6+ messages in thread From: Frederik Deweerdt @ 2006-08-24 22:07 UTC (permalink / raw) To: Eric W. Biederman; +Cc: Amnon Shiloh, linux-kernel, akpm, gregkh On Thu, Aug 24, 2006 at 10:33:20AM -0600, Eric W. Biederman wrote: > Frederik Deweerdt <deweerdt@free.fr> writes: > > > On Thu, Aug 24, 2006 at 11:25:37AM +0300, Amnon Shiloh wrote: > >> Hi, > >> > >> Alright, I know that "mem_write" (fs/proc/base.c) is a "security hazard", > >> but I need to use it anyway (as super-user only), and find it broken, > >> somewhere between Linux-2.6.17 and Linux-2.6.18-rc4. > >> > >> The point is that in the beginning of the routine, "copied" is set to 0, > >> but it is no good because in lines 805 and 812 it is set to other values. > >> Finally, the routine returns as if it copied 12 (=ENOMEM) bytes less than > >> it actually did. > > True, it looks like the faulty commit is: > > de7587343bfebc186995ad294e3de0da382eb9bc > > Actually it was: 99f895518368252ba862cc15ce4eb98ebbe1bec6 > Which is what you url points to, odd. > > > http://www.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff_plain;h=99f895518368252ba862cc15ce4eb98ebbe1bec6;hp=8578cea7509cbdec25b31d08b48a92fcc3b1a9e3 > > > > The attached patch should fix it. Maybe that should go to 2.6.18. > > Thanks for the bug report, > > The patch looks correct. Although this won't cause anyone problems as the code > is disabled. Right, I missed this, so this is really not urgent. > > Signed-off-by: Eric Biederman <ebiederm@xmission.com> > > As for enabling this. I believe we need an extra permission check just before > we copy the data from our temporary buffer to the target task, to ensure > nothing has changed. The history does not really capture why this code > was disabled, but before this gets enabled I would like to understand more > than just the comment. I believe with a little care this can be safely enabled > as it doesn't let you do anything ptrace wouldn't do, and it should let you do > it anytime except when ptrace would allow it. Thus not introducing any new > security holes. I've found two interesting links on that: http://lkml.org/lkml/2006/3/10/224 and http://www.google.com/search?q=cache:4y8MWSuHOpIJ:files.security-protocols.com/kernelhacking/procpidmem.pdf&hl=en&ct=clnk&cd=3&client=firefox-a The second one in particular goes in great detail on why the author thinks this is dangerous, and what could be done to re-enable it. Regards, Frederik ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [2.6.18 patch] fix mem_write return value (was: Re: bug report: mem_write) 2006-08-24 22:07 ` Frederik Deweerdt @ 2006-08-25 1:05 ` Amnon Shiloh 0 siblings, 0 replies; 6+ messages in thread From: Amnon Shiloh @ 2006-08-25 1:05 UTC (permalink / raw) To: Frederik Deweerdt Cc: Eric W. Biederman, Amnon Shiloh, linux-kernel, akpm, gregkh > On Thu, Aug 24, 2006 at 10:33:20AM -0600, Eric W. Biederman wrote: > > Frederik Deweerdt <deweerdt@free.fr> writes: > > > > > On Thu, Aug 24, 2006 at 11:25:37AM +0300, Amnon Shiloh wrote: > > >> Hi, > > >> > > >> Alright, I know that "mem_write" (fs/proc/base.c) is a "security hazard", > > >> but I need to use it anyway (as super-user only), and find it broken, > > >> somewhere between Linux-2.6.17 and Linux-2.6.18-rc4. > > >> > > >> The point is that in the beginning of the routine, "copied" is set to 0, > > >> but it is no good because in lines 805 and 812 it is set to other values. > > >> Finally, the routine returns as if it copied 12 (=ENOMEM) bytes less than > > >> it actually did. > > > True, it looks like the faulty commit is: > > > de7587343bfebc186995ad294e3de0da382eb9bc > > > > Actually it was: 99f895518368252ba862cc15ce4eb98ebbe1bec6 > > Which is what you url points to, odd. > > > > > http://www.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff_plain;h=99f895518368252ba862cc15ce4eb98ebbe1bec6;hp=8578cea7509cbdec25b31d08b48a92fcc3b1a9e3 > > > > > > The attached patch should fix it. Maybe that should go to 2.6.18. > > > Thanks for the bug report, > > > > The patch looks correct. Although this won't cause anyone problems as the code > > is disabled. > Right, I missed this, so this is really not urgent. > > > > Signed-off-by: Eric Biederman <ebiederm@xmission.com> > > > > As for enabling this. I believe we need an extra permission check just before > > we copy the data from our temporary buffer to the target task, to ensure > > nothing has changed. The history does not really capture why this code > > was disabled, but before this gets enabled I would like to understand more > > than just the comment. I believe with a little care this can be safely enabled > > as it doesn't let you do anything ptrace wouldn't do, and it should let you do > > it anytime except when ptrace would allow it. Thus not introducing any new > > security holes. > I've found two interesting links on that: > http://lkml.org/lkml/2006/3/10/224 > and > http://www.google.com/search?q=cache:4y8MWSuHOpIJ:files.security-protocols.com/kernelhacking/procpidmem.pdf&hl=en&ct=clnk&cd=3&client=firefox-a > The second one in particular goes in great detail on why the author > thinks this is dangerous, and what could be done to re-enable it. > > Regards, > Frederik > I am aware of those risks, but since I desparately need this feature and the program that needs it is SETUID-root anyway, I have it enabled but added a test to make sure that only root can use it. It works well and I can see no reason on earth how this could be a security hazard when only called by the super-user. Regards, Amnon. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-08-25 1:05 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2006-08-24 8:25 bug report: mem_write Amnon Shiloh 2006-08-24 10:35 ` Gerard J Snitselaar 2006-08-24 14:00 ` [2.6.18 patch] fix mem_write return value (was: Re: bug report: mem_write) Frederik Deweerdt 2006-08-24 16:33 ` Eric W. Biederman 2006-08-24 22:07 ` Frederik Deweerdt 2006-08-25 1:05 ` Amnon Shiloh
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox