Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-7]: src/sys/kern Pull up following revision(s) (requested by chs ...
details: https://anonhg.NetBSD.org/src/rev/7d19ecb969c6
branches: netbsd-7
changeset: 799348:7d19ecb969c6
user: snj <snj%NetBSD.org@localhost>
date: Tue May 19 04:53:02 2015 +0000
description:
Pull up following revision(s) (requested by chs in ticket #766):
sys/kern/subr_disk.c: revision 1.113
in bounds_check_with_*, reject negative block numbers and avoid
a potential overflow in calculating the size of the request.
diffstat:
sys/kern/subr_disk.c | 33 ++++++++++++++++++++++++++++-----
1 files changed, 28 insertions(+), 5 deletions(-)
diffs (68 lines):
diff -r 5af27949a5da -r 7d19ecb969c6 sys/kern/subr_disk.c
--- a/sys/kern/subr_disk.c Tue May 19 04:42:31 2015 +0000
+++ b/sys/kern/subr_disk.c Tue May 19 04:53:02 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_disk.c,v 1.103 2013/10/19 22:36:57 mlelstv Exp $ */
+/* $NetBSD: subr_disk.c,v 1.103.4.1 2015/05/19 04:53:02 snj Exp $ */
/*-
* Copyright (c) 1996, 1997, 1999, 2000, 2009 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.103 2013/10/19 22:36:57 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.103.4.1 2015/05/19 04:53:02 snj Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -323,7 +323,18 @@
{
int64_t sz;
- sz = howmany(bp->b_bcount, secsize);
+ if (bp->b_blkno < 0) {
+ /* Reject negative offsets immediately. */
+ bp->b_error = EINVAL;
+ return 0;
+ }
+
+ sz = howmany((int64_t)bp->b_bcount, secsize);
+
+ /*
+ * bp->b_bcount is a 32-bit value, and we rejected a negative
+ * bp->b_blkno already, so "bp->b_blkno + sz" cannot overflow.
+ */
if (bp->b_blkno + sz > mediasize) {
sz = mediasize - bp->b_blkno;
@@ -357,6 +368,12 @@
uint64_t p_size, p_offset, labelsector;
int64_t sz;
+ if (bp->b_blkno < 0) {
+ /* Reject negative offsets immediately. */
+ bp->b_error = EINVAL;
+ return -1;
+ }
+
/* Protect against division by zero. XXX: Should never happen?!?! */
if (lp->d_secpercyl == 0) {
bp->b_error = EINVAL;
@@ -372,8 +389,14 @@
#endif
labelsector = (labelsector + dk->dk_labelsector) << dk->dk_blkshift;
- sz = howmany(bp->b_bcount, DEV_BSIZE);
- if ((bp->b_blkno + sz) > p_size) {
+ sz = howmany((int64_t)bp->b_bcount, DEV_BSIZE);
+
+ /*
+ * bp->b_bcount is a 32-bit value, and we rejected a negative
+ * bp->b_blkno already, so "bp->b_blkno + sz" cannot overflow.
+ */
+
+ if (bp->b_blkno + sz > p_size) {
sz = p_size - bp->b_blkno;
if (sz == 0) {
/* If exactly at end of disk, return EOF. */
Home |
Main Index |
Thread Index |
Old Index