From nobody@FreeBSD.org  Sun Nov 13 14:45:13 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 92B381065672
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 13 Nov 2011 14:45:13 +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 828948FC0A
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 13 Nov 2011 14:45:13 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id pADEjDiY028781
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 13 Nov 2011 14:45:13 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id pADEjD41028754;
	Sun, 13 Nov 2011 14:45:13 GMT
	(envelope-from nobody)
Message-Id: <201111131445.pADEjD41028754@red.freebsd.org>
Date: Sun, 13 Nov 2011 14:45:13 GMT
From: Robert Millan <rmh@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [zfs] "zpool import" relies on buggy realpath() behaviour
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         162519
>Category:       kern
>Synopsis:       [zfs] "zpool import" relies on buggy realpath() behaviour
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-fs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Nov 13 14:50:07 UTC 2011
>Closed-Date:    
>Last-Modified:  Sun Nov 13 20:30:00 UTC 2011
>Originator:     Robert Millan
>Release:        Debian GNU/kFreeBSD "sid"
>Organization:
>Environment:
>Description:
zpool_find_import_impl() in cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c
is relying on buggy realpath() behaviour.

FreeBSD realpath() does not currently conform to SUS specification (see
PR 128933). It returns succesfully for invalid paths for which it should
return ENOENT.

The code in zpool will stop working correctly when this bug is fixed:

  - By default zpool_find_import_impl() operates on "/dev/dsk/" directory,
    which on FreeBSD doesn't exist.

  - It begins by attempting to canonicalize this path using realpath().
    This should fail with ENOENT and abort execution, but realpath()
    returns succesfully.

  - It then proceeds to replace "/dev/dsk/" with "/dev/".

  - Finally it opens devices from the (now correct) directory and imports
    them.

>How-To-Repeat:

>Fix:
The correct solution IMHO is to replace all instances of "/dev/dsk/" with
"/dev/". However this could be undesirable wrt new code imports.

Other possibilities could be to move the 'rdsk = "/dev/";' correction up
so that it happens before realpath() call, or to add "errno != ENOENT"
requirement before aborting with error.


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-fs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sun Nov 13 20:28:39 UTC 2011 
Responsible-Changed-Why:  
Over to maintainer(s). 

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