Module Name:    src
Committed By:   msaitoh
Date:           Mon Aug 26 10:24:39 UTC 2019

Modified Files:
        src/sys/kern: vfs_bio.c
        src/sys/sys: buf.h

Log Message:
 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?


To generate a diff of this commit:
cvs rdiff -u -r1.278 -r1.279 src/sys/kern/vfs_bio.c
cvs rdiff -u -r1.130 -r1.131 src/sys/sys/buf.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/vfs_bio.c
diff -u src/sys/kern/vfs_bio.c:1.278 src/sys/kern/vfs_bio.c:1.279
--- src/sys/kern/vfs_bio.c:1.278	Sat Nov 24 17:52:39 2018
+++ src/sys/kern/vfs_bio.c	Mon Aug 26 10:24:39 2019
@@ -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 @@ bbusy(buf_t *bp, bool intr, int timo, km
  * 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)
 {
 

Index: src/sys/sys/buf.h
diff -u src/sys/sys/buf.h:1.130 src/sys/sys/buf.h:1.131
--- src/sys/sys/buf.h:1.130	Fri Jun 28 14:56:45 2019
+++ src/sys/sys/buf.h	Mon Aug 26 10:24:39 2019
@@ -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	vfs_buf_print(buf_t *, int, void (*
 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);
 

Reply via email to