Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev Reject unaligned writes to cgd.
details: https://anonhg.NetBSD.org/src/rev/c10a44e8a3e4
branches: trunk
changeset: 765111:c10a44e8a3e4
user: riastradh <riastradh%NetBSD.org@localhost>
date: Thu May 19 20:34:13 2011 +0000
description:
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
diffstat:
sys/dev/cgd.c | 19 +++++++++++++++++--
1 files changed, 17 insertions(+), 2 deletions(-)
diffs (40 lines):
diff -r 8ff4d799578a -r c10a44e8a3e4 sys/dev/cgd.c
--- a/sys/dev/cgd.c Thu May 19 15:18:29 2011 +0000
+++ b/sys/dev/cgd.c Thu May 19 20:34:13 2011 +0000
@@ -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;
Home |
Main Index |
Thread Index |
Old Index