From nobody@FreeBSD.org  Thu Sep 13 11:27:50 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id B8944106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 13 Sep 2012 11:27:50 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id A48AE8FC14
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 13 Sep 2012 11:27:50 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id q8DBRoZh060922
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 13 Sep 2012 11:27:50 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id q8DBRofM060921;
	Thu, 13 Sep 2012 11:27:50 GMT
	(envelope-from nobody)
Message-Id: <201209131127.q8DBRofM060921@red.freebsd.org>
Date: Thu, 13 Sep 2012 11:27:50 GMT
From: Andrey Simonenko <simon@comsys.ntu-kpi.kiev.ua>
To: freebsd-gnats-submit@FreeBSD.org
Subject: LD_PRELOAD set to not absolute path crashes rtld
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         171604
>Category:       bin
>Synopsis:       [patch] LD_PRELOAD set to not absolute path crashes rtld
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kib
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 13 11:30:08 UTC 2012
>Closed-Date:    Sat Dec 15 06:31:57 UTC 2012
>Last-Modified:  Sat Dec 15 06:32:18 UTC 2012
>Originator:     Andrey Simonenko
>Release:        9.1-PRELEASE
>Organization:
>Environment:
>Description:
Recent RELENEG_9 got some changes that crash rtld if LD_PRELOAD is not absolute pathname.
>How-To-Repeat:
# env LD_PRELOAD=libz.so.6 ls
Segmentation fault (core dumped)
# gdb /bin/ls ls.core
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...(no debugging symbols found)...
Core was generated by `ls'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /libexec/ld-elf.so.1...(no debugging symbols found)...done.
Loaded symbols for /libexec/ld-elf.so.1
#0  0x000000080060d819 in dlinfo () from /libexec/ld-elf.so.1
(gdb) bt
#0  0x000000080060d819 in dlinfo () from /libexec/ld-elf.so.1
#1  0x000000080060fed1 in dlsym () from /libexec/ld-elf.so.1
#2  0x0000000800608fa9 in .text () from /libexec/ld-elf.so.1
#3  0x0000000000000000 in ?? ()
#4  0x0000000000000000 in ?? ()
....
Previous frame inner to this frame (corrupt stack?)
# env LD_PRELOAD=/lib/libz.so.6 ls
....

>Fix:


>Release-Note:
>Audit-Trail:

From: Mark Johnston <markjdb@gmail.com>
To: bug-followup@FreeBSD.org, simon@comsys.ntu-kpi.kiev.ua
Cc:  
Subject: Re: bin/171604: LD_PRELOAD set to not absolute path crashes rtld
Date: Thu, 13 Sep 2012 13:52:55 -0400

 --tVmo9FyGdCe4F4YN
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 Hi Andrey,
 
 Could you give the attached patch a try?
 
 Thanks,
 -Mark
 
 --tVmo9FyGdCe4F4YN
 Content-Type: text/x-diff; charset=us-ascii
 Content-Disposition: attachment; filename="rtld_crash.patch"
 
 diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
 index 050adbb..7272eea 100644
 --- a/libexec/rtld-elf/rtld.c
 +++ b/libexec/rtld-elf/rtld.c
 @@ -1471,8 +1471,9 @@ find_library(const char *xname, const Obj_Entry *refobj)
  	  (pathname = search_library_path(name, ld_library_path)) != NULL ||
  	  (objgiven &&
  	  (pathname = search_library_path(name, refobj->runpath)) != NULL) ||
 +	  (objgiven &&
  	  (pathname = search_library_path(name, gethints(refobj->z_nodeflib)))
 -	  != NULL ||
 +	  != NULL) ||
  	  (objgiven && !refobj->z_nodeflib &&
  	  (pathname = search_library_path(name, STANDARD_LIBRARY_PATH)) != NULL))
  	    return (pathname);
 
 --tVmo9FyGdCe4F4YN--

From: Andrey Simonenko <simon@comsys.ntu-kpi.kiev.ua>
To: bug-followup@FreeBSD.org
Cc: Mark Johnston <markjdb@gmail.com>
Subject: bin/171604: [patch] LD_PRELOAD set to not absolute path crashes rtld
Date: Fri, 14 Sep 2012 10:24:31 +0300

 Having applied this patch:
 
 % env LD_PRELOAD=libz.so.6 date
 Shared object "libz.so.6" not found
 % env LD_PRELOAD=/lin/libz.so.6 date
 ...
 
 ps: please send bug followup, I cannot receive messages sent to my address.

From: Mark Johnston <markjdb@gmail.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/171604: [patch] LD_PRELOAD set to not absolute path crashes
 rtld
Date: Sat, 15 Sep 2012 03:39:39 -0400

 --45Z9DzgjV8m4Oswq
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 Ok, so that fixed the segfault at least. I think the LD_PRELOAD handling
 is still incorrect. According to rtld(1), if LD_PRELOAD isn't an
 absolute path, then LD_LIBRARY_PATH and the standard library path
 (/lib:/usr/lib) should be searched. However, we're only searching
 LD_LIBRARY_PATH in this case at the moment:
 
 $ LD_PRELOAD=libc.so.7 ls
 Shared object "libc.so.7" not found
 $ LD_LIBRARY_PATH=/lib LD_PRELOAD=libc.so.7 ls
 <no errors>
 
 The attached patch addresses this problem as well.
 
 Thanks,
 -Mark
 
 --45Z9DzgjV8m4Oswq
 Content-Type: text/x-diff; charset=us-ascii
 Content-Disposition: attachment; filename="rtld_crash.patch"
 
 diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
 index 050adbb..bd6d33a 100644
 --- a/libexec/rtld-elf/rtld.c
 +++ b/libexec/rtld-elf/rtld.c
 @@ -1471,9 +1471,10 @@ find_library(const char *xname, const Obj_Entry *refobj)
  	  (pathname = search_library_path(name, ld_library_path)) != NULL ||
  	  (objgiven &&
  	  (pathname = search_library_path(name, refobj->runpath)) != NULL) ||
 +	  (objgiven &&
  	  (pathname = search_library_path(name, gethints(refobj->z_nodeflib)))
 -	  != NULL ||
 -	  (objgiven && !refobj->z_nodeflib &&
 +	  != NULL) ||
 +	  (((objgiven && !refobj->z_nodeflib) || !objgiven) &&
  	  (pathname = search_library_path(name, STANDARD_LIBRARY_PATH)) != NULL))
  	    return (pathname);
      }
 
 --45Z9DzgjV8m4Oswq--

From: Andrey Simonenko <simon@comsys.ntu-kpi.kiev.ua>
To: bug-followup@FreeBSD.org
Cc: Mark Johnston <markjdb@gmail.com>
Subject: bin/171604: [patch] LD_PRELOAD set to not absolute path crashes rtld
Date: Mon, 17 Sep 2012 18:30:53 +0300

 > Ok, so that fixed the segfault at least. I think the LD_PRELOAD handling
 > is still incorrect. According to rtld(1), if LD_PRELOAD isn't an
 > absolute path, then LD_LIBRARY_PATH and the standard library path
 > (/lib:/usr/lib) should be searched. However, we're only searching
 > LD_LIBRARY_PATH in this case at the moment:
 
 That manual page references to "built-in standard directories", but
 does not define what they are.  Previously LD_PRELOAD set to not absolute
 path worked even for /usr/local/lib (as I understand because of ldconfig
 called for that directory).  I notice that net/proxychains that worked
 before on RELENG_9 did not work now (it calls any program with
 LD_PRELOAD=libproxychains.so, just install it and check shell script
 at bin/proxychains).
 
 > The attached patch addresses this problem as well.
 
 Yes, it works for /lib at least.

From: Mark Johnston <markjdb@gmail.com>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: bin/171604: [patch] LD_PRELOAD set to not absolute path crashes
 rtld
Date: Tue, 18 Sep 2012 13:49:57 -0400

 --45Z9DzgjV8m4Oswq
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 > That manual page references to "built-in standard directories", but
 > does not define what they are. Previously LD_PRELOAD set to not absolute
 > path worked even for /usr/local/lib (as I understand because of ldconfig
 > called for that directory).
 
 I believe it refers to the 6th item in the search order described in
 rtld(1). So /lib and /usr/lib. But perhaps it also searched the
 directories in the hints file - I don't have access to a machine running
 9 or older at the moment, so I can't really check.
 
 Attached is yet another patch which restores that behaviour. But someone
 who's actually familiar with recent changes to rtld should probably be
 taking a look. =)
 
 --45Z9DzgjV8m4Oswq
 Content-Type: text/x-diff; charset=us-ascii
 Content-Disposition: attachment; filename="rtld_crash.patch"
 
 diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
 index 050adbb..8b541fd 100644
 --- a/libexec/rtld-elf/rtld.c
 +++ b/libexec/rtld-elf/rtld.c
 @@ -1471,9 +1471,12 @@ find_library(const char *xname, const Obj_Entry *refobj)
  	  (pathname = search_library_path(name, ld_library_path)) != NULL ||
  	  (objgiven &&
  	  (pathname = search_library_path(name, refobj->runpath)) != NULL) ||
 +	  (objgiven &&
  	  (pathname = search_library_path(name, gethints(refobj->z_nodeflib)))
 -	  != NULL ||
 -	  (objgiven && !refobj->z_nodeflib &&
 +	  != NULL) ||
 +	  (!objgiven &&
 +	  (pathname = search_library_path(name, gethints(false))) != NULL) ||
 +	  (((objgiven && !refobj->z_nodeflib) || !objgiven) &&
  	  (pathname = search_library_path(name, STANDARD_LIBRARY_PATH)) != NULL))
  	    return (pathname);
      }
 
 --45Z9DzgjV8m4Oswq--

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/171604: commit references a PR
Date: Wed, 19 Sep 2012 05:11:37 +0000 (UTC)

 Author: kib
 Date: Wed Sep 19 05:11:25 2012
 New Revision: 240686
 URL: http://svn.freebsd.org/changeset/base/240686
 
 Log:
   Do not reference z_nodeflib for !objgiven case, thus fixing LD_PRELOAD
   for a non-absolute path.
   
   PR:	bin/171604
   MFC after:	3 days
 
 Modified:
   head/libexec/rtld-elf/rtld.c
 
 Modified: head/libexec/rtld-elf/rtld.c
 ==============================================================================
 --- head/libexec/rtld-elf/rtld.c	Wed Sep 19 00:27:50 2012	(r240685)
 +++ head/libexec/rtld-elf/rtld.c	Wed Sep 19 05:11:25 2012	(r240686)
 @@ -1429,7 +1429,7 @@ find_library(const char *xname, const Ob
  {
      char *pathname;
      char *name;
 -    bool objgiven;
 +    bool nodeflib, objgiven;
  
      objgiven = refobj != NULL;
      if (strchr(xname, '/') != NULL) {	/* Hard coded pathname */
 @@ -1464,6 +1464,7 @@ find_library(const char *xname, const Ob
  	  (pathname = search_library_path(name, STANDARD_LIBRARY_PATH)) != NULL)
  	    return (pathname);
      } else {
 +	nodeflib = objgiven ? refobj->z_nodeflib : false;
  	if ((objgiven &&
  	  (pathname = search_library_path(name, refobj->rpath)) != NULL) ||
  	  (objgiven && refobj->runpath == NULL && refobj != obj_main &&
 @@ -1471,9 +1472,8 @@ find_library(const char *xname, const Ob
  	  (pathname = search_library_path(name, ld_library_path)) != NULL ||
  	  (objgiven &&
  	  (pathname = search_library_path(name, refobj->runpath)) != NULL) ||
 -	  (pathname = search_library_path(name, gethints(refobj->z_nodeflib)))
 -	  != NULL ||
 -	  (objgiven && !refobj->z_nodeflib &&
 +	  (pathname = search_library_path(name, gethints(nodeflib))) != NULL ||
 +	  (objgiven && !nodeflib &&
  	  (pathname = search_library_path(name, STANDARD_LIBRARY_PATH)) != NULL))
  	    return (pathname);
      }
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/171604: commit references a PR
Date: Sat, 22 Sep 2012 05:28:00 +0000 (UTC)

 Author: kib
 Date: Sat Sep 22 05:27:47 2012
 New Revision: 240801
 URL: http://svn.freebsd.org/changeset/base/240801
 
 Log:
   MFC r240686:
   Do not reference z_nodeflib for !objgiven case, thus fixing LD_PRELOAD
   for a non-absolute path.
   
   PR:	bin/171604
 
 Modified:
   stable/9/libexec/rtld-elf/rtld.c
 Directory Properties:
   stable/9/libexec/rtld-elf/   (props changed)
 
 Modified: stable/9/libexec/rtld-elf/rtld.c
 ==============================================================================
 --- stable/9/libexec/rtld-elf/rtld.c	Sat Sep 22 04:22:17 2012	(r240800)
 +++ stable/9/libexec/rtld-elf/rtld.c	Sat Sep 22 05:27:47 2012	(r240801)
 @@ -1429,7 +1429,7 @@ find_library(const char *xname, const Ob
  {
      char *pathname;
      char *name;
 -    bool objgiven;
 +    bool nodeflib, objgiven;
  
      objgiven = refobj != NULL;
      if (strchr(xname, '/') != NULL) {	/* Hard coded pathname */
 @@ -1464,6 +1464,7 @@ find_library(const char *xname, const Ob
  	  (pathname = search_library_path(name, STANDARD_LIBRARY_PATH)) != NULL)
  	    return (pathname);
      } else {
 +	nodeflib = objgiven ? refobj->z_nodeflib : false;
  	if ((objgiven &&
  	  (pathname = search_library_path(name, refobj->rpath)) != NULL) ||
  	  (objgiven && refobj->runpath == NULL && refobj != obj_main &&
 @@ -1471,9 +1472,8 @@ find_library(const char *xname, const Ob
  	  (pathname = search_library_path(name, ld_library_path)) != NULL ||
  	  (objgiven &&
  	  (pathname = search_library_path(name, refobj->runpath)) != NULL) ||
 -	  (pathname = search_library_path(name, gethints(refobj->z_nodeflib)))
 -	  != NULL ||
 -	  (objgiven && !refobj->z_nodeflib &&
 +	  (pathname = search_library_path(name, gethints(nodeflib))) != NULL ||
 +	  (objgiven && !nodeflib &&
  	  (pathname = search_library_path(name, STANDARD_LIBRARY_PATH)) != NULL))
  	    return (pathname);
      }
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: Mark Johnston <markjdb@gmail.com>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: bin/171604: [patch] LD_PRELOAD set to not absolute path crashes rtld
Date: Sat, 15 Dec 2012 01:21:48 -0500

 This PR can be closed. Note that the submitter asked that email not be
 sent to his address.
 
 Thanks,
 -Mark
State-Changed-From-To: open->closed 
State-Changed-By: eadler 
State-Changed-When: Sat Dec 15 06:31:53 UTC 2012 
State-Changed-Why:  
Committed. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=171604 
Responsible-Changed-From-To: freebsd-bugs->kib 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Sat Dec 15 06:32:17 UTC 2012 
Responsible-Changed-Why:  
over to committer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=171604 
>Unformatted:
