Subject: port-sparc/2598: [dM] everything before sd*a is read-only
To: None <gnats-bugs@NetBSD.ORG>
From: der Mouse <mouse@Collatz.McRCIM.McGill.EDU>
List: netbsd-bugs
Date: 07/02/1996 17:52:04
>Number:         2598
>Category:       port-sparc
>Synopsis:       [dM] everything before sd*a is read-only
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    gnats-admin (GNATS administrator)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jul  2 18:05:03 1996
>Last-Modified:
>Originator:     der Mouse
>Organization:
	Dis-
>Release:        -current sup (ie, 1.2 release branch), 0610 and 0702.
>Environment:
	IPC, but it doesn't matter
>Description:
	Due to some weirdness in bounds_check_with_label(),
	arch/sparc/sparc/disksubr.c, everything before the beginning of
	the a partition on the disk is read-only (except when accessed
	via RAW_PART).
>How-To-Repeat:
	Repartition so that the a partition begins not at cylinder
	zero, with some other partition before it.  Try to write to the
	"other partition".  (If it's swap, you'll get the
	"swap_pager_clean" complaints port-sparc has seen reported.)
>Fix:
	Here's what I'm running with.  It certainly fixes the
	swap_pager_clean complaints; I haven't tested it in detail.

--- OLD/sys/arch/sparc/sparc/disksubr.c	Thu Jan  1 00:00:00 1970
+++ NEW/sys/arch/sparc/sparc/disksubr.c	Thu Jan  1 00:00:00 1970
@@ -285,14 +285,16 @@
 #define dkpart(dev) (minor(dev) & 7)
 
 	struct partition *p = lp->d_partitions + dkpart(bp->b_dev);
-	int labelsect = lp->d_partitions[0].p_offset;
 	int maxsz = p->p_size;
 	int sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT;
 
 	/* overwriting disk label ? */
 	/* XXX should also protect bootstrap in first 8K */
-	if (bp->b_blkno + p->p_offset <= LABELSECTOR + labelsect &&
-	    (bp->b_flags & B_READ) == 0 && wlabel == 0) {
+	/* XXX this assumes everything <=LABELSECTOR is label! */
+	/*     But since LABELSECTOR is 0, that's ok for now. */
+	if ( (bp->b_blkno + p->p_offset <= LABELSECTOR) &&
+	     ((bp->b_flags & B_READ) == 0) &&
+	     (wlabel == 0) ) {
 		bp->b_error = EROFS;
 		goto bad;
 	}

					der Mouse

			    mouse@collatz.mcrcim.mcgill.edu
		    01 EE 31 F6 BB 0C 34 36  00 F3 7C 5A C1 A0 67 1D
>Audit-Trail:
>Unformatted: