From jylefort@brutele.be  Wed Mar  9 20:58:41 2005
Return-Path: <jylefort@brutele.be>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id AB4F516A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  9 Mar 2005 20:58:41 +0000 (GMT)
Received: from gateway.lefort.net (212.68.242.177.brutele.be [212.68.242.177])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 2D38743D2D
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  9 Mar 2005 20:58:41 +0000 (GMT)
	(envelope-from jylefort@brutele.be)
Received: from jsite.lefort.net (jsite.lefort.net [192.168.1.2])
	by gateway.lefort.net (Postfix) with ESMTP id D017E549A
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  9 Mar 2005 21:58:39 +0100 (CET)
Received: by jsite.lefort.net (Postfix, from userid 1000)
	id 799348380; Wed,  9 Mar 2005 21:58:39 +0100 (CET)
Message-Id: <20050309205839.799348380@jsite.lefort.net>
Date: Wed,  9 Mar 2005 21:58:39 +0100 (CET)
From: Jean-Yves Lefort <jylefort@brutele.be>
Reply-To: Jean-Yves Lefort <jylefort@brutele.be>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] libmap should canonicalize pathnames before matching them against constraints
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         78646
>Category:       kern
>Synopsis:       [libmap] [patch] libmap should canonicalize pathnames before matching them against constraints
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Mar 09 21:00:09 GMT 2005
>Closed-Date:    
>Last-Modified:  Sun Oct 23 22:28:27 GMT 2005
>Originator:     Jean-Yves Lefort
>Release:        FreeBSD 5.3-RELEASE-p5 i386
>Organization:
>Environment:
System: FreeBSD jsite.lefort.net 5.3-RELEASE-p5 FreeBSD 5.3-RELEASE-p5 #0: Mon Feb 14 18:06:40 CET 2005 jylefort@jsite.lefort.net:/usr/obj/usr/src/sys/JSITE i386
>Description:
lm_find() should canonicalize the pathname it passes to lmp_find(), in
order to follow symbolic links, etc.
>How-To-Repeat:
[/foo1/bar.so]
lib.so	replacement.so

If /foo2/bar.so (a symlink to /foo1/bar.so) is dlopen()ed, the
libmap.conf mapping will not be honoured, because libmap matches
/foo2/bar.so instead of /foo1/bar.so.
>Fix:
--- libexec/rtld-elf/libmap.c.orig	Wed Mar  9 21:17:50 2005
+++ libexec/rtld-elf/libmap.c	Wed Mar  9 21:19:05 2005
@@ -8,6 +8,7 @@
 #include <stdlib.h>
 #include <sys/queue.h>
 #include <sys/param.h>
+#include <limits.h>
 
 #include "debug.h"
 #include "rtld.h"
@@ -200,15 +201,24 @@
 
 	dbg("%s(\"%s\", \"%s\")", __func__, p, f);
 
-	if (p != NULL && (lml = lmp_find(p)) != NULL) {
-		t = lml_find(lml, f);
-		if (t != NULL) {
-			/*
-			 * Add a global mapping if we have
-			 * a successful constrained match.
-			 */
-			lm_add(NULL, f, t);
-			return (t);
+	if (p != NULL) {
+		char *rp;
+		char rpbuf[PATH_MAX];
+
+		rp = realpath(p, rpbuf);
+		if (rp != NULL)
+			p = rp;
+
+		if ((lml = lmp_find(p)) != NULL) {
+			t = lml_find(lml, f);
+			if (t != NULL) {
+				/*
+				 * Add a global mapping if we have
+				 * a successful constrained match.
+				 */
+				lm_add(NULL, f, t);
+				return (t);
+			}
 		}
 	}
 	lml = lmp_find("$DEFAULT$");
>Release-Note:
>Audit-Trail:
>Unformatted:
