Source-Changes-HG archive

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

[src/trunk]: src/sys/kern cache_lookup(): fix a use-after-free.



details:   https://anonhg.NetBSD.org/src/rev/e804b3cb0f89
branches:  trunk
changeset: 746409:e804b3cb0f89
user:      ad <ad%NetBSD.org@localhost>
date:      Mon Mar 30 19:15:28 2020 +0000

description:
cache_lookup(): fix a use-after-free.

diffstat:

 sys/kern/vfs_cache.c |  20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)

diffs (48 lines):

diff -r a2903e548631 -r e804b3cb0f89 sys/kern/vfs_cache.c
--- a/sys/kern/vfs_cache.c      Mon Mar 30 19:07:32 2020 +0000
+++ b/sys/kern/vfs_cache.c      Mon Mar 30 19:15:28 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_cache.c,v 1.135 2020/03/27 00:14:25 ad Exp $       */
+/*     $NetBSD: vfs_cache.c,v 1.136 2020/03/30 19:15:28 ad Exp $       */
 
 /*-
  * Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc.
@@ -172,7 +172,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.135 2020/03/27 00:14:25 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.136 2020/03/30 19:15:28 ad Exp $");
 
 #define __NAMECACHE_PRIVATE
 #ifdef _KERNEL_OPT
@@ -554,6 +554,14 @@
                return false;
        }
        if (ncp->nc_vp == NULL) {
+               if (iswht_ret != NULL) {
+                       /*
+                        * Restore the ISWHITEOUT flag saved earlier.
+                        */
+                       *iswht_ret = ncp->nc_whiteout;
+               } else {
+                       KASSERT(!ncp->nc_whiteout);
+               }
                if (nameiop == CREATE && (cnflags & ISLASTCN) != 0) {
                        /*
                         * Last component and we are preparing to create
@@ -570,14 +578,6 @@
                        /* found neg entry; vn is already null from above */
                        hit = true;
                }
-               if (iswht_ret != NULL) {
-                       /*
-                        * Restore the ISWHITEOUT flag saved earlier.
-                        */
-                       *iswht_ret = ncp->nc_whiteout;
-               } else {
-                       KASSERT(!ncp->nc_whiteout);
-               }
                rw_exit(&dvi->vi_nc_lock);
                return hit;
        }



Home | Main Index | Thread Index | Old Index