NetBSD Problem Report #49684

From khorben@defora.org  Sat Feb 21 23:10:03 2015
Return-Path: <khorben@defora.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id DBB8AA57FE
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 21 Feb 2015 23:10:02 +0000 (UTC)
Message-Id: <20150221230727.7899A19A50@sleak.defora.rom>
Date: Sun, 22 Feb 2015 00:07:27 +0100 (CET)
From: Pierre Pronchery <khorben@defora.org>
To: gnats-bugs@gnats.NetBSD.org
Subject: readlinkat(2) is not compliant
X-Send-Pr-Version: 3.95

>Number:         49684
>Category:       standards
>Synopsis:       readlinkat(2) is not compliant
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    standards-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Feb 21 23:15:00 +0000 2015
>Closed-Date:    Wed Apr 15 07:39:36 +0000 2015
>Last-Modified:  Wed Apr 15 07:39:36 +0000 2015
>Originator:     Pierre Pronchery
>Release:        NetBSD 7.0_BETA
>Organization:
The NetBSD Foundation
>Environment:
>Description:
There is a discrepancy between the manual page for readlinkat(2) and the
actual prototype for this system call as found in /usr/include/unistd.h.

The manual page says:
  ssize_t
  readlinkat(int fd, const char * restrict path, char * restrict buf,
      size_t bufsiz);

Whereas the header actually contains:
  int
  readlinkat(int fd, const char *, char *, size_t);

The issue is therefore with the return value, respectively typed ssize_t
and int. Somewhat interestingly, I noticed this because of a build issue
in a software project failing to recognize support of readlinkat(2) in
NetBSD, and then providing a conflicting prototype for it.

Last but not least, according to The Open Group Base Specifications
Issue 7, the prototype should be:
  ssize_t
  readlinkat(int fd, const char *restrict path, char *restrict buf,
      size_t bufsize);

Just like the manual says. I am afraid this may involve an ABI update in
NetBSD's libc, but I do not know for sure as of now.

A quick look at the functions surrounding readlinkat(2) in unistd.h:
- linkat() is fine
- renameat() is fine
- faccessat() is fine
- fchownat() apparently not in the specification online
- symlinkat() is fine
- unlinkat() is fine

Likewise readlink(2) looks good to me. My immediate knowledge does not
allow me to be sure whether the actual implementation in
sys/kern/vfs_syscalls.c is impacted at all. It seems to be that the
result might be truncated from sizeof(ssize_t) to sizeof(int) on some
platforms (like every 32-bits I know). But I will welcome a better
expertise here.

>How-To-Repeat:
Build wip/pkg15 1.4.99.11nb4 from pkgsrc on NetBSD 7.0_BETA or newer.
>Fix:
Probably involves modifying /usr/include/unistd.h as follows:

Index: include/unistd.h
===================================================================
RCS file: /cvsroot/src/include/unistd.h,v
retrieving revision 1.143
diff -p -u -r1.143 unistd.h
--- include/unistd.h	26 Sep 2014 19:28:03 -0000	1.143
+++ include/unistd.h	21 Feb 2015 22:41:29 -0000
@@ -308,7 +308,7 @@ int	linkat(int, const char *, int, const
 int	renameat(int, const char *, int, const char *);
 int	faccessat(int, const char *, int, int);
 int	fchownat(int, const char *, uid_t, gid_t, int);
-int	readlinkat(int, const char *, char *, size_t);
+ssize_t	readlinkat(int, const char *, char *, size_t);
 int	symlinkat(const char *, int, const char *);
 int	unlinkat(int, const char *, int);
 #endif

Then also syscalls.master:

Index: sys/kern/syscalls.master
===================================================================
RCS file: /cvsroot/src/sys/kern/syscalls.master,v
retrieving revision 1.271
diff -p -u -r1.271 syscalls.master
--- sys/kern/syscalls.master	10 Feb 2015 15:07:39 -0000	1.271
+++ sys/kern/syscalls.master	21 Feb 2015 22:59:07 -0000
@@ -919,7 +919,7 @@
 			    const struct timespec *tptr, int flag); }
 468	STD  RUMP	{ int|sys||openat(int fd, const char *path, \
 			    int oflags, ... mode_t mode); }
