linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch 0/3] [RFC] kernel/glibc mismatch of "readlink" syscall?
@ 2008-10-23 14:50 Daniel Gollub
  2008-10-23 14:50 ` [patch 1/3] [RFC] Change sys_readlink/sys_readlinkat buffer size parameter to size_t (POSIX mismatch) Daniel Gollub
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Daniel Gollub @ 2008-10-23 14:50 UTC (permalink / raw)
  To: linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-api-u79uwXL29TY76Z2rM5mHXA,
	linux-man-u79uwXL29TY76Z2rM5mHXA,
	ltp-list-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

Hi,

found something which looks for me like a kernel/glibc syscall mismatch. At
least the parameter list of "readlink" is different in the kernel compared to
glibc, POSIX and linux-man-pages. I'm not quite sure if this difference was
intended or not ... 

man 3p readlink:
ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize);

http://www.opengroup.org/onlinepubs/000095399/functions/readlink.html:
size_t readlink(const char *restrict path, char *restrict buf, size_t bufsize);

glibc (/usr/include/unistd.h):
size_t readlink (__const char *__restrict __path, char *__restrict __buf, size_t

man 2 readlink:
ssize_t readlink(const char *path, char *buf, size_t bufsiz);
                                              ^^^^^^
linux-2.6/include/linux/syscalls.h:
asmlinkage long sys_readlink(const char __user *path, char __user *buf, int
		bufsiz);                                                ^^^


All readlink prototypes, expect the one in the kernel, have an unsigned
buffer size. Even the readlink(2) man-page, which also describes an error
statement like this:

EINVAL bufsiz is not positive.

Note: the same man-page defined bufsiz as type of size_t (unsigned).

While reviewing LTP i discovered that the "readlink03" syscall test contains a 
testcase to do a functional error-path test for "EINVAL bufsiz is not positive".
This testcase is using the glibc readlink() interface, which cause a unsigned
cast of the value "-1" and let the testcase fail (actually due to gcc/glibc
fortify checks and cause a __chk_fail()).

Before workarounding the testcase, or not applying -D_FORTIFY_SOURCE=2 on LTP
build, i try to understand if there is any reason for this mismatch between
kernel and glibc/POSIX. Regarding the man-page, i'm quite certain this was a
copy&paste-error by coping the prototype from the POSIX man-page.

Even sys_readlinkat(), which got introduced a long time after sys_readlink(),
got a signed buffer size. Intended?

In the rare case all this was unintended, find patches for kernel, man-pages
and LTP to change the kernel readlink syscall interface to a unsigned buffer
size.

Thoughts?

best regards,
Daniel
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2008-11-04 16:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-23 14:50 [patch 0/3] [RFC] kernel/glibc mismatch of "readlink" syscall? Daniel Gollub
2008-10-23 14:50 ` [patch 1/3] [RFC] Change sys_readlink/sys_readlinkat buffer size parameter to size_t (POSIX mismatch) Daniel Gollub
2008-10-23 14:50 ` [patch 2/3] [man-pages] Remove "bufsize is not positive" from readlink(2) error section Daniel Gollub
2008-10-23 14:50 ` [patch 3/3] [ltp] Remove testcase for "Buffer size is not positive" in kernel/syscalls/readlink/readlink03 Daniel Gollub
     [not found] ` <20081023145054.998439866-MHjlv9skyARbpigZmTR7Iw@public.gmane.org>
2008-10-24 22:53   ` [patch 0/3] [RFC] kernel/glibc mismatch of "readlink" syscall? Michael Kerrisk
     [not found]     ` <cfd18e0f0810241553x77194611o11655a89871dc210-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-10-28  9:11       ` Andries E. Brouwer
2008-10-31 15:02       ` Kai Henningsen
     [not found]         ` <20081031160248.2b95d0e8-r49W/1Cwd2f9tVrXfjCyDJqJBGhVce5bs0AfqQuZ5sE@public.gmane.org>
2008-10-31 15:37           ` Daniel Gollub
     [not found]             ` <200810311637.25371.dgollub-l3A5Bk7waGM@public.gmane.org>
2008-11-04 16:20               ` Michael Kerrisk

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