Skip to content

RFC kernel/glibc mismatch of "readlink" syscall?

Daniel Gollub linux-api linux-man lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest3 patches 5 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3Change sys_readlink/sys_readlinkat buffer size parameter to size_t (POSIX mismatch)fs/9p/vfs_inode.c fs/bad_inode.c fs/ecryptfs/inode.c +8 more+24 -240 replies
2/3Remove "bufsize is not positive" from readlink(2) error sectionman2/readlink.2+0 -40 replies
3/3Remove testcase for "Buffer size is not positive" in kernel/syscalls/readlink/readlink03testcases/kernel/syscalls/readlink/readlink03.c+0 -30 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [patch 0/3] [RFC] kernel/glibc mismatch of "readlink" syscall?

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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html