NetBSD Problem Report #54882

From martin@aprisoft.de  Tue Jan 21 19:46:16 2020
Return-Path: <martin@aprisoft.de>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id B27EA7A16B
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 21 Jan 2020 19:46:16 +0000 (UTC)
Message-Id: <20200121194608.47ED35CC8D0@emmas.aprisoft.de>
Date: Tue, 21 Jan 2020 20:46:08 +0100 (CET)
From: martin@NetBSD.org
Reply-To: martin@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: Stange default disklabels generated for non-512 byte disks
X-Send-Pr-Version: 3.95

>Number:         54882
>Category:       kern
>Synopsis:       Stange default disklabels generated for non-512 byte disks
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jan 21 19:50:00 +0000 2020
>Last-Modified:  Wed Jan 22 11:40:01 +0000 2020
>Originator:     Martin Husemann
>Release:        NetBSD 9.99.40
>Organization:
The NetBSD Foundation, Inc.
>Environment:
System: NetBSD seven-days-to-the-wolves.aprisoft.de 9.99.40 NetBSD 9.99.40 (GENERIC) #342: Tue Jan 21 08:31:04 CET 2020 martin@seven-days-to-the-wolves.aprisoft.de:/work/src/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:

Creating a vnd with 2048 byte sectors cause pretty strange fictious disklabels.

This confuses the heuristic in sysinst that is trying to tell a pure fictious
(empty) disklabel from something that either has a real disklabel on disk
or is generated via automatic conversion magic in the kernel from a foreign
partitioning scheme. It also looks bad and causes lots of overlapping
partition warnings.

>How-To-Repeat:

Create a file of zeros and configure a vnd on it, like:

-rw-r--r--  1 root  wheel  524288000 Jan 18 20:01 disk_small.img
 # vnconfig -c vnd0 disk_small.img 2048/32/16/256

and then check the disklabel:

# /dev/rvnd0:
type: vnd
disk: vnd
label: default label
flags:
bytes/sector: 2048
sectors/track: 32
tracks/cylinder: 16
sectors/cylinder: 512
cylinders: 256
total sectors: 256000
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0           # microseconds
track-to-track seek: 0  # microseconds
drivedata: 0 

16 partitions:
#        size    offset     fstype [fsize bsize cpg/sgs]
 a:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 b:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 c:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 d:    256000         0     unused      0     0        # (Cyl.      0 -    499)
 e:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 f:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 g:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 h:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 i:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 j:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 k:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 l:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 m:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 n:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 o:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 p:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)


>Fix:
n/a

>Audit-Trail:
From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/54882 CVS commit: src/usr.sbin/sysinst
Date: Tue, 21 Jan 2020 20:04:30 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Tue Jan 21 20:04:30 UTC 2020

 Modified Files:
 	src/usr.sbin/sysinst: disklabel.c

 Log Message:
 Deal with even stranger fictious empty disklabels (PR kern/54882).


 To generate a diff of this commit:
 cvs rdiff -u -r1.32 -r1.33 src/usr.sbin/sysinst/disklabel.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: mlelstv@serpens.de (Michael van Elst)
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/54882: Stange default disklabels generated for non-512 byte disks
Date: Wed, 22 Jan 2020 09:35:48 -0000 (UTC)

 martin@NetBSD.org writes:

 >Creating a vnd with 2048 byte sectors cause pretty strange fictious disklabels.

 >Create a file of zeros and configure a vnd on it, like:
 >-rw-r--r--  1 root  wheel  524288000 Jan 18 20:01 disk_small.img
 > # vnconfig -c vnd0 disk_small.img 2048/32/16/256
 >and then check the disklabel:

 >16 partitions:
 >#        size    offset     fstype [fsize bsize cpg/sgs]
 > a:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 > b:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 > c:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 > d:    256000         0     unused      0     0        # (Cyl.      0 -    499)
 > e:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 > f:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 > g:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 > h:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 > i:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 > j:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 > k:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 > l:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 > m:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 > n:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 > o:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)
 > p:    256000         0     4.2BSD      0     0     0  # (Cyl.      0 -    499)


 That's historical behaviour of vnd.

 However, it only occurs when reading a disklabel fails in opposite to
 reading the disk successfully but finding no disklabel. In this
 case, no error is returned by readdisklabel().

 That part apparently is not so "historical" as the code talks about
 "lack of disklabel is common" and "lack of disklabel" does not
 trigger that behaviour.

 You should see an error message printed by the kernel why readdisklabel()
 failed.

 Does this happen with a 4k (not 512e) disk for the underlying filesystem ?

 -- 
 -- 
                                 Michael van Elst
 Internet: mlelstv@serpens.de
                                 "A potential Snark may lurk in every tree."

From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/54882: Stange default disklabels generated for non-512 byte
 disks
Date: Wed, 22 Jan 2020 10:46:37 +0100

 On Wed, Jan 22, 2020 at 09:40:02AM +0000, Michael van Elst wrote:
 >  That part apparently is not so "historical" as the code talks about
 >  "lack of disklabel is common" and "lack of disklabel" does not
 >  trigger that behaviour.
 >  
 >  You should see an error message printed by the kernel why readdisklabel()
 >  failed.

 Duh - indeed. There was a bogus MBR in the image file:

 vnd0: mbr partition exceeds disk size

 removing that makes the symptom go away and I get a "sane" fictious label
 (only a and d partition).

 >  Does this happen with a 4k (not 512e) disk for the underlying filesystem ?

 No, the filsystem is on a 512 byte block disk.

 Martin

From: mlelstv@serpens.de (Michael van Elst)
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/54882: Stange default disklabels generated for non-512 byte disks
Date: Wed, 22 Jan 2020 11:37:00 -0000 (UTC)

 martin@duskware.de (Martin Husemann) writes:

 > >  You should see an error message printed by the kernel why readdisklabel()
 > >  failed.
 > 
 > Duh - indeed. There was a bogus MBR in the image file:
 > vnd0: mbr partition exceeds disk size

 Awful heuristics in subr_disk_mbr.c.

 Without MBR it would search for a disklabel at the disk start and return
 no error when none is found.

 With a valid MBR it would search for a disklabel in a NetBSD partition and
 return no error when none is found.

 With an invalid MBR it still looks for a disklabel at the disk start, but
 now it returns an error when none is found.

 With no disklabel read and no error you get a conventional default label,
 with error you get the "historic" label.

 The historic behaviour in vnd should be removed, then it can also be
 refactored to use common disk driver code.

 And the heuristics for finding a disklabel should be simplified. But
 don't ask me who still relies on them and then needs to move.

 -- 
 -- 
                                 Michael van Elst
 Internet: mlelstv@serpens.de
                                 "A potential Snark may lurk in every tree."

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.