linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: AUDIT: copy_from_user is a deathtrap.
@ 2002-05-19  3:38 Rusty Russell
  2002-05-19  5:23 ` Linus Torvalds
  0 siblings, 1 reply; 84+ messages in thread
From: Rusty Russell @ 2002-05-19  3:38 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel, alan

> Um, what about delivering a SIGSEGV?  So, copy_to/from_user always
> returns 0, but a signal is delivered.  Then the only places which need
> to be clever are the mount option copying, and the signal delivery
> code for SIGSEGV (which uses copy_to_user).

Sorry, this doesn't work here either: this would return the wrong
value from read.

Of course, everyone who does more than one copy_to_user should be
checking that return value, and not doing:

	if (copy_to_user(uptr....) 
	   || copy_to_user(uptr+10,....) 
		return -EFAULT

So that such gc schemes actually work,
Rusty.
--
  Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

^ permalink raw reply	[flat|nested] 84+ messages in thread
* Re: AUDIT: copy_from_user is a deathtrap.
@ 2002-05-22 13:40 Petr Vandrovec
  2002-05-22 18:58 ` Denis Vlasenko
  0 siblings, 1 reply; 84+ messages in thread
From: Petr Vandrovec @ 2002-05-22 13:40 UTC (permalink / raw)
  To: Denis Vlasenko; +Cc: linux-kernel, acme

[trimmed cc a bit]

On 22 May 02 at 14:23, Denis Vlasenko wrote:
> > On 22 May 02 at 12:27, Denis Vlasenko wrote:
> > > > As Linus and others pointed out, copy_{to_from}_user has its uses and
> > > > will stay, but something like:
> > >
> > > I don't say 'kill it', I say 'rename it so that its name tells users what
> > > return value to expect'. However, one have to weigh
> >
> > Why?
> 
> Why what? Why rename copy_to_user? Because in its current form people

Why rename it. 

> misunderstand its return value and misuse it.
> We can keep unmodified version of copy_to_user for some time for
> compatibility.

Function name is not documentation. Documentation documents function
API, or, in case documentation is not available, source does it.
copy_to_user_dude_I_return_uncopied_length_on_error_not_EFAULT_parameters_are_same_as_for_memcpy() 
is unacceptable name, and anything shorter does not document things 
you must know.

