Source-Changes-HG archive

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

[src/trunk]: src/sys/kern This thing is totally buggy: 'data_len' is modified...



details:   https://anonhg.NetBSD.org/src/rev/e1cab5426063
branches:  trunk
changeset: 328844:e1cab5426063
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sun Apr 20 21:26:51 2014 +0000

description:
This thing is totally buggy: 'data_len' is modified by the fs, so calling
kmem_free with it while its value has changed since the kmem_alloc is far
from being a good idea.

If the kernel figures out that something mismatches, it will panic
(typically with kernfs).

diffstat:

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

diffs (45 lines):

diff -r 1e16bf16e928 -r e1cab5426063 sys/kern/vfs_syscalls.c
--- a/sys/kern/vfs_syscalls.c   Sun Apr 20 16:06:05 2014 +0000
+++ b/sys/kern/vfs_syscalls.c   Sun Apr 20 21:26:51 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_syscalls.c,v 1.481 2014/04/18 05:22:13 maxv Exp $  */
+/*     $NetBSD: vfs_syscalls.c,v 1.482 2014/04/20 21:26:51 maxv Exp $  */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.481 2014/04/18 05:22:13 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.482 2014/04/20 21:26:51 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_fileassoc.h"
@@ -454,6 +454,7 @@
        struct vnode *vp;
        void *data_buf = data;
        bool vfsopsrele = false;
+       size_t alloc_sz = 0;
        int error;
 
        /* XXX: The calling convention of this routine is totally bizarre */
@@ -502,7 +503,8 @@
                        error = EINVAL;
                        goto done;
                }
-               data_buf = kmem_alloc(data_len, KM_SLEEP);
+               alloc_sz = data_len;
+               data_buf = kmem_alloc(alloc_sz, KM_SLEEP);
 
                /* NFS needs the buffer even for mnt_getargs .... */
                error = copyin(data, data_buf, data_len);
@@ -538,7 +540,7 @@
                vrele(vp);
        }
        if (data_buf != data)
-               kmem_free(data_buf, data_len);
+               kmem_free(data_buf, alloc_sz);
        return (error);
 }
 



Home | Main Index | Thread Index | Old Index