Source-Changes-HG archive

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

[src/trunk]: src/sys/fs/tmpfs tmpfs: Assert no arithmetic overflow in directo...



details:   https://anonhg.NetBSD.org/src/rev/59cbdf4c50c0
branches:  trunk
changeset: 374508:59cbdf4c50c0
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sat Apr 29 08:15:13 2023 +0000

description:
tmpfs: Assert no arithmetic overflow in directory node tn_size.

Need >2^57 directory entries before this is a problem.  If we created
a million per second, this would take over 4000 years.

diffstat:

 sys/fs/tmpfs/tmpfs_subr.c |  6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diffs (34 lines):

diff -r 6c3d29885340 -r 59cbdf4c50c0 sys/fs/tmpfs/tmpfs_subr.c
--- a/sys/fs/tmpfs/tmpfs_subr.c Sat Apr 29 08:13:27 2023 +0000
+++ b/sys/fs/tmpfs/tmpfs_subr.c Sat Apr 29 08:15:13 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tmpfs_subr.c,v 1.116 2023/04/29 08:13:27 riastradh Exp $       */
+/*     $NetBSD: tmpfs_subr.c,v 1.117 2023/04/29 08:15:13 riastradh Exp $       */
 
 /*
  * Copyright (c) 2005-2020 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.116 2023/04/29 08:13:27 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.117 2023/04/29 08:15:13 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/cprng.h>
@@ -522,6 +522,7 @@ tmpfs_dir_attach(tmpfs_node_t *dnode, tm
 
        /* Insert the entry to the directory (parent of inode). */
        TAILQ_INSERT_TAIL(&dnode->tn_spec.tn_dir.tn_dir, de, td_entries);
+       KASSERT(dnode->tn_size <= __type_max(off_t) - sizeof(tmpfs_dirent_t));
        dnode->tn_size += sizeof(tmpfs_dirent_t);
        uvm_vnp_setsize(dvp, dnode->tn_size);
 
@@ -580,6 +581,7 @@ tmpfs_dir_detach(tmpfs_node_t *dnode, tm
                dnode->tn_spec.tn_dir.tn_readdir_lastp = NULL;
        }
        TAILQ_REMOVE(&dnode->tn_spec.tn_dir.tn_dir, de, td_entries);
+       KASSERT(dnode->tn_size >= sizeof(tmpfs_dirent_t));
        dnode->tn_size -= sizeof(tmpfs_dirent_t);
        tmpfs_dir_putseq(dnode, de);
 



Home | Main Index | Thread Index | Old Index