NetBSD Problem Report #36609

From martin@duskware.de  Thu Jul  5 20:40:33 2007
Return-Path: <martin@duskware.de>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id D9BC163B8C9
	for <gnats-bugs@gnats.netbsd.org>; Thu,  5 Jul 2007 20:40:32 +0000 (UTC)
Message-Id: <20070705192202.007DF63B89E@narn.NetBSD.org>
Date: Thu,  5 Jul 2007 19:22:02 +0000 (UTC)
From: zeurkous@nichten.info
Reply-To: zeurkous@nichten.info
To: netbsd-bugs-owner@NetBSD.org
Subject: Fix {fdisk,disklabel}(8) device path parsing
X-Send-Pr-Version: www-1.0

>Number:         36609
>Category:       bin
>Synopsis:       Fix {fdisk,disklabel}(8) device path parsing
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jul 05 20:45:00 +0000 2007
>Closed-Date:    Sun Dec 30 01:07:18 +0000 2007
>Last-Modified:  Sun Dec 30 01:07:18 +0000 2007
>Originator:     De Zeurkous
>Release:        NetBSD-3.1/i386
>Organization:
NichtNet
>Environment:
NetBSD lichee.nichten.info 3.1 NetBSD 3.1 (GENERIC) #0: Tue Oct 31 04:27:07 UTC 2006  builds@b0.netbsd.org:/home/builds/ab/netbsd-3-1-RELEASE/i386/200610302053Z-obj/home/builds/ab/netbsd-3-1-RELEASE/src/sys/arch/i386/compile/GENERIC i386
>Description:
Obvious from other input.
>How-To-Repeat:
lichee# pwd
/root
lichee# ls -l | grep 'wd2'
drwxr-xr-x  2 root  wheel   512 Jul  5 18:42 wd2
lichee# disklabel wd2
disklabel: Invalid signature in mbr record 0
disklabel: ioctl DIOCGDINFO: Inappropriate ioctl for device
lichee# fdisk wd2
fdisk: DIOCGDEFLABEL: Inappropriate ioctl for device
fdisk: DIOCGDINFO: Inappropriate ioctl for device
lichee# disklabel wd2d
[snip correct output]
lichee# fdisk wd2d
[snip correct output]
lichee# ( cd / && disklabel wd2; )
[snip correct output]
lichee# ( cd / && fdisk wd2; )
[snip correct output]
>Fix:
My proposal for a fix is to only parse explicit paths:

example# pwd
/root
example# ls -l | grep 'wd2'
drwxr-xr-x  2 root  wheel   512 Jul  5 18:42 wd2
example# disklabel wd2
[snip correct output]
example# fdisk wd2
[snip correct output]
example# disklabel ./wd2
disklabel: Invalid signature in mbr record 0
disklabel: ioctl DIOCGDINFO: Inappropriate ioctl for device
lichee# fdisk ./wd2
fdisk: DIOCGDEFLABEL: Inappropriate ioctl for device
fdisk: DIOCGDINFO: Inappropriate ioctl for device

Detection can obviously be arranged by grepping the argument for a '/'.

>Release-Note:

