Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Check if secsize and numsec returned from ioctl's a...
details: https://anonhg.NetBSD.org/src/rev/948728a3dbab
branches: trunk
changeset: 780017:948728a3dbab
user: tsutsui <tsutsui%NetBSD.org@localhost>
date: Sat Jul 07 16:10:23 2012 +0000
description:
Check if secsize and numsec returned from ioctl's are sane values
and add DIAGNOSTIC messages in getdisksize().
Discussed on source-changes-d@:
http://mail-index.NetBSD.org/source-changes-d/2012/07/02/msg004989.html
and patch is reviwed by christos@ and pgoyette@.
diffstat:
sys/kern/subr_disk_open.c | 42 ++++++++++++++++++++++++++++++------------
1 files changed, 30 insertions(+), 12 deletions(-)
diffs (70 lines):
diff -r 28055e8f7b26 -r 948728a3dbab sys/kern/subr_disk_open.c
--- a/sys/kern/subr_disk_open.c Sat Jul 07 08:06:51 2012 +0000
+++ b/sys/kern/subr_disk_open.c Sat Jul 07 16:10:23 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_disk_open.c,v 1.8 2012/04/27 18:15:55 drochner Exp $ */
+/* $NetBSD: subr_disk_open.c,v 1.9 2012/07/07 16:10:23 tsutsui Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_disk_open.c,v 1.8 2012/04/27 18:15:55 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_disk_open.c,v 1.9 2012/07/07 16:10:23 tsutsui Exp $");
#include <sys/param.h>
#include <sys/conf.h>
@@ -94,23 +94,41 @@
struct partinfo dpart;
struct dkwedge_info dkw;
struct disk *pdk;
+ unsigned int secsize;
+ uint64_t numsec;
int error;
error = VOP_IOCTL(vp, DIOCGPART, &dpart, FREAD, NOCRED);
if (error == 0) {
- *secsizep = dpart.disklab->d_secsize;
- *numsecp = dpart.part->p_size;
- return 0;
+ secsize = dpart.disklab->d_secsize;
+ numsec = dpart.part->p_size;
+ } else {
+ error = VOP_IOCTL(vp, DIOCGWEDGEINFO, &dkw, FREAD, NOCRED);
+ if (error == 0) {
+ pdk = disk_find(dkw.dkw_parent);
+ if (pdk != NULL) {
+ secsize = DEV_BSIZE << pdk->dk_blkshift;
+ numsec = dkw.dkw_size;
+ } else
+ error = ENODEV;
+ }
}
- error = VOP_IOCTL(vp, DIOCGWEDGEINFO, &dkw, FREAD, NOCRED);
+ if (error == 0 &&
+ (secsize == 0 || secsize > MAXBSIZE || !powerof2(secsize) ||
+ numsec == 0)) {
+#ifdef DIAGNOSTIC
+ printf("%s: %s returns invalid disksize values"
+ " (secsize = %u, numsec = %" PRIu64 ")\n",
+ __func__,
+ devsw_blk2name(major(vp->v_specnode->sn_rdev)),
+ secsize, numsec);
+#endif
+ error = EINVAL;
+ }
if (error == 0) {
- pdk = disk_find(dkw.dkw_parent);
- if (pdk != NULL) {
- *secsizep = DEV_BSIZE << pdk->dk_blkshift;
- *numsecp = dkw.dkw_size;
- } else
- error = ENODEV;
+ *secsizep = secsize;
+ *numsecp = numsec;
}
return error;
Home |
Main Index |
Thread Index |
Old Index