Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Don't allow callers of fsync_range() to trigger UB ...



details:   https://anonhg.NetBSD.org/src/rev/c53e32859cc4
branches:  trunk
changeset: 952794:c53e32859cc4
user:      dholland <dholland%NetBSD.org@localhost>
date:      Wed Feb 17 17:39:08 2021 +0000

description:
Don't allow callers of fsync_range() to trigger UB in the kernel.

(also prohibit syncing ranges at start offsets less than zero)

diffstat:

 sys/kern/vfs_syscalls.c |  9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diffs (33 lines):

diff -r 9cf059c45c18 -r c53e32859cc4 sys/kern/vfs_syscalls.c
--- a/sys/kern/vfs_syscalls.c   Wed Feb 17 12:37:33 2021 +0000
+++ b/sys/kern/vfs_syscalls.c   Wed Feb 17 17:39:08 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_syscalls.c,v 1.548 2020/05/16 18:31:50 christos Exp $      */
+/*     $NetBSD: vfs_syscalls.c,v 1.549 2021/02/17 17:39:08 dholland Exp $      */
 
 /*-
  * Copyright (c) 2008, 2009, 2019, 2020 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.548 2020/05/16 18:31:50 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.549 2021/02/17 17:39:08 dholland Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_fileassoc.h"
@@ -4198,11 +4198,12 @@
        /* If length == 0, we do the whole file, and s = e = 0 will do that */
        if (len) {
                s = SCARG(uap, start);
-               e = s + len;
-               if (e < s) {
+               if (s < 0 || len < 0 || len > OFF_T_MAX - s) {
                        error = EINVAL;
                        goto out;
                }
+               e = s + len;
+               KASSERT(s <= e);
        } else {
                e = 0;
                s = 0;



Home | Main Index | Thread Index | Old Index