>Audit-Trail:
From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org
Cc: 
Subject: Re: bin/36609: Fix {fdisk,disklabel}(8) device path parsing
Date: Thu, 5 Jul 2007 16:51:01 -0400

 On Jul 5,  8:45pm, zeurkous@nichten.info (zeurkous@nichten.info) wrote:
 -- Subject: bin/36609: Fix {fdisk,disklabel}(8) device path parsing

 | >Number:         36609
 | >Category:       bin
 | >Synopsis:       Fix {fdisk,disklabel}(8) device path parsing
 | >Confidential:   no
 | >Severity:       non-critical
 | >Priority:       low
 | >Responsible:    bin-bug-people
 | >State:          open
 | >Class:          sw-bug
 | >Submitter-Id:   net
 | >Arrival-Date:   Thu Jul 05 20:45:00 +0000 2007
 | >Originator:     De Zeurkous
 | >Release:        NetBSD-3.1/i386
 | >Organization:
 | NichtNet
 | >Environment:
 | NetBSD lichee.nichten.info 3.1 NetBSD 3.1 (GENERIC) #0: Tue Oct 31 04:27:07 UTC 2006  builds@b0.netbsd.org:/home/builds/ab/netbsd-3-1-RELEASE/i386/200610302053Z-obj/home/builds/ab/netbsd-3-1-RELEASE/src/sys/arch/i386/compile/GENERIC i386
 | >Description:
 | Obvious from other input.
 | >How-To-Repeat:
 | lichee# pwd
 | /root
 | lichee# ls -l | grep 'wd2'
 | drwxr-xr-x  2 root  wheel   512 Jul  5 18:42 wd2
 | lichee# disklabel wd2
 | disklabel: Invalid signature in mbr record 0
 | disklabel: ioctl DIOCGDINFO: Inappropriate ioctl for device
 | lichee# fdisk wd2
 | fdisk: DIOCGDEFLABEL: Inappropriate ioctl for device
 | fdisk: DIOCGDINFO: Inappropriate ioctl for device
 | lichee# disklabel wd2d
 | [snip correct output]
 | lichee# fdisk wd2d
 | [snip correct output]
 | lichee# ( cd / && disklabel wd2; )
 | [snip correct output]
 | lichee# ( cd / && fdisk wd2; )
 | [snip correct output]
 | >Fix:
 | My proposal for a fix is to only parse explicit paths:
 | 
 | example# pwd
 | /root
 | example# ls -l | grep 'wd2'
 | drwxr-xr-x  2 root  wheel   512 Jul  5 18:42 wd2
 | example# disklabel wd2
 | [snip correct output]
 | example# fdisk wd2
 | [snip correct output]
 | example# disklabel ./wd2
 | disklabel: Invalid signature in mbr record 0
 | disklabel: ioctl DIOCGDINFO: Inappropriate ioctl for device
 | lichee# fdisk ./wd2
 | fdisk: DIOCGDEFLABEL: Inappropriate ioctl for device
 | fdisk: DIOCGDINFO: Inappropriate ioctl for device
 | 
 | Detection can obviously be arranged by grepping the argument for a '/'.

 Although what you proposed satisfies POLA, it is un-unix-like to parse and
 treat filenames specially, when filenames are accepted. Here the mistake
 was made when for convenience wd2 was magically rewritten to /dev/rwd2{c,d}.
 We could even do one better and stat the file to see if it is a directory,
 and then auto-process the device file... I am not sure I like all this
 magic though; at least it is centralized in opendisk(3).

 christos

