diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2007-06-18 20:55:53 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2007-06-18 20:55:53 +0000 |
commit | 83650bf4e48a1bc81f78a500e54ed7c673403455 (patch) | |
tree | 389291f424d8945b0b81689a380c31fca1323ec6 | |
parent | ff69e42a25f7827983c4551bf5186e40f03a6637 (diff) |
avoid modification race in DIOCRLDINFO; ok krw miod
-rw-r--r-- | sys/dev/ata/wd.c | 10 | ||||
-rw-r--r-- | sys/dev/isa/mcd.c | 10 | ||||
-rw-r--r-- | sys/dev/ramdisk.c | 12 | ||||
-rw-r--r-- | sys/scsi/cd.c | 9 | ||||
-rw-r--r-- | sys/scsi/sd.c | 9 |
5 files changed, 33 insertions, 17 deletions
diff --git a/sys/dev/ata/wd.c b/sys/dev/ata/wd.c index 834f9a52c9b..4448744a1fb 100644 --- a/sys/dev/ata/wd.c +++ b/sys/dev/ata/wd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wd.c,v 1.64 2007/06/08 05:27:58 deraadt Exp $ */ +/* $OpenBSD: wd.c,v 1.65 2007/06/18 20:55:52 deraadt Exp $ */ /* $NetBSD: wd.c,v 1.193 1999/02/28 17:15:27 explorer Exp $ */ /* @@ -826,6 +826,7 @@ int wdioctl(dev_t dev, u_long xfer, caddr_t addr, int flag, struct proc *p) { struct wd_softc *wd; + struct disklabel *lp; int error = 0; WDCDEBUG_PRINT(("wdioctl\n"), DEBUG_FUNCS); @@ -841,9 +842,12 @@ wdioctl(dev_t dev, u_long xfer, caddr_t addr, int flag, struct proc *p) switch (xfer) { case DIOCRLDINFO: - wdgetdisklabel(dev, wd, wd->sc_dk.dk_label, - wd->sc_dk.dk_cpulabel, 0); + lp = malloc(sizeof(*lp), M_TEMP, M_WAITOK); + wdgetdisklabel(dev, wd, lp, wd->sc_dk.dk_cpulabel, 0); + bcopy(lp, wd->sc_dk.dk_label, sizeof(*lp)); + free(lp, M_TEMP); goto exit; + case DIOCGPDINFO: { struct cpu_disklabel osdep; diff --git a/sys/dev/isa/mcd.c b/sys/dev/isa/mcd.c index 30b439fc979..c9c31be7bf9 100644 --- a/sys/dev/isa/mcd.c +++ b/sys/dev/isa/mcd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mcd.c,v 1.47 2007/06/08 05:27:58 deraadt Exp $ */ +/* $OpenBSD: mcd.c,v 1.48 2007/06/18 20:55:52 deraadt Exp $ */ /* $NetBSD: mcd.c,v 1.60 1998/01/14 12:14:41 drochner Exp $ */ /* @@ -621,6 +621,7 @@ mcdioctl(dev, cmd, addr, flag, p) struct proc *p; { struct mcd_softc *sc = mcd_cd.cd_devs[DISKUNIT(dev)]; + struct disklabel *lp; int error; MCD_TRACE("ioctl: cmd=0x%x\n", cmd, 0, 0, 0); @@ -630,9 +631,12 @@ mcdioctl(dev, cmd, addr, flag, p) switch (cmd) { case DIOCRLDINFO: - mcdgetdisklabel(dev, sc, sc->sc_dk.dk_label, - sc->sc_dk.dk_cpulabel, 0); + lp = malloc(sizeof(*lp), M_TEMP, M_WAITOK); + mcdgetdisklabel(dev, sc, lp, sc->sc_dk.dk_cpulabel, 0); + bcopy(lp, sc->sc_dk.dk_label, sizeof(*lp)); + free(lp, M_TEMP); return 0; + case DIOCGDINFO: case DIOCGPDINFO: *(struct disklabel *)addr = *(sc->sc_dk.dk_label); diff --git a/sys/dev/ramdisk.c b/sys/dev/ramdisk.c index 0d9adfa801f..3dde36fee18 100644 --- a/sys/dev/ramdisk.c +++ b/sys/dev/ramdisk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ramdisk.c,v 1.35 2007/06/18 20:49:19 krw Exp $ */ +/* $OpenBSD: ramdisk.c,v 1.36 2007/06/18 20:55:52 deraadt Exp $ */ /* $NetBSD: ramdisk.c,v 1.8 1996/04/12 08:30:09 leo Exp $ */ /* @@ -396,6 +396,7 @@ rdioctl(dev, cmd, data, flag, proc) struct proc *proc; { int unit; + struct disklabel *lp; struct rd_softc *sc; struct rd_conf *urd; int error; @@ -406,11 +407,12 @@ rdioctl(dev, cmd, data, flag, proc) urd = (struct rd_conf *)data; switch (cmd) { case DIOCRLDINFO: - if (sc->sc_type == RD_UNCONFIGURED) { + if (sc->sc_type == RD_UNCONFIGURED) break; - } - rdgetdisklabel(dev, sc, sc->sc_dkdev.dk_label, - sc->sc_dkdev.dk_cpulabel, 0); + lp = malloc(sizeof(*lp), M_TEMP, M_WAITOK); + rdgetdisklabel(dev, sc, lp, sc->sc_dkdev.dk_cpulabel, 0); + bcopy(lp, sc->sc_dkdev.dk_label, sizeof(*lp)); + free(lp, M_TEMP); return 0; case DIOCGPDINFO: { diff --git a/sys/scsi/cd.c b/sys/scsi/cd.c index c9f83e99e54..a1fa2efc42e 100644 --- a/sys/scsi/cd.c +++ b/sys/scsi/cd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cd.c,v 1.130 2007/06/08 05:27:58 deraadt Exp $ */ +/* $OpenBSD: cd.c,v 1.131 2007/06/18 20:55:52 deraadt Exp $ */ /* $NetBSD: cd.c,v 1.100 1997/04/02 02:29:30 mycroft Exp $ */ /* @@ -771,6 +771,7 @@ int cdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p) { struct cd_softc *cd; + struct disklabel *lp; int part = DISKPART(dev); int error = 0; @@ -824,8 +825,10 @@ cdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p) switch (cmd) { case DIOCRLDINFO: - cdgetdisklabel(dev, cd, cd->sc_dk.dk_label, - cd->sc_dk.dk_cpulabel, 0); + lp = malloc(sizeof(*lp), M_TEMP, M_WAITOK); + cdgetdisklabel(dev, cd, lp, cd->sc_dk.dk_cpulabel, 0); + bcopy(lp, cd->sc_dk.dk_label, sizeof(*lp)); + free(lp, M_TEMP); break; case DIOCGDINFO: case DIOCGPDINFO: diff --git a/sys/scsi/sd.c b/sys/scsi/sd.c index 5f1bbc3f2f4..6eb2fc404e3 100644 --- a/sys/scsi/sd.c +++ b/sys/scsi/sd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sd.c,v 1.133 2007/06/08 05:27:58 deraadt Exp $ */ +/* $OpenBSD: sd.c,v 1.134 2007/06/18 20:55:52 deraadt Exp $ */ /* $NetBSD: sd.c,v 1.111 1997/04/02 02:29:41 mycroft Exp $ */ /*- @@ -824,6 +824,7 @@ int sdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p) { struct sd_softc *sd; + struct disklabel *lp; int error = 0; int part = DISKPART(dev); @@ -860,8 +861,10 @@ sdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p) switch (cmd) { case DIOCRLDINFO: - sdgetdisklabel(dev, sd, sd->sc_dk.dk_label, - sd->sc_dk.dk_cpulabel, 0); + lp = malloc(sizeof(*lp), M_TEMP, M_WAITOK); + sdgetdisklabel(dev, sd, lp, sd->sc_dk.dk_cpulabel, 0); + bcopy(lp, sd->sc_dk.dk_label, sizeof(*lp)); + free(lp, M_TEMP); goto exit; case DIOCGPDINFO: { struct cpu_disklabel osdep; |