diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2009-06-14 00:09:41 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2009-06-14 00:09:41 +0000 |
commit | 02a365840c38e842976e2e6bfb8a24990aaa23e6 (patch) | |
tree | 40b28e93438bd0c49cdee7b2a2acc9bdab782d28 | |
parent | 7e97643755bb45a839c99309ba46c6c5b31c0669 (diff) |
Don't mess with the bounds in the lp if *partoffp is non-NULL, since this
indicates that writedisklabel is trying to find the location for writing
the label. If the lp is messed with, an invalid checksum is written.
done with miod and kettenis, lots of moaning and gnashing of teeth, etc
-rw-r--r-- | sys/arch/hppa/hppa/disksubr.c | 25 | ||||
-rw-r--r-- | sys/arch/hppa/include/disklabel.h | 4 | ||||
-rw-r--r-- | sys/arch/hppa64/hppa64/disksubr.c | 25 | ||||
-rw-r--r-- | sys/arch/hppa64/include/disklabel.h | 4 | ||||
-rw-r--r-- | sys/arch/macppc/macppc/disksubr.c | 10 | ||||
-rw-r--r-- | sys/arch/sgi/sgi/disksubr.c | 19 | ||||
-rw-r--r-- | sys/arch/socppc/socppc/disksubr.c | 11 | ||||
-rw-r--r-- | sys/kern/subr_disk.c | 12 |
8 files changed, 66 insertions, 44 deletions
diff --git a/sys/arch/hppa/hppa/disksubr.c b/sys/arch/hppa/hppa/disksubr.c index df0df856259..962dc450a6a 100644 --- a/sys/arch/hppa/hppa/disksubr.c +++ b/sys/arch/hppa/hppa/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.73 2009/06/04 21:13:01 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.74 2009/06/14 00:09:37 deraadt Exp $ */ /* * Copyright (c) 1999 Michael Shalayeff @@ -102,7 +102,7 @@ readliflabel(struct buf *bp, void (*strat)(struct buf *), struct lifdir *p; struct lifvol *lvp; char *msg = NULL; - int fsoff = 0, i; + int fsoff = 0, openbsdstart = MAXLIFSPACE, i; /* read LIF volume header */ bp->b_blkno = btodb(LIF_VOLSTART); @@ -113,8 +113,10 @@ readliflabel(struct buf *bp, void (*strat)(struct buf *), return "LIF volume header I/O error"; lvp = (struct lifvol *)bp->b_data; - if (lvp->vol_id != LIF_VOL_ID) + if (lvp->vol_id != LIF_VOL_ID) { + openbsdstart = 0; goto finished; + } dbp = geteblk(LIF_DIRSIZE); dbp->b_dev = bp->b_dev; @@ -127,6 +129,7 @@ readliflabel(struct buf *bp, void (*strat)(struct buf *), if (biowait(dbp)) { msg = "LIF directory I/O error"; + openbsdstart = 0; goto done; } @@ -138,11 +141,12 @@ readliflabel(struct buf *bp, void (*strat)(struct buf *), if (p->dir_type == LIF_DIR_FS) { fsoff = lifstodb(p->dir_addr); + openbsdstart = 0; goto finished; } /* Only came here to find the offset... */ - if (partoffp && spoofonly) + if (partoffp) goto finished; if (p->dir_type == LIF_DIR_HPLBL) { @@ -210,12 +214,15 @@ readliflabel(struct buf *bp, void (*strat)(struct buf *), } finished: + /* record the OpenBSD partition's placement for the caller */ if (partoffp) *partoffp = fsoff; + else { + DL_SETBSTART(lp, openbsdstart); + DL_SETBEND(lp, DL_GETDSIZE(lp)); /* XXX */ + } - DL_SETBSTART(lp, fsoff); - DL_SETBEND(lp, DL_GETDSIZE(lp)); /* XXX */ - + /* don't read the on-disk label if we are in spoofed-only mode */ if (spoofonly) goto done; @@ -223,14 +230,12 @@ finished: bp->b_bcount = lp->d_secsize; bp->b_flags = B_BUSY | B_READ | B_RAW; (*strat)(bp); - - /* if successful, locate disk label within block and validate */ if (biowait(bp)) { msg = "disk label I/O error"; goto done; } - return checkdisklabel(bp->b_data + LABELOFFSET, lp, fsoff, + return checkdisklabel(bp->b_data + LABELOFFSET, lp, openbsdstart, DL_GETDSIZE(lp)); /* XXX */ done: diff --git a/sys/arch/hppa/include/disklabel.h b/sys/arch/hppa/include/disklabel.h index 701535bf4c2..6f1b84abbe6 100644 --- a/sys/arch/hppa/include/disklabel.h +++ b/sys/arch/hppa/include/disklabel.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.h,v 1.21 2007/06/20 18:15:45 deraadt Exp $ */ +/* $OpenBSD: disklabel.h,v 1.22 2009/06/14 00:09:39 deraadt Exp $ */ /* * Copyright (c) 1994 Christopher G. Demetriou @@ -126,4 +126,6 @@ struct hpux_label { #define lifstob(s) ((s) * LIF_SECTSIZE) #define lifstodb(s) ((s) * LIF_SECTSIZE / DEV_BSIZE) +#define MAXLIFSPACE 256 /* 512 byte blocks */ + #endif /* _MACHINE_DISKLABEL_H_ */ diff --git a/sys/arch/hppa64/hppa64/disksubr.c b/sys/arch/hppa64/hppa64/disksubr.c index 0b94e410e86..65df5fbe288 100644 --- a/sys/arch/hppa64/hppa64/disksubr.c +++ b/sys/arch/hppa64/hppa64/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.57 2009/06/11 18:54:13 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.58 2009/06/14 00:09:38 deraadt Exp $ */ /* * Copyright (c) 1999 Michael Shalayeff @@ -102,7 +102,7 @@ readliflabel(struct buf *bp, void (*strat)(struct buf *), struct lifdir *p; struct lifvol *lvp; char *msg = NULL; - int fsoff = 0, i; + int fsoff = 0, openbsdstart = MAXLIFSPACE, i; /* read LIF volume header */ bp->b_blkno = btodb(LIF_VOLSTART); @@ -113,8 +113,10 @@ readliflabel(struct buf *bp, void (*strat)(struct buf *), return "LIF volume header I/O error"; lvp = (struct lifvol *)bp->b_data; - if (lvp->vol_id != LIF_VOL_ID) + if (lvp->vol_id != LIF_VOL_ID) { + openbsdstart = 0; goto finished; + } dbp = geteblk(LIF_DIRSIZE); dbp->b_dev = bp->b_dev; @@ -127,6 +129,7 @@ readliflabel(struct buf *bp, void (*strat)(struct buf *), if (biowait(dbp)) { msg = "LIF directory I/O error"; + openbsdstart = 0; goto done; } @@ -138,11 +141,12 @@ readliflabel(struct buf *bp, void (*strat)(struct buf *), if (p->dir_type == LIF_DIR_FS) { fsoff = lifstodb(p->dir_addr); + openbsdstart = 0; goto finished; } /* Only came here to find the offset... */ - if (partoffp && spoofonly) + if (partoffp) goto finished; if (p->dir_type == LIF_DIR_HPLBL) { @@ -210,12 +214,15 @@ readliflabel(struct buf *bp, void (*strat)(struct buf *), } finished: + /* record the OpenBSD partition's placement for the caller */ if (partoffp) *partoffp = fsoff; + else { + DL_SETBSTART(lp, openbsdstart); + DL_SETBEND(lp, DL_GETDSIZE(lp)); /* XXX */ + } - DL_SETBSTART(lp, fsoff); - DL_SETBEND(lp, DL_GETDSIZE(lp)); /* XXX */ - + /* don't read the on-disk label if we are in spoofed-only mode */ if (spoofonly) goto done; @@ -223,14 +230,12 @@ finished: bp->b_bcount = lp->d_secsize; bp->b_flags = B_BUSY | B_READ | B_RAW; (*strat)(bp); - - /* if successful, locate disk label within block and validate */ if (biowait(bp)) { msg = "disk label I/O error"; goto done; } - return checkdisklabel(bp->b_data + LABELOFFSET, lp, fsoff, + return checkdisklabel(bp->b_data + LABELOFFSET, lp, openbsdstart, DL_GETDSIZE(lp)); /* XXX */ done: diff --git a/sys/arch/hppa64/include/disklabel.h b/sys/arch/hppa64/include/disklabel.h index bad291819a3..df4a61d87e9 100644 --- a/sys/arch/hppa64/include/disklabel.h +++ b/sys/arch/hppa64/include/disklabel.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.h,v 1.15 2007/06/20 18:15:45 deraadt Exp $ */ +/* $OpenBSD: disklabel.h,v 1.16 2009/06/14 00:09:39 deraadt Exp $ */ /* * Copyright (c) 1994 Christopher G. Demetriou @@ -126,4 +126,6 @@ struct hpux_label { #define lifstob(s) ((s) * LIF_SECTSIZE) #define lifstodb(s) ((s) * LIF_SECTSIZE / DEV_BSIZE) +#define MAXLIFSPACE 256 /* 512 byte blocks */ + #endif /* _MACHINE_DISKLABEL_H_ */ diff --git a/sys/arch/macppc/macppc/disksubr.c b/sys/arch/macppc/macppc/disksubr.c index 8e938218694..f9a51272109 100644 --- a/sys/arch/macppc/macppc/disksubr.c +++ b/sys/arch/macppc/macppc/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.64 2009/06/13 16:28:23 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.65 2009/06/14 00:09:38 deraadt Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -144,12 +144,14 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *), if (strcmp(part->pmPartType, PART_TYPE_OPENBSD) == 0) { hfspartoff = part->pmPyPartStart - LABELSECTOR; hfspartend = hfspartoff + part->pmPartBlkCnt; - DL_SETBSTART(lp, hfspartoff); - DL_SETBEND(lp, hfspartend < DL_GETDSIZE(lp) ? hfspartend : - DL_GETDSIZE(lp)); if (partoffp) { *partoffp = hfspartoff; return (NULL); + } else { + DL_SETBSTART(lp, hfspartoff); + DL_SETBEND(lp, + hfspartend < DL_GETDSIZE(lp) ? hfspartend : + DL_GETDSIZE(lp)); } continue; } diff --git a/sys/arch/sgi/sgi/disksubr.c b/sys/arch/sgi/sgi/disksubr.c index 481fa2df5fc..534a579fced 100644 --- a/sys/arch/sgi/sgi/disksubr.c +++ b/sys/arch/sgi/sgi/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.15 2009/06/05 09:12:25 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.16 2009/06/14 00:09:39 deraadt Exp $ */ /* * Copyright (c) 1999 Michael Shalayeff @@ -120,9 +120,6 @@ readsgilabel(struct buf *bp, void (*strat)(struct buf *), u_int fsend; int offset; - if (partoffp) - *partoffp = fsoffs; - bp->b_blkno = 0; bp->b_bcount = lp->d_secsize; bp->b_flags = B_BUSY | B_READ | B_RAW; @@ -145,10 +142,7 @@ readsgilabel(struct buf *bp, void (*strat)(struct buf *), fsoffs = dlp->partitions[0].first * (dlp->dp.dp_secbytes / DEV_BSIZE); fsend = fsoffs + dlp->partitions[0].blocks * (dlp->dp.dp_secbytes / DEV_BSIZE); - /* - * If the disklabel is about to be written to disk, don't modify it! - * just bail out. - */ + /* Only came here to find the offset... */ if (partoffp) { *partoffp = fsoffs; goto finished; @@ -199,6 +193,15 @@ readsgilabel(struct buf *bp, void (*strat)(struct buf *), lp->d_checksum = dkcksum(lp); finished: + /* record the OpenBSD partition's placement for the caller */ + if (partoffp) + *partoffp = fsoffs; + else { + DL_SETBSTART(lp, fsoffs); + DL_SETBEND(lp, fsend); + } + + /* don't read the on-disk label if we are in spoofed-only mode */ if (spoofonly) goto done; diff --git a/sys/arch/socppc/socppc/disksubr.c b/sys/arch/socppc/socppc/disksubr.c index c7c459d0a64..380732c4cb8 100644 --- a/sys/arch/socppc/socppc/disksubr.c +++ b/sys/arch/socppc/socppc/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.7 2009/06/05 00:41:13 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.8 2009/06/14 00:09:39 deraadt Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -147,6 +147,11 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *), if (partoffp) { *partoffp = hfspartoff; return (NULL); + } else { + DL_SETBSTART(lp, hfspartoff); + DL_SETBEND(lp, + hfspartend < DL_GETDSIZE(lp) ? hfspartend : + DL_GETDSIZE(lp)); } continue; } @@ -162,10 +167,6 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *), pp->p_fstype = FS_HFS; n++; } - - DL_SETBSTART(lp, hfspartoff); - DL_SETBEND(lp, hfspartend < DL_GETDSIZE(lp) ? hfspartend : - DL_GETDSIZE(lp)); } if (hfspartoff == -1) diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index 2508c186ce1..d33a152d299 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_disk.c,v 1.93 2009/06/05 00:41:13 deraadt Exp $ */ +/* $OpenBSD: subr_disk.c,v 1.94 2009/06/14 00:09:40 deraadt Exp $ */ /* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */ /* @@ -575,16 +575,18 @@ donot: lp->d_partitions['i' - 'a'].p_fstype = FS_MSDOS; } notfat: - DL_SETBSTART(lp, dospartoff); - DL_SETBEND(lp, dospartend < DL_GETDSIZE(lp) ? dospartend : DL_GETDSIZE(lp)); - /* record the OpenBSD partition's placement for the caller */ if (partoffp) *partoffp = dospartoff; + else { + DL_SETBSTART(lp, dospartoff); + DL_SETBEND(lp, + dospartend < DL_GETDSIZE(lp) ? dospartend : DL_GETDSIZE(lp)); + } /* don't read the on-disk label if we are in spoofed-only mode */ if (spoofonly) - return (NULL); + return (NULL); /* jump to the checkdisklabel below?? */ bp->b_blkno = DL_BLKTOSEC(lp, dospartoff + DOS_LABELSECTOR) * DL_BLKSPERSEC(lp); |