From: "De Zeurkous" <zeurkous@nichten.info>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: FU: bin/36609: Fix {fdisk,disklabel}(8) device path parsing
Date: Thu, 5 Jul 2007 20:52:08 -0000 (UTC)

 The final 'lichee#' should have been 'example#' -- my apologies.

 --De Zeurkous.

 On Thu, July 5, 2007 20:45, gnats-admin@NetBSD.org wrote:
 > Thank you very much for your problem report.
 > It has the internal identification `bin/36609'.
 > The individual assigned to look at your
 > report is: bin-bug-people.
 >
 >>Category:       bin
 >>Responsible:    bin-bug-people
 >>Synopsis:       Fix {fdisk,disklabel}(8) device path parsing
 >>Arrival-Date:   Thu Jul 05 20:45:00 +0000 2007
 >
 >


From: "De Zeurkous" <zeurkous@nichten.info>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: RE: bin/36609: Fix {fdisk,disklabel}(8) device path parsing
Date: Thu, 5 Jul 2007 21:11:12 -0000 (UTC)

 On Thu, July 5, 2007 20:55, Christos Zoulas wrote:
 > The following reply was made to PR bin/36609; it has been noted by GNATS.
 >
 > From: christos@zoulas.com (Christos Zoulas)
 > To: gnats-bugs@NetBSD.org, gnats-admin@netbsd.org,
 > 	netbsd-bugs@netbsd.org
 > Cc:
 > Subject: Re: bin/36609: Fix {fdisk,disklabel}(8) device path parsing
 > Date: Thu, 5 Jul 2007 16:51:01 -0400
 >
 >  On Jul 5,  8:45pm, zeurkous@nichten.info (zeurkous@nichten.info) wrote:
 >  -- Subject: bin/36609: Fix {fdisk,disklabel}(8) device path parsing
 >
 >[snip]
 >
 >  Although what you proposed satisfies POLA, it is un-unix-like to parse
 > and
 >  treat filenames specially, when filenames are accepted. Here the mistake
 >  was made when for convenience wd2 was magically rewritten to
 > /dev/rwd2{c,d}.

 Actually, I like this behavior. Besides, we better look beyond UNIX or
 it'll never evolve :)

 >  We could even do one better and stat the file to see if it is a
 > directory,
 >  and then auto-process the device file...

 Hmm, I should have been a bit more clear -- the fact that it was a
 directory is irrelevant to the problem.

 > I am not sure I like all this
 >  magic though; at least it is centralized in opendisk(3).

 Personally, since tools like disklabel(8) are pretty low-level (they play
 a vital role in making the disk adressable in luserspace), I parse it as
 addressing the device itself instead of the node. That's why it makes
 sense to me.

 --De Zeurkous.

 >
 >  christos
 >
 >

From: Alan Barrett <apb@cequrux.com>
To: gnats-bugs@NetBSD.org, gnats-admin@NetBSD.org,
	netbsd-bugs@NetBSD.org
Cc: 
Subject: Re: bin/36609: Fix {fdisk,disklabel}(8) device path parsing
Date: Fri, 6 Jul 2007 00:19:50 +0200

 On Thu, 05 Jul 2007, Christos Zoulas wrote:
 > Although what you proposed satisfies POLA, it is un-unix-like to parse and
 > treat filenames specially, when filenames are accepted.

 I think that opendisk(3) should do something like

 	/* assume it's a disk name, until proven otherwise */
 	if (arg contains "/") {
 		interpret it as a file name;
 		do not fall back to any other interpretation;
 	} else {
 		try various combinations of /dev/{,r}foo{,rawpart};
 		if that fails, try interpreting it as a file name;
 	}

 In this scheme, users who want "./wd2" can ask for that explicitly,
 while users who want "/dev/rwd2d" (where "d" is the raw partition) can
 ask for any of "wd2", "wd2d", or "/dev/rwd2d".

 I don't think it's un-unix-like for an interface that's intended to open
 a "disk" to interpreting its argument as a disk name in preference to a
 file name.

 --apb (Alan Barrett)

From: "De Zeurkous" <zeurkous@nichten.info>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: RE: bin/36609: Fix {fdisk,disklabel}(8) device path parsing
Date: Fri, 6 Jul 2007 13:03:32 -0000 (UTC)

 On Fri, July 6, 2007 06:35, Alan Barrett wrote:
 > The following reply was made to PR bin/36609; it has been noted by GNATS.
 >
 > From: Alan Barrett <apb@cequrux.com>
 > To: gnats-bugs@NetBSD.org, gnats-admin@NetBSD.org,
 > 	netbsd-bugs@NetBSD.org
 > Cc:
 > Subject: Re: bin/36609: Fix {fdisk,disklabel}(8) device path parsing
 > Date: Fri, 6 Jul 2007 00:19:50 +0200
 >
 >  On Thu, 05 Jul 2007, Christos Zoulas wrote:
 >[snip]
 >
 >  In this scheme, users who want "./wd2" can ask for that explicitly,
 >  while users who want "/dev/rwd2d" (where "d" is the raw partition) can
 >  ask for any of "wd2", "wd2d", or "/dev/rwd2d".

 Note that this solution does not take into account recursive /dev
 configurations (also my bad). Propose to check if path begins with '/' or
 './' instead. Automaged processes are of course strongly encouraged to use
 the device file in the first place; this magic is strictly intended for
 admin convenience.

 >
 >  I don't think it's un-unix-like for an interface that's intended to open
 >  a "disk" to interpreting its argument as a disk name in preference to a
 >  file name.

 No, but it is un-UNIX-like to ask for a disk identifier instead of the
 corresponding device file in the first place. Note that I do not oppose
 this behavior; see my earlier reply.

 --De Zeurkous.

 >
 >  --apb (Alan Barrett)
 >
 >

State-Changed-From-To: open->closed
State-Changed-By: jmcneill@netbsd.org
State-Changed-When: Sun, 30 Dec 2007 01:07:18 +0000
State-Changed-Why:
Closed at the request of the submitter.


>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-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.