NetBSD Problem Report #40220
From jmcneill@black.invisible.ca Thu Dec 18 14:41:41 2008
Return-Path: <jmcneill@black.invisible.ca>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
by narn.NetBSD.org (Postfix) with ESMTP id 139E263BA47
for <gnats-bugs@gnats.NetBSD.org>; Thu, 18 Dec 2008 14:41:41 +0000 (UTC)
Message-Id: <20081218144121.D48AA7D8734@black.invisible.ca>
Date: Thu, 18 Dec 2008 09:41:21 -0500 (EST)
From: jmcneill@invisible.ca
Reply-To: jmcneill@invisible.ca
To: gnats-bugs@gnats.NetBSD.org
Subject: LD_PRELOAD with dlsym(RTLD_NEXT, "stat") recursion
X-Send-Pr-Version: 3.95
>Number: 40220
>Category: lib
>Synopsis: LD_PRELOAD with dlsym(RTLD_NEXT, "stat") recursion
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Dec 18 14:45:00 +0000 2008
>Last-Modified: Sat Apr 18 18:00:02 +0000 2009
>Originator: Jared D. McNeill
>Release: NetBSD 5.99.5
>Organization:
>Environment:
System: NetBSD black.invisible.ca 5.99.5 NetBSD 5.99.5 (GENERIC) #39: Mon Dec 15 20:56:04 EST 2008 jmcneill@black.invisible.ca:/export/home/jmcneill/branches/HEAD/src/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
When trying to overload the 'stat' function with LD_PRELOAD,
the overloaded function will end up recursing.
>How-To-Repeat:
Compile the following program with:
$ cc -fPIC -DPIC -shared test.c -o test.so
and then run:
$ LD_PRELOAD=test.so ls -l
stat(/etc/nsswitch.conf) depth=1
stat(/etc/nsswitch.conf) depth=2
assertion "depth == 1" failed: file "test.c", line 20, function "stat"
Abort (core dumped)
#include <sys/stat.h>
#include <assert.h>
#include <dlfcn.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static int (*_stat)(const char *, struct stat *) = NULL;
int
stat(const char *pathname, struct stat *buf)
{
static int depth = 0;
int ret;
++depth;
(void)fprintf(stderr, "stat(%s) depth=%d\n", pathname, depth);
assert(depth == 1);
if (!_stat)
_stat = dlsym(RTLD_NEXT, "stat");
ret = _stat(pathname, buf);
--depth;
return ret;
}
>Fix:
>Audit-Trail:
From: "Jared D. McNeill" <jmcneill@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/40220 CVS commit: pkgsrc/audio/pulseaudio
Date: Thu, 18 Dec 2008 18:43:52 +0000 (UTC)
Module Name: pkgsrc
Committed By: jmcneill
Date: Thu Dec 18 18:43:52 UTC 2008
Modified Files:
pkgsrc/audio/pulseaudio: Makefile distinfo
pkgsrc/audio/pulseaudio/patches: patch-aa
Log Message:
Workaround PR lib/40220 on NetBSD, padsp (OSS wrapper) now works.
Bump PKGREVISION.
To generate a diff of this commit:
cvs rdiff -r1.1.1.1 -r1.2 pkgsrc/audio/pulseaudio/Makefile \
pkgsrc/audio/pulseaudio/distinfo
cvs rdiff -r1.1.1.1 -r1.2 pkgsrc/audio/pulseaudio/patches/patch-aa
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: Christian Biere <christianbiere@gmx.de>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: Re: lib/40220: LD_PRELOAD with dlsym(RTLD_NEXT, "stat") recursion
Date: Sat, 18 Apr 2009 15:58:23 +0200
I just noticed similar i.e., socker[1] doesn't work anymore when using
the LD_PRELOAD wrapper on NetBSD. I've looked at the workaround in the
pkgsrc patch.
The workaround is to use "__stat30" instead of "stat" for dlsym().
For socker I had to change "socket" to "__socket30".
A quick check shows that a couple functions seem to be affected by
this:
$ nm /lib/libc.so|sed -n 's,^.* T __\(.*\)30$,\1,p'
_readdir_unlocked
fhstat
fstat
fts_children
fts_close
fts_open
fts_read
fts_set
getdents
getfh
glob
globfree
lstat
ntp_gettime
opendir2
opendir
readdir
readdir_r
scandir
socket
stat
Will this be fixed or are the "__.*30" names permanent?
If these change the workaround will of course turn into a bug itself.
[1] https://gtk-gnutella.svn.sourceforge.net/svnroot/gtk-gnutella/trunk/gtk-gnutella/contrib/socker/README
--
Christian
From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: lib/40220: LD_PRELOAD with dlsym(RTLD_NEXT, "stat") recursion
Date: Sat, 18 Apr 2009 19:56:54 +0200
On Sat, Apr 18, 2009 at 02:00:06PM +0000, Christian Biere wrote:
> Will this be fixed or are the "__.*30" names permanent?
> If these change the workaround will of course turn into a bug itself.
These are weak aliases, the functions had abi changes and have been renamed.
This will stay this way untill libc gets it's major bumped.
When compiling a wrapper you probably have to double check wether the
rename/weak alias is in scope (i.e. avoid the official headers) or play
ifdef games.
Martin
>Unformatted:
(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-2007
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.