Re: bug in write(2) system call.

Andries.Brouwer@cwi.nl
Mon, 19 Oct 1998 14:02:48 +0200 (MET DST)


From tigran@sco.COM Mon Oct 19 10:33:30 1998

Alan,

It is true that you said POSIX does not specify it, not even Single UNIX v2...
However, most existing Unix flavours, including Linux, document
read,v(2)/write,v(2) (and many others) as returning EFAULT if the buf is
outside of process' address space. Therefore either the manpage should be
changed (hence cc: Andries) or the "issue" (not a bug, just issue) should
be fixed.

Hmm. The POSIX description of EFAULT is:

[EFAULT]: Bad address
The system detected an invalid address in attempting to use
an argument of a call. The reliable detection of this error
is implementation defined; however, implementations that do detect
this condition shall use this value.

The man page write.2 says:

ERRORS
EBADF fd is not a valid file descriptor or is not open
for writing.

EINVAL fd is attached to an object which is unsuitable for
writing.

EFAULT buf is outside your accessible address space.
...

That is, if the write call returns EFAULT, then your address
was bad, but not necessarily conversely.

Of course it is highly desirable that Linux detect all such
invalid addresses, but it would be bad software that relied on it.

>
> Its also not actually a bug. What happens when you pass invalid pointers is
> undefined by posix. Obviously the Linux idea of undefined doesnt include
> crashes but returning an OK is fine
>

It is a matter of quality of implementation.
A high quality implementation detects all bad addresses and
returns EFAULT for them.

Andries

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/