Randomly initialize the node's generation to make file handles less

predictable.  This solves a problem that may appear when serving a tmpfs
over NFS: if the server reboots, newly allocated files should have
different file handles; otherwise the remote clients could access files
they were not supposed to touch.
This commit is contained in:
jmmv 2006-11-05 19:40:31 +00:00
parent 1a3e8c3caa
commit 042827a010

View File

@ -1,4 +1,4 @@
/* $NetBSD: tmpfs_subr.c,v 1.27 2006/11/05 16:59:18 jmmv Exp $ */
/* $NetBSD: tmpfs_subr.c,v 1.28 2006/11/05 19:40:31 jmmv Exp $ */
/*
* Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.27 2006/11/05 16:59:18 jmmv Exp $");
__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.28 2006/11/05 19:40:31 jmmv Exp $");
#include <sys/param.h>
#include <sys/dirent.h>
@ -116,7 +116,7 @@ tmpfs_alloc_node(struct tmpfs_mount *tmp, enum vtype type,
if (nnode == NULL)
return ENOSPC;
nnode->tn_id = tmp->tm_nodes_last++;
nnode->tn_gen = 0;
nnode->tn_gen = arc4random();
} else {
nnode = LIST_FIRST(&tmp->tm_nodes_avail);
LIST_REMOVE(nnode, tn_entries);