> > From copyin/out descriptions sent yesterday if you want same source code
> > running on all (BSD,SVR4,OSF/1) platforms, you must do
> >
> > if (copyin()) return [-]EFAULT;
> 
> But if I am new to Linux and just want to write my first piece of kernel
> code, copyout() is even worse than copy_to_user(): 
> it too lacks info of what it can return (0/1, 0/-EFAULT, # of copied bytes,

Hey, please change sys_read(). I'm used that read() returns -1 on error,
but now in kernel it returns some strange negative value. Please fix it.

I'm not sure that I want to use kernel which contains code written
by people who do not read API documentation. I expect that everyone 
here tests every branch in code he writes at least once - and such test
would (f.e.) quickly reveal that read(fd, NULL, 1000) does not return -1 &
set errno to EFAULT, but instead returns complete success (1000) on
affected sound drivers.

No. copy_*_user interface is documented since 2.1.0, only bad old
verify_area() in older kernels returned -EFAULT on error, and I do
not believe that coders who coded for 2.0.x did not notice completely
different interface (copy_from_user instead of verify_area + memcpy_fromfs)
during last almost 6 years.
                                            Best regards,
                                                Petr Vandrovec
                                                vandrove@vc.cvut.cz
                                                

^ permalink raw reply	[flat|nested] 84+ messages in thread
* Re: AUDIT: copy_from_user is a deathtrap.
@ 2002-05-22 10:08 Petr Vandrovec
  2002-05-22 16:23 ` Denis Vlasenko
  0 siblings, 1 reply; 84+ messages in thread
From: Petr Vandrovec @ 2002-05-22 10:08 UTC (permalink / raw)
  To: Denis Vlasenko; +Cc: Pete Zaitcev, linux-kernel, acme

On 22 May 02 at 12:27, Denis Vlasenko wrote:

> > As Linus and others pointed out, copy_{to_from}_user has its uses and will
> > stay, but something like:
> 
> I don't say 'kill it', I say 'rename it so that its name tells users what
> return value to expect'. However, one have to weigh 

Why? OSF/1's copyin/copyout returns exactly same value which
our current copy_{to,from}_user does. You should not penalize
developers who read documentation.

> I usually vote for long_but_easy_to_understand_name(), but it's MHO only.
> 
> > #define copyin(...) (copy_from_user(...) ? -EFAULT : 0)
> > #define copyout(...) (copy_to_user(...) ? -EFAULT : 0)
> 
> This falls in cryptcnshrt() category.
> Will "new programmer" grasp form the name alone that it returns EFAULT?
> /me in doubt. OTOH BSD folks may be happy.

>From copyin/out descriptions sent yesterday if you want same source code 
running on all (BSD,SVR4,OSF/1) platforms, you must do

if (copyin()) return [-]EFAULT;

anyway, otherwise OSF/1 and SVR4 variants are wrong.
                                                    Petr Vandrovec
                                                    vandrove@vc.cvut.cz


^ permalink raw reply	[flat|nested] 84+ messages in thread
[parent not found: <Pine.LNX.4.44.0205191951460.22433-100000@home.transmeta.com.suse.lists.linux.kernel>]
[parent not found: <E178eMm-0000NO-00@wagner.rustcorp.com.au.suse.lists.linux.kernel>]
[parent not found: <mailman.1021642692.12772.linux-kernel2news@redhat.com>]
* AUDIT: copy_from_user is a deathtrap.
@ 2002-05-17  9:27 Rusty Russell
  2002-05-17  9:21 ` David S. Miller
  2002-05-17 10:20 ` Christoph Hellwig
  0 siblings, 2 replies; 84+ messages in thread
From: Rusty Russell @ 2002-05-17  9:27 UTC (permalink / raw)
  To: torvalds; +Cc: linux-kernel

Linus,

	Should I change copy_to/from_user to return -EFAULT, or
introduce a new copy_to/from_uspace which does and start moving
everything across?

There are 5,500 uses of copy_to/from_user in 2.5.15.  52 of them use
the return value in a way which would be broken by it returning
-EFAULT.  51 of those don't need to (mainly cut & paste between serial
drivers).

	/* Returns amount which wasn't copied before EFAULT.  Used by mount. */
	static inline unsigned long
	gradual_copy_from_user(void *to, const void *from, unsigned long n)
	{
		unsigned long i;

		for (i = 0; i < n; i++, to++, from++) {
			if (copy_from_user(from, to, 1) != 0)
				break;
		}

		return n - i;
	}

There are 415 uses of copy_to/from_user which are wrong, despite an
audit 12 months ago by the Stanford checker.

Tired of auditing the same bugs,
Rusty.
--
  Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

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

end of thread, other threads:[~2002-05-23 11:26 UTC | newest]

Thread overview: 84+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-19  3:38 AUDIT: copy_from_user is a deathtrap Rusty Russell
2002-05-19  5:23 ` Linus Torvalds
2002-05-17  0:00   ` Pavel Machek
2002-05-18 21:47   ` Benjamin Herrenschmidt
2002-05-19 12:22     ` Alan Cox
2002-05-19 18:29     ` Linus Torvalds
2002-05-19 19:57       ` Roman Zippel
2002-05-20  2:06       ` Rusty Russell
2002-05-20  2:54         ` Linus Torvalds
2002-05-19 17:59           ` [BK PATCH] char: " Arnaldo Carvalho de Melo
2002-05-20  4:53           ` Rusty Russell
2002-05-19 20:12             ` Arnaldo Carvalho de Melo
2002-05-20 16:00             ` Linus Torvalds
2002-05-19 11:41   ` Alan Cox
  -- strict thread matches above, loose matches on Subject: below --
2002-05-22 13:40 Petr Vandrovec
2002-05-22 18:58 ` Denis Vlasenko
2002-05-22 14:13   ` Ruth Ivimey-Cook
2002-05-22 10:08 Petr Vandrovec
2002-05-22 16:23 ` Denis Vlasenko
     [not found] <Pine.LNX.4.44.0205191951460.22433-100000@home.transmeta.com.suse.lists.linux.kernel>
     [not found] ` <E179fAd-0005vs-00@wagner.rustcorp.com.au.suse.lists.linux.kernel>
2002-05-20 10:59   ` Andi Kleen
     [not found] <E178eMm-0000NO-00@wagner.rustcorp.com.au.suse.lists.linux.kernel>
     [not found] ` <Pine.LNX.4.44.0205171936220.1524-100000@home.transmeta.com.suse.lists.linux.kernel>
2002-05-18 10:16   ` Andi Kleen
2002-05-18 16:14     ` Linus Torvalds
2002-05-19  2:10       ` Rusty Russell
2002-05-19  3:01         ` Linus Torvalds
2002-05-19  3:05           ` Larry McVoy
2002-05-19  4:01             ` Rusty Russell
2002-05-19  4:02               ` Larry McVoy
2002-05-16 23:56                 ` Pavel Machek
2002-05-16 23:56                 ` Pavel Machek
2002-05-19  3:31           ` Rusty Russell
2002-05-19  3:34             ` Linus Torvalds
2002-05-16 23:53               ` Pavel Machek
2002-05-21 20:47                 ` Linus Torvalds
2002-05-21 21:17                   ` Pavel Machek
2002-05-21 21:25                     ` Linus Torvalds
2002-05-21 21:44                     ` Alan Cox
2002-05-21 21:46                       ` Andrew Morton
2002-05-21 22:04                         ` Linus Torvalds
2002-05-21 22:21                           ` Pavel Machek
2002-05-22 13:47                             ` Alan Cox
2002-05-22 14:13                               ` Pavel Machek
2002-05-22 14:54                                 ` Alan Cox
2002-05-22 14:42                                   ` Pavel Machek
2002-05-22 15:27                                     ` Alan Cox
2002-05-22 18:58                                   ` Kasper Dupont
2002-05-22 22:02                                     ` Alan Cox
2002-05-23  3:54                                   ` Rusty Russell
2002-05-23 11:15                                     ` Edgar Toernig
2002-05-22 16:09                                 ` Linus Torvalds
2002-05-22 20:28                                   ` Pavel Machek
2002-05-22  0:47                         ` Andrea Arcangeli
2002-05-22  5:01                         ` Rusty Russell
2002-05-22  6:28                         ` Rusty Russell
2002-05-22  4:57                       ` Rusty Russell
2002-05-22 13:30                         ` Alan Cox
2002-05-22 18:43                     ` Marco Colombo
2002-05-19 20:23       ` Edgar Toernig
2002-05-19 22:44         ` Alan Cox
     [not found] <mailman.1021642692.12772.linux-kernel2news@redhat.com>
2002-05-17 17:36 ` Pete Zaitcev
2002-05-18  1:05   ` Rusty Russell
2002-05-18  2:57     ` Alan Cox
2002-05-16 23:27       ` Pavel Machek
     [not found] ` <200205191212.g4JCCLY25867@Port.imtp.ilyichevsk.odessa.ua>
     [not found]   ` <20020520112232.A8983@devserv.devel.redhat.com>
2002-05-21 10:57     ` Denis Vlasenko
2002-05-21  6:21       ` Arnaldo Carvalho de Melo
2002-05-21  8:33         ` Christoph Hellwig
2002-05-21 19:02           ` Albert D. Cahalan
2002-05-22 14:27         ` Denis Vlasenko
2002-05-17  9:27 Rusty Russell
2002-05-17  9:21 ` David S. Miller
2002-05-17  9:49   ` Rusty Russell
2002-05-17  9:35     ` David S. Miller
2002-05-17 12:26       ` Rusty Russell
2002-05-17 17:42         ` Denis Vlasenko
2002-05-17 12:17     ` Alan Cox
2002-05-17 12:21       ` Rusty Russell
2002-05-17 12:58         ` Alan Cox
2002-05-17 12:58           ` Rusty Russell
2002-05-17 13:13             ` John Levon
2002-05-17 14:52             ` Alan Cox
2002-05-18  1:26               ` Rusty Russell
2002-05-17 17:58             ` Denis Vlasenko
2002-05-18  2:37     ` Linus Torvalds
2002-05-18 15:06       ` John Alvord
2002-05-17 10:20 ` Christoph Hellwig

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).