Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Change buf_nbuf()'s return value from int to u_int to av...



details:   https://anonhg.NetBSD.org/src/rev/5a47c567b4c4
branches:  trunk
changeset: 453800:5a47c567b4c4
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Mon Aug 26 10:24:39 2019 +0000

description:
Change buf_nbuf()'s return value from int to u_int to avoid undefined
behavior in wapbl_start() which extended int to size_t.

Error message was:
> UBSan: Undefined Behavior in ../../../../kern/vfs_wapbl.c:609:41, signed integer overflow: 3345138 * 1024 cannot be represented in type 'int'

>        /* XXX maybe use filesystem fragment size instead of 1024 */
>         /* XXX fix actual number of buffers reserved per filesystem. */
>         wl->wl_bufcount_max = (buf_nbuf() / 2) * 1024;

Need more work?

diffstat:

 sys/kern/vfs_bio.c |  6 +++---
 sys/sys/buf.h      |  4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diffs (45 lines):

diff -r 61eb575a911d -r 5a47c567b4c4 sys/kern/vfs_bio.c
--- a/sys/kern/vfs_bio.c        Mon Aug 26 10:19:08 2019 +0000
+++ b/sys/kern/vfs_bio.c        Mon Aug 26 10:24:39 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_bio.c,v 1.278 2018/11/24 17:52:39 maxv Exp $       */
+/*     $NetBSD: vfs_bio.c,v 1.279 2019/08/26 10:24:39 msaitoh Exp $    */
 
 /*-
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -123,7 +123,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.278 2018/11/24 17:52:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.279 2019/08/26 10:24:39 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_bufcache.h"
@@ -2177,7 +2177,7 @@
  * Nothing outside this file should really need to know about nbuf,
  * but a few things still want to read it, so give them a way to do that.
  */
-int
+u_int
 buf_nbuf(void)
 {
 
diff -r 61eb575a911d -r 5a47c567b4c4 sys/sys/buf.h
--- a/sys/sys/buf.h     Mon Aug 26 10:19:08 2019 +0000
+++ b/sys/sys/buf.h     Mon Aug 26 10:24:39 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: buf.h,v 1.130 2019/06/28 14:56:45 jmcneill Exp $ */
+/*     $NetBSD: buf.h,v 1.131 2019/08/26 10:24:39 msaitoh Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2007, 2008 The NetBSD Foundation, Inc.
@@ -311,7 +311,7 @@
 void   buf_init(buf_t *);
 void   buf_destroy(buf_t *);
 int    bbusy(buf_t *, bool, int, kmutex_t *);
-int    buf_nbuf(void);
+u_int  buf_nbuf(void);
 
 void   biohist_init(void);
 



Home | Main Index | Thread Index | Old Index