-469	STD  RUMP	{ int|sys||readlinkat(int fd, const char *path, \
+469	STD  RUMP	{ ssize_t|sys||readlinkat(int fd, const char *path, \
 			    char *buf, size_t bufsize); }
 470	STD  RUMP	{ int|sys||symlinkat(const char *path1, int fd, \
 			    const char *path2); }

(then of course re-generating everything related)

>Release-Note:

>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/49684 CVS commit: src/sys/kern
Date: Sat, 21 Feb 2015 19:50:30 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Sun Feb 22 00:50:30 UTC 2015

 Modified Files:
 	src/sys/kern: syscalls.master

 Log Message:
 PR/49684: Pierre Pronchery: readlinkat(2) return type is wrong.


 To generate a diff of this commit:
 cvs rdiff -u -r1.271 -r1.272 src/sys/kern/syscalls.master

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/49684 CVS commit: src/sys
Date: Sat, 21 Feb 2015 19:53:29 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Sun Feb 22 00:53:29 UTC 2015

 Modified Files:
 	src/sys/kern: init_sysent.c syscalls.c
 	src/sys/rump/include/rump: rump_syscalls.h
 	src/sys/sys: syscall.h syscallargs.h

 Log Message:
 PR/49684: Pierre Pronchery: readlinkat(2) return type is wrong.


 To generate a diff of this commit:
 cvs rdiff -u -r1.288 -r1.289 src/sys/kern/init_sysent.c
 cvs rdiff -u -r1.279 -r1.280 src/sys/kern/syscalls.c
 cvs rdiff -u -r1.80 -r1.81 src/sys/rump/include/rump/rump_syscalls.h
 cvs rdiff -u -r1.275 -r1.276 src/sys/sys/syscall.h
 cvs rdiff -u -r1.258 -r1.259 src/sys/sys/syscallargs.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/49684 CVS commit: src/include
Date: Sat, 21 Feb 2015 19:54:47 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Sun Feb 22 00:54:46 UTC 2015

 Modified Files:
 	src/include: unistd.h

 Log Message:
 PR/49684: Pierre Pronchery: readlinkat(2) return type is wrong.


 To generate a diff of this commit:
 cvs rdiff -u -r1.143 -r1.144 src/include/unistd.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/49684 CVS commit: [netbsd-7] src
Date: Tue, 24 Feb 2015 10:47:17 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Tue Feb 24 10:47:17 UTC 2015

 Modified Files:
 	src/include [netbsd-7]: unistd.h
 	src/sys/kern [netbsd-7]: syscalls.master

 Log Message:
 Pull up following revision(s) (requested by khorben in ticket #547):
 	include/unistd.h: revision 1.144
 	sys/kern/syscalls.master: revision 1.272

 PR/49684: Pierre Pronchery: readlinkat(2) return type is wrong.


 To generate a diff of this commit:
 cvs rdiff -u -r1.142 -r1.142.2.1 src/include/unistd.h
 cvs rdiff -u -r1.270 -r1.270.2.1 src/sys/kern/syscalls.master

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->pending-pullups
State-Changed-By: khorben@NetBSD.org
State-Changed-When: Sun, 01 Mar 2015 01:25:29 +0000
State-Changed-Why:
Pending pullup-6 #1264 and pullup-7 #560


From: "SAITOH Masanobu" <msaitoh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/49684 CVS commit: [netbsd-6] src
Date: Tue, 14 Apr 2015 15:03:38 +0000

 Module Name:	src
 Committed By:	msaitoh
 Date:		Tue Apr 14 15:03:38 UTC 2015

 Modified Files:
 	src/include [netbsd-6]: unistd.h
 	src/sys/compat/netbsd32 [netbsd-6]: netbsd32_syscall.h
 	    netbsd32_syscallargs.h netbsd32_syscalls.c netbsd32_sysent.c
 	    syscalls.master
 	src/sys/kern [netbsd-6]: init_sysent.c syscalls.c syscalls.master
 	src/sys/rump/include/rump [netbsd-6]: rump_syscalls.h
 	src/sys/rump/librump/rumpkern [netbsd-6]: rump_syscalls.c
 	src/sys/sys [netbsd-6]: syscall.h syscallargs.h

 Log Message:
 Pull up following revision(s) (requested by khorben in ticket #1264):

 include/unistd.h				1.144
 sys/kern/init_sysent.c				regen
 sys/kern/syscalls.c				regen
 sys/kern/syscalls.master			1.272
 sys/rump/include/rump/rump_syscalls.h		regen
 sys/rump/librump/rumpkern/rump_syscalls.c	regen
 sys/sys/syscall.h				regen
 sys/sys/syscallargs.h				regen
 sys/compat/netbds32/netbsd32_syscall.h		regen
 sys/compat/netbds32/netbsd32_syscallargs.h	regen
 sys/compat/netbds32/netbsd32_syscalls.c		regen
 sys/compat/netbds32/netbsd32_sysent.c		regen
 sys/compat/netbsd32/syscalls.master		1.102

 	Fix return type of the readlinkat(2) syscall. PR#49684.


 To generate a diff of this commit:
 cvs rdiff -u -r1.128 -r1.128.2.1 src/include/unistd.h
 cvs rdiff -u -r1.99.2.1 -r1.99.2.2 src/sys/compat/netbsd32/netbsd32_syscall.h \
     src/sys/compat/netbsd32/netbsd32_syscallargs.h
 cvs rdiff -u -r1.98.2.1 -r1.98.2.2 \
     src/sys/compat/netbsd32/netbsd32_syscalls.c \
     src/sys/compat/netbsd32/netbsd32_sysent.c
 cvs rdiff -u -r1.91.2.1 -r1.91.2.2 src/sys/compat/netbsd32/syscalls.master
 cvs rdiff -u -r1.261 -r1.261.2.1 src/sys/kern/init_sysent.c
 cvs rdiff -u -r1.252 -r1.252.2.1 src/sys/kern/syscalls.c
 cvs rdiff -u -r1.254 -r1.254.2.1 src/sys/kern/syscalls.master
 cvs rdiff -u -r1.55 -r1.55.2.1 src/sys/rump/include/rump/rump_syscalls.h
 cvs rdiff -u -r1.77 -r1.77.2.1 src/sys/rump/librump/rumpkern/rump_syscalls.c
 cvs rdiff -u -r1.248 -r1.248.2.1 src/sys/sys/syscall.h
 cvs rdiff -u -r1.231 -r1.231.2.1 src/sys/sys/syscallargs.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: pending-pullups->closed
State-Changed-By: khorben@NetBSD.org
State-Changed-When: Wed, 15 Apr 2015 07:39:36 +0000
State-Changed-Why:
Pull-up to netbsd-6 complete (#1264).
Pull-up to netbsd-7 complete (#560).


>Unformatted:
 Built on February 16th 2015, up to tickets #500 and #501 applied.
 (EdgeBSD's commit ID c2bd92a3)

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.