NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

port-arm/47081: Wrong offset and size in MBR partition on armeb.



>Number:         47081
>Category:       port-arm
>Synopsis:       Wrong offset and size in MBR partition on armeb.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    port-arm-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Oct 15 14:15:00 +0000 2012
>Originator:     SAITOH Masanobu
>Release:        all releases
>Organization:
>Environment:
1.6 and newer.
Architecture: armeb
Machine: evbarm
>Description:
        arm/arm/disksubr_mbr.c has a long standing bug that the offset
        and size of MBR partition table read as host byteorder.

        An example on armeb (NSLU2):
nslu2# disklabel sd0
# /dev/rsd0c:
type: SCSI
disk: USB Flash Disk
label: fictitious-MBR
flags: removable
bytes/sector: 512
sectors/track: 32
tracks/cylinder: 16
sectors/cylinder: 512
cylinders: 492
total sectors: 251904
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0           # microseconds
track-to-track seek: 0  # microseconds
drivedata: 0

8 partitions:
#        size    offset     fstype [fsize bsize cpg/sgs]
 c:    251904         0     unused      0     0        # (Cyl.      0 -    491)
 e: 262996736 1056964608      MSDOS                     # (Cyl. 2064384+- 
2578049+)
disklabel: boot block size 0
disklabel: super block size 0
disklabel: partition e: offset past end of unit
disklabel: partition e: partition extends past end of unit

>How-To-Repeat:
        Connect a USB disk which has MBR partition (MSDOS formatted)
        and do "disklabel sd0" or something.

>Fix:
        Patch:

Index: disksubr_mbr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/arm/disksubr_mbr.c,v
retrieving revision 1.13
diff -u -r1.13 disksubr_mbr.c
--- disksubr_mbr.c      2 Dec 2011 00:25:37 -0000       1.13
+++ disksubr_mbr.c      15 Oct 2012 14:09:18 -0000
@@ -128,6 +128,9 @@
          memcpy(mbrp, (char *)bp->b_data + MBR_PART_OFFSET,
                             MBR_PART_COUNT * sizeof(*mbrp));
 
+               LE32TOH(mbrp->mbrp_start);
+               LE32TOH(mbrp->mbrp_size);
+
                /* look for NetBSD partition */
                   ourmbrp = NULL;
                           for (i = 0; !ourmbrp && i < MBR_PART_COUNT; i++) {
@@ -249,6 +252,9 @@
          goto out;
          }
 
+       HTOLE32(ourmbrp->mbrp_start);
+       HTOLE32(ourmbrp->mbrp_size);
+
        /* need sector address for SCSI/IDE, cylinder for ESDI/ST506/RLL */
        mbrpartoff = ourmbrp->mbrp_start;
        cyl = MBR_PCYL(ourmbrp->mbrp_scyl, ourmbrp->mbrp_ssect);



Home | Main Index | Thread Index | Old Index