NetBSD Problem Report #49759

From www@NetBSD.org  Thu Mar 19 14:32:46 2015
Return-Path: <www@NetBSD.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 9F536A6567
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 19 Mar 2015 14:32:46 +0000 (UTC)
Message-Id: <20150319143245.26E85A65B7@mollari.NetBSD.org>
Date: Thu, 19 Mar 2015 14:32:45 +0000 (UTC)
From: oshima-ya@yagoto-urayama.jp
Reply-To: oshima-ya@yagoto-urayama.jp
To: gnats-bugs@NetBSD.org
Subject: pth call incorrect syscall when netbsd-6 or lator
X-Send-Pr-Version: www-1.0

>Number:         49759
>Category:       pkg
>Synopsis:       pth call incorrect syscall when netbsd-6 or lator
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    pkg-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Mar 19 14:35:01 +0000 2015
>Closed-Date:    Sat Mar 21 16:18:37 +0000 2015
>Last-Modified:  Sat Mar 21 16:20:01 +0000 2015
>Originator:     Yasushi Oshima
>Release:        pkgsrc-current at Mar 19 2015
>Organization:
>Environment:
NetBSD n6i836 6.1.5 NetBSD 6.1.5 (GENERIC)
>Description:
When run gpg-agent --daemon --enable-ssh-support and run gpg2 --card-status, the /usr/pkg/libexec/scdaemon uses 100% CPU load.
It will occur on all 32bit NetBSD platform after NetBSD-6.0. 

This cause is in devel/pth.

The syscall interface of pth, it calls symbol name such as "select" from libc.so by dlsym().

But the 'select' syscall was changed from NetBSD-6.
It is 'compat_50_select' for NetBSD 5 or before compatible with 32bit time_t interface.
In native build on NetBSD-6 or later, it should use a new syscall '__syscall50'.

By the same reason 'nanosleep' should be '__nanosleep50' and 'wait4' should be '__wait450'.
>How-To-Repeat:
In NetBSD/i386 6.x or 7.0_BETA,
- build pkgsrc/security/gnupg2
- run 
   /usr/pkg/libexec/scdaemon --daemon

>Fix:
The patch-ad for pth_syscall.c will below:


--- pth_syscall.c.orig	2006-06-08 17:54:03.000000000 +0000
+++ pth_syscall.c
@@ -57,6 +57,7 @@
 #define sendto        __pth_sys_sendto
 #define pread         __pth_sys_pread
 #define pwrite        __pth_sys_pwrite
+#define wait4         __pth_sys_wait4

 /* include the private header and this way system headers */
 #include "pth_p.h"
@@ -108,6 +109,7 @@ int pth_syscall_hard = PTH_SYSCALL_HARD;
 #undef sendto
 #undef pread
 #undef pwrite
+#undef wait4

 /* internal data structures */
 #if cpp
@@ -157,15 +159,28 @@ intern pth_syscall_fct_tab_t pth_syscall
 #define PTH_SCF_sendto        19
 #define PTH_SCF_pread         20
 #define PTH_SCF_pwrite        21
+#define PTH_SCF_wait4         22
     { "fork",        NULL },
     { "waitpid",     NULL },
     { "system",      NULL },
+#if defined(__NetBSD__) && defined(SYS___nanosleep50)
+    { "__nanosleep50",      NULL },
+#else
     { "nanosleep",   NULL },
+#endif
     { "usleep",      NULL },
     { "sleep",       NULL },
+#if defined(__NetBSD__)
+    { "__sigprocmask14", NULL },
+#else
     { "sigprocmask", NULL },
+#endif
     { "sigwait",     NULL },
+#if defined(__NetBSD__) && defined(SYS___select50)
+    { "__select50",      NULL },
+#else
     { "select",      NULL },
+#endif
     { "poll",        NULL },
     { "connect",     NULL },
     { "accept",      NULL },
@@ -179,6 +194,11 @@ intern pth_syscall_fct_tab_t pth_syscall
     { "sendto",      NULL },
     { "pread",       NULL },
     { "pwrite",      NULL },
+#if defined(__NetBSD__) && defined(SYS___wait450)
+    { "__wait450",      NULL },
+#else
+    { "wait4",       NULL },
+#endif
     { NULL,          NULL }
 };
 #endif
@@ -405,6 +425,10 @@ intern pid_t pth_sc_waitpid(pid_t wpid, 
                (wpid, status, options);
 #if defined(HAVE_SYSCALL) && defined(SYS_waitpid)
     else return (pid_t)syscall(SYS_waitpid, wpid, status, options);
+#elif defined(HAVE_SYSCALL) && defined(SYS_wait4)
+    else return (pid_t)syscall(SYS_wait4, wpid, status, options, (struct rusage *) NULL);
+#elif defined(HAVE_SYSCALL) && defined(SYS___wait450)
+    else return (pid_t)syscall(SYS___wait450, wpid, status, options, (struct rusage *) NULL);
 #else
     else PTH_SYSCALL_ERROR(-1, ENOSYS, "waitpid");
 #endif
@@ -491,6 +515,8 @@ intern int pth_sc_select(int nfds, fd_se
     else return (int)syscall(SYS__newselect, nfds, readfds, writefds, exceptfds, timeout);
 #elif defined(HAVE_SYSCALL) && defined(SYS_select)
     else return (int)syscall(SYS_select, nfds, readfds, writefds, exceptfds, timeout);
+#elif defined(HAVE_SYSCALL) && defined(SYS___select50)
+    else return (int)syscall(SYS___select50, nfds, readfds, writefds, exceptfds, timeout);
 #else
     else PTH_SYSCALL_ERROR(-1, ENOSYS, "accept");
 #endif
@@ -721,5 +747,29 @@ intern ssize_t pth_sc_sendto(int fd, con
 #endif
 }

+/* ==== Pth hard syscall wrapper for wait4(2) ==== */
+pid_t wait4(pid_t, int *, int, struct rusage *);
+pid_t wait4(pid_t wpid, int *status, int options, struct rusage *rusage)
+{
+    /* external entry point for application */
+    pth_implicit_init();
+    return pth_wait4(wpid, status, options, rusage);
+}
+intern pid_t pth_sc_wait4(pid_t wpid, int *status, int options, struct rusage *rusage)
+{
+    /* internal exit point for Pth */
+    if (pth_syscall_fct_tab[PTH_SCF_wait4].addr != NULL)
+        return ((pid_t (*)(pid_t, int *, int, struct rusage *))
+               pth_syscall_fct_tab[PTH_SCF_wait4].addr)
+               (wpid, status, options, rusage);
+#if defined(HAVE_SYSCALL) && defined(SYS_wait4)
+    else return (pid_t)syscall(SYS_wait4, wpid, status, options, rusage);
+#elif defined(HAVE_SYSCALL) && defined(SYS___wait450)
+    else return (pid_t)syscall(SYS___wait450, wpid, status, options, rusage);
+#else
+    else PTH_SYSCALL_ERROR(-1, ENOSYS, "wait4");
+#endif
+}
+
 #endif /* PTH_SYSCALL_HARD */


>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->closed
State-Changed-By: wiz@NetBSD.org
State-Changed-When: Sat, 21 Mar 2015 16:18:37 +0000
State-Changed-Why:
Committed, thank you!

Can you please send this patch (and perhaps all of patch-ad) upstream?


From: "Thomas Klausner" <wiz@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/49759 CVS commit: pkgsrc/devel/pth
Date: Sat, 21 Mar 2015 16:18:12 +0000

 Module Name:	pkgsrc
 Committed By:	wiz
 Date:		Sat Mar 21 16:18:12 UTC 2015

 Modified Files:
 	pkgsrc/devel/pth: Makefile distinfo
 	pkgsrc/devel/pth/patches: patch-ad

 Log Message:
 Adapt syscall name patch for NetBSD>=6.0.
 From Yasushi Oshima in PR 49759.


 To generate a diff of this commit:
 cvs rdiff -u -r1.77 -r1.78 pkgsrc/devel/pth/Makefile
 cvs rdiff -u -r1.16 -r1.17 pkgsrc/devel/pth/distinfo
 cvs rdiff -u -r1.6 -r1.7 pkgsrc/devel/pth/patches/patch-ad

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

>Unformatted:

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.