Module Name: src
Committed By: riastradh
Date: Thu May 19 20:34:13 UTC 2011
Modified Files:
src/sys/dev: cgd.c
Log Message:
Reject unaligned writes to cgd.
Fixes the following PRs:
PR kern/44515 (cgd dies on non-aligned writes to the raw device)
PR kern/44964 (cgd seems to panic on unaligned writes instead of giving EINVAL)
ok christos
To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/sys/dev/cgd.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/cgd.c
diff -u src/sys/dev/cgd.c:1.71 src/sys/dev/cgd.c:1.72
--- src/sys/dev/cgd.c:1.71 Fri Nov 19 06:44:39 2010
+++ src/sys/dev/cgd.c Thu May 19 20:34:13 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: cgd.c,v 1.71 2010/11/19 06:44:39 dholland Exp $ */
+/* $NetBSD: cgd.c,v 1.72 2011/05/19 20:34:13 riastradh Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.71 2010/11/19 06:44:39 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.72 2011/05/19 20:34:13 riastradh Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -293,6 +293,21 @@
DPRINTF_FOLLOW(("cgdstrategy(%p): b_bcount = %ld\n", bp,
(long)bp->b_bcount));
+
+ /*
+ * Reject unaligned writes. We can encrypt and decrypt only
+ * complete disk sectors, and we let the ciphers require their
+ * buffers to be aligned to 32-bit boundaries.
+ */
+ if (bp->b_blkno < 0 ||
+ (bp->b_bcount % DEV_BSIZE) != 0 ||
+ ((uintptr_t)bp->b_data & 3) != 0) {
+ bp->b_error = EINVAL;
+ bp->b_resid = bp->b_bcount;
+ biodone(bp);
+ return;
+ }
+
/* XXXrcd: Should we test for (cs != NULL)? */
dk_strategy(di, &cs->sc_dksc, bp);
return;