summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/isofs/cd9660/cd9660_node.c21
-rw-r--r--sys/isofs/udf/udf.h3
-rw-r--r--sys/isofs/udf/udf_subr.c4
-rw-r--r--sys/isofs/udf/udf_vfsops.c5
-rw-r--r--sys/isofs/udf/udf_vnops.c13
-rw-r--r--sys/msdosfs/msdosfs_denode.c24
-rw-r--r--sys/nfs/nfs_srvcache.c18
-rw-r--r--sys/ntfs/ntfs_ihash.c22
-rw-r--r--sys/ufs/ffs/ffs_softdep.c33
-rw-r--r--sys/ufs/ufs/ufs_quota.c15
10 files changed, 124 insertions, 34 deletions
diff --git a/sys/isofs/cd9660/cd9660_node.c b/sys/isofs/cd9660/cd9660_node.c
index bda92461ab4..e77f710cd91 100644
--- a/sys/isofs/cd9660/cd9660_node.c
+++ b/sys/isofs/cd9660/cd9660_node.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cd9660_node.c,v 1.25 2014/09/14 14:17:25 jsg Exp $ */
+/* $OpenBSD: cd9660_node.c,v 1.26 2014/11/18 10:42:15 dlg Exp $ */
/* $NetBSD: cd9660_node.c,v 1.17 1997/05/05 07:13:57 mycroft Exp $ */
/*-
@@ -48,6 +48,8 @@
#include <sys/malloc.h>
#include <sys/stat.h>
+#include <crypto/siphash.h>
+
#include <isofs/cd9660/iso.h>
#include <isofs/cd9660/cd9660_extern.h>
#include <isofs/cd9660/cd9660_node.h>
@@ -56,9 +58,12 @@
/*
* Structures associated with iso_node caching.
*/
+u_int cd9660_isohash(dev_t, cdino_t);
+
struct iso_node **isohashtbl;
u_long isohash;
-#define INOHASH(device, inum) (((device) + ((inum)>>12)) & isohash)
+SIPHASH_KEY isohashkey;
+#define INOHASH(device, inum) cd9660_isohash((device), (inum))
extern int prtactive; /* 1 => print out reclaim of active vnodes */
@@ -73,9 +78,21 @@ cd9660_init(vfsp)
{
isohashtbl = hashinit(desiredvnodes, M_ISOFSMNT, M_WAITOK, &isohash);
+ arc4random_buf(&isohashkey, sizeof(isohashkey));
return (0);
}
+u_int
+cd9660_isohash(dev_t device, cdino_t inum)
+{
+ SIPHASH_CTX ctx;
+
+ SipHash24_Init(&ctx, &isohashkey);
+ SipHash24_Update(&ctx, &device, sizeof(device));
+ SipHash24_Update(&ctx, &inum, sizeof(inum));
+ return (SipHash24_End(&ctx) & isohash);
+}
+
/*
* Use the device/inum pair to find the incore inode, and return a pointer
* to it. If it is in core, but locked, wait for it.
diff --git a/sys/isofs/udf/udf.h b/sys/isofs/udf/udf.h
index 52562e220eb..d65d7cdb1b2 100644
--- a/sys/isofs/udf/udf.h
+++ b/sys/isofs/udf/udf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: udf.h,v 1.19 2013/09/17 04:31:56 mlarkin Exp $ */
+/* $OpenBSD: udf.h,v 1.20 2014/11/18 10:42:15 dlg Exp $ */
/*
* Copyright (c) 2001, 2002 Scott Long <scottl@freebsd.org>
@@ -71,6 +71,7 @@ struct umount {
struct unode *um_vat;
struct long_ad um_root_icb;
LIST_HEAD(udf_hash_lh, unode) *um_hashtbl;
+ SIPHASH_KEY um_hashkey;
u_long um_hashsz;
struct mutex um_hashmtx;
int um_psecs;
diff --git a/sys/isofs/udf/udf_subr.c b/sys/isofs/udf/udf_subr.c
index e6fed3ce9ac..9771fe38063 100644
--- a/sys/isofs/udf/udf_subr.c
+++ b/sys/isofs/udf/udf_subr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: udf_subr.c,v 1.23 2014/11/03 21:28:35 tedu Exp $ */
+/* $OpenBSD: udf_subr.c,v 1.24 2014/11/18 10:42:15 dlg Exp $ */
/*
* Copyright (c) 2006, Miodrag Vallat
@@ -38,6 +38,8 @@
#include <sys/dirent.h>
#include <sys/disklabel.h>
+#include <crypto/siphash.h>
+
#include <isofs/udf/ecma167-udf.h>
#include <isofs/udf/udf.h>
#include <isofs/udf/udf_extern.h>
diff --git a/sys/isofs/udf/udf_vfsops.c b/sys/isofs/udf/udf_vfsops.c
index e12553b9d97..58cda539e2f 100644
--- a/sys/isofs/udf/udf_vfsops.c
+++ b/sys/isofs/udf/udf_vfsops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: udf_vfsops.c,v 1.42 2014/07/12 18:50:00 tedu Exp $ */
+/* $OpenBSD: udf_vfsops.c,v 1.43 2014/11/18 10:42:15 dlg Exp $ */
/*
* Copyright (c) 2001, 2002 Scott Long <scottl@freebsd.org>
@@ -67,6 +67,8 @@
#include <sys/endian.h>
#include <sys/specdev.h>
+#include <crypto/siphash.h>
+
#include <isofs/udf/ecma167-udf.h>
#include <isofs/udf/udf.h>
#include <isofs/udf/udf_extern.h>
@@ -364,6 +366,7 @@ udf_mountfs(struct vnode *devvp, struct mount *mp, uint32_t lb, struct proc *p)
mtx_init(&ump->um_hashmtx, IPL_NONE);
ump->um_hashtbl = hashinit(UDF_HASHTBLSIZE, M_UDFMOUNT, M_WAITOK,
&ump->um_hashsz);
+ arc4random_buf(&ump->um_hashkey, sizeof(ump->um_hashkey));
/* Get the VAT, if needed */
if (ump->um_flags & UDF_MNT_FIND_VAT) {
diff --git a/sys/isofs/udf/udf_vnops.c b/sys/isofs/udf/udf_vnops.c
index 2f933010528..4c318ce27fa 100644
--- a/sys/isofs/udf/udf_vnops.c
+++ b/sys/isofs/udf/udf_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: udf_vnops.c,v 1.56 2014/11/03 21:28:35 tedu Exp $ */
+/* $OpenBSD: udf_vnops.c,v 1.57 2014/11/18 10:42:15 dlg Exp $ */
/*
* Copyright (c) 2001, 2002 Scott Long <scottl@freebsd.org>
@@ -50,6 +50,8 @@
#include <sys/specdev.h>
#include <sys/unistd.h>
+#include <crypto/siphash.h>
+
#include <isofs/udf/ecma167-udf.h>
#include <isofs/udf/udf.h>
#include <isofs/udf/udf_extern.h>
@@ -92,7 +94,8 @@ udf_hashlookup(struct umount *ump, udfino_t id, int flags, struct vnode **vpp)
loop:
mtx_enter(&ump->um_hashmtx);
- lh = &ump->um_hashtbl[id & ump->um_hashsz];
+ lh = &ump->um_hashtbl[SipHash24(&ump->um_hashkey, &id, sizeof(id)) &
+ ump->um_hashsz];
if (lh == NULL) {
mtx_leave(&ump->um_hashmtx);
return (ENOENT);
@@ -127,7 +130,8 @@ udf_hashins(struct unode *up)
vn_lock(up->u_vnode, LK_EXCLUSIVE | LK_RETRY, p);
mtx_enter(&ump->um_hashmtx);
- lh = &ump->um_hashtbl[up->u_ino & ump->um_hashsz];
+ lh = &ump->um_hashtbl[SipHash24(&ump->um_hashkey,
+ &up->u_ino, sizeof(up->u_ino)) & ump->um_hashsz];
if (lh == NULL)
panic("hash entry is NULL, up->u_ino = %d", up->u_ino);
LIST_INSERT_HEAD(lh, up, u_le);
@@ -145,7 +149,8 @@ udf_hashrem(struct unode *up)
ump = up->u_ump;
mtx_enter(&ump->um_hashmtx);
- lh = &ump->um_hashtbl[up->u_ino & ump->um_hashsz];
+ lh = &ump->um_hashtbl[SipHash24(&ump->um_hashkey,
+ &up->u_ino, sizeof(up->u_ino)) & ump->um_hashsz];
if (lh == NULL)
panic("hash entry is NULL, up->u_ino = %d", up->u_ino);
LIST_REMOVE(up, u_le);
diff --git a/sys/msdosfs/msdosfs_denode.c b/sys/msdosfs/msdosfs_denode.c
index cb32bbb8416..aaf87b1dcb9 100644
--- a/sys/msdosfs/msdosfs_denode.c
+++ b/sys/msdosfs/msdosfs_denode.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: msdosfs_denode.c,v 1.50 2014/09/14 14:17:26 jsg Exp $ */
+/* $OpenBSD: msdosfs_denode.c,v 1.51 2014/11/18 10:42:15 dlg Exp $ */
/* $NetBSD: msdosfs_denode.c,v 1.23 1997/10/17 11:23:58 ws Exp $ */
/*-
@@ -58,16 +58,20 @@
#include <sys/dirent.h>
#include <sys/namei.h>
+#include <crypto/siphash.h>
+
#include <msdosfs/bpb.h>
#include <msdosfs/msdosfsmount.h>
#include <msdosfs/direntry.h>
#include <msdosfs/denode.h>
#include <msdosfs/fat.h>
+u_int msdosfs_dehash(dev_t, uint32_t, uint32_t);
+
struct denode **dehashtbl;
+SIPHASH_KEY dehashkey;
u_long dehash; /* size of hash table - 1 */
-#define DEHASH(dev, dcl, doff) (((dev) + (dcl) + (doff) / sizeof(struct direntry)) \
- & dehash)
+#define DEHASH(dev, dcl, doff) msdosfs_dehash((dev), (dcl), (doff))
static struct denode *msdosfs_hashget(dev_t, uint32_t, uint32_t);
static int msdosfs_hashins(struct denode *);
@@ -78,9 +82,23 @@ int
msdosfs_init(struct vfsconf *vfsp)
{
dehashtbl = hashinit(desiredvnodes/2, M_MSDOSFSMNT, M_WAITOK, &dehash);
+ arc4random_buf(&dehashkey, sizeof(dehashkey));
return (0);
}
+u_int
+msdosfs_dehash(dev_t dev, uint32_t dirclust, uint32_t diroff)
+{
+ SIPHASH_CTX ctx;
+
+ SipHash24_Init(&ctx, &dehashkey);
+ SipHash24_Update(&ctx, &dev, sizeof(dev));
+ SipHash24_Update(&ctx, &dirclust, sizeof(dirclust));
+ SipHash24_Update(&ctx, &diroff, sizeof(diroff));
+
+ return (SipHash24_End(&ctx) & dehash);
+}
+
static struct denode *
msdosfs_hashget(dev_t dev, uint32_t dirclust, uint32_t diroff)
{
diff --git a/sys/nfs/nfs_srvcache.c b/sys/nfs/nfs_srvcache.c
index 6b34b35ff3f..d3ddb77316d 100644
--- a/sys/nfs/nfs_srvcache.c
+++ b/sys/nfs/nfs_srvcache.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nfs_srvcache.c,v 1.25 2014/09/14 14:17:26 jsg Exp $ */
+/* $OpenBSD: nfs_srvcache.c,v 1.26 2014/11/18 10:42:15 dlg Exp $ */
/* $NetBSD: nfs_srvcache.c,v 1.12 1996/02/18 11:53:49 fvdl Exp $ */
/*
@@ -49,6 +49,8 @@
#include <sys/socket.h>
#include <sys/queue.h>
+#include <crypto/siphash.h>
+
#include <netinet/in.h>
#include <nfs/rpcv2.h>
#include <nfs/nfsproto.h>
@@ -63,11 +65,12 @@ long numnfsrvcache, desirednfsrvcache = NFSRVCACHESIZ;
struct nfsrvcache *nfsrv_lookupcache(struct nfsrv_descript *);
void nfsrv_cleanentry(struct nfsrvcache *);
-#define NFSRCHASH(xid) \
- (&nfsrvhashtbl[((xid) + ((xid) >> 24)) & nfsrvhash])
LIST_HEAD(nfsrvhash, nfsrvcache) *nfsrvhashtbl;
+SIPHASH_KEY nfsrvhashkey;
TAILQ_HEAD(nfsrvlru, nfsrvcache) nfsrvlruhead;
u_long nfsrvhash;
+#define NFSRCHASH(xid) \
+ (&nfsrvhashtbl[SipHash24(&nfsrvhashkey, &(xid), sizeof(xid)) & nfsrvhash])
#define NETFAMILY(rp) \
(((rp)->rc_flag & RC_INETADDR) ? AF_INET : AF_UNSPEC)
@@ -104,6 +107,7 @@ nfsrv_initcache(void)
{
nfsrvhashtbl = hashinit(desirednfsrvcache, M_NFSD, M_WAITOK, &nfsrvhash);
+ arc4random_buf(&nfsrvhashkey, sizeof(nfsrvhashkey));
TAILQ_INIT(&nfsrvlruhead);
}
@@ -125,6 +129,7 @@ int
nfsrv_getcache(struct nfsrv_descript *nd, struct nfssvc_sock *slp,
struct mbuf **repp)
{
+ struct nfsrvhash *hash;
struct nfsrvcache *rp;
struct mbuf *mb;
struct sockaddr_in *saddr;
@@ -203,7 +208,8 @@ nfsrv_getcache(struct nfsrv_descript *nd, struct nfssvc_sock *slp,
break;
};
rp->rc_proc = nd->nd_procnum;
- LIST_INSERT_HEAD(NFSRCHASH(nd->nd_retxid), rp, rc_hash);
+ hash = NFSRCHASH(nd->nd_retxid);
+ LIST_INSERT_HEAD(hash, rp, rc_hash);
rp->rc_flag &= ~RC_LOCKED;
if (rp->rc_flag & RC_WANTED) {
rp->rc_flag &= ~RC_WANTED;
@@ -269,10 +275,12 @@ nfsrv_cleancache(void)
struct nfsrvcache *
nfsrv_lookupcache(struct nfsrv_descript *nd)
{
+ struct nfsrvhash *hash;
struct nfsrvcache *rp;
+ hash = NFSRCHASH(nd->nd_retxid);
loop:
- LIST_FOREACH(rp, NFSRCHASH(nd->nd_retxid), rc_hash) {
+ LIST_FOREACH(rp, hash, rc_hash) {
if (nd->nd_retxid == rp->rc_xid &&
nd->nd_procnum == rp->rc_proc &&
netaddr_match(NETFAMILY(rp), &rp->rc_haddr, nd->nd_nam)) {
diff --git a/sys/ntfs/ntfs_ihash.c b/sys/ntfs/ntfs_ihash.c
index 4bbe2e42f55..b8ad49278b3 100644
--- a/sys/ntfs/ntfs_ihash.c
+++ b/sys/ntfs/ntfs_ihash.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntfs_ihash.c,v 1.16 2014/09/14 14:17:26 jsg Exp $ */
+/* $OpenBSD: ntfs_ihash.c,v 1.17 2014/11/18 10:42:15 dlg Exp $ */
/* $NetBSD: ntfs_ihash.c,v 1.1 2002/12/23 17:38:32 jdolecek Exp $ */
/*
@@ -41,6 +41,8 @@
#include <sys/malloc.h>
#include <sys/mount.h>
+#include <crypto/siphash.h>
+
#include <ntfs/ntfs.h>
#include <ntfs/ntfs_inode.h>
#include <ntfs/ntfs_ihash.h>
@@ -48,9 +50,11 @@
/*
* Structures associated with inode cacheing.
*/
+u_int ntfs_hash(dev_t, ntfsino_t);
static LIST_HEAD(nthashhead, ntnode) *ntfs_nthashtbl;
+static SIPHASH_KEY ntfs_nthashkey;
static u_long ntfs_nthash; /* size of hash table - 1 */
-#define NTNOHASH(device, inum) ((minor(device) + (inum)) & ntfs_nthash)
+#define NTNOHASH(device, inum) ntfs_hash((device), (inum))
struct rwlock ntfs_hashlock = RWLOCK_INITIALIZER("ntfs_nthashlock");
/*
@@ -72,6 +76,20 @@ ntfs_nthashinit(void)
}
ntfs_nthashtbl = nthashtbl;
ntfs_nthash = nthash;
+
+ arc4random_buf(&ntfs_nthashkey, sizeof(ntfs_nthashkey));
+}
+
+u_int
+ntfs_hash(dev_t dev, ntfsino_t inum)
+{
+ SIPHASH_CTX ctx;
+
+ SipHash24_Init(&ctx, &ntfs_nthashkey);
+ SipHash24_Update(&ctx, &dev, sizeof(dev));
+ SipHash24_Update(&ctx, &inum, sizeof(inum));
+
+ return (SipHash24_End(&ctx) & ntfs_nthash);
}
/*
diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c
index 3caf5b6ea5c..747a41082aa 100644
--- a/sys/ufs/ffs/ffs_softdep.c
+++ b/sys/ufs/ffs/ffs_softdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ffs_softdep.c,v 1.128 2014/07/12 18:44:01 tedu Exp $ */
+/* $OpenBSD: ffs_softdep.c,v 1.129 2014/11/18 10:42:15 dlg Exp $ */
/*
* Copyright 1998, 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -52,6 +52,7 @@
#include <sys/systm.h>
#include <sys/vnode.h>
#include <sys/specdev.h>
+#include <crypto/siphash.h>
#include <ufs/ufs/dir.h>
#include <ufs/ufs/quota.h>
#include <ufs/ufs/inode.h>
@@ -938,14 +939,13 @@ softdep_flushfiles(struct mount *oldmnt, int flags, struct proc *p)
#define DEPALLOC 0x0001 /* allocate structure if lookup fails */
#define NODELAY 0x0002 /* cannot do background work */
+SIPHASH_KEY softdep_hashkey;
+
/*
* Structures and routines associated with pagedep caching.
*/
LIST_HEAD(pagedep_hashhead, pagedep) *pagedep_hashtbl;
u_long pagedep_hash; /* size of hash table - 1 */
-#define PAGEDEP_HASH(mp, inum, lbn) \
- (&pagedep_hashtbl[((((register_t)(mp)) >> 13) + (inum) + (lbn)) & \
- pagedep_hash])
STATIC struct sema pagedep_in_progress;
/*
@@ -959,6 +959,7 @@ STATIC int
pagedep_lookup(struct inode *ip, daddr_t lbn, int flags,
struct pagedep **pagedeppp)
{
+ SIPHASH_CTX ctx;
struct pagedep *pagedep;
struct pagedep_hashhead *pagedephd;
struct mount *mp;
@@ -971,7 +972,12 @@ pagedep_lookup(struct inode *ip, daddr_t lbn, int flags,
panic("pagedep_lookup: lock not held");
#endif
mp = ITOV(ip)->v_mount;
- pagedephd = PAGEDEP_HASH(mp, ip->i_number, lbn);
+
+ SipHash24_Init(&ctx, &softdep_hashkey);
+ SipHash24_Update(&ctx, &mp, sizeof(mp));
+ SipHash24_Update(&ctx, &ip->i_number, sizeof(ip->i_number));
+ SipHash24_Update(&ctx, &lbn, sizeof(lbn));
+ pagedephd = &pagedep_hashtbl[SipHash24_End(&ctx) & pagedep_hash];
top:
LIST_FOREACH(pagedep, pagedephd, pd_hash)
if (ip->i_number == pagedep->pd_ino &&
@@ -1015,8 +1021,6 @@ top:
LIST_HEAD(inodedep_hashhead, inodedep) *inodedep_hashtbl;
STATIC u_long inodedep_hash; /* size of hash table - 1 */
STATIC long num_inodedep; /* number of inodedep allocated */
-#define INODEDEP_HASH(fs, inum) \
- (&inodedep_hashtbl[((((register_t)(fs)) >> 13) + (inum)) & inodedep_hash])
STATIC struct sema inodedep_in_progress;
/*
@@ -1029,6 +1033,7 @@ STATIC int
inodedep_lookup(struct fs *fs, ufsino_t inum, int flags,
struct inodedep **inodedeppp)
{
+ SIPHASH_CTX ctx;
struct inodedep *inodedep;
struct inodedep_hashhead *inodedephd;
int firsttry;
@@ -1040,7 +1045,10 @@ inodedep_lookup(struct fs *fs, ufsino_t inum, int flags,
panic("inodedep_lookup: lock not held");
#endif
firsttry = 1;
- inodedephd = INODEDEP_HASH(fs, inum);
+ SipHash24_Init(&ctx, &softdep_hashkey);
+ SipHash24_Update(&ctx, &fs, sizeof(fs));
+ SipHash24_Update(&ctx, &inum, sizeof(inum));
+ inodedephd = &inodedep_hashtbl[SipHash24_End(&ctx) & inodedep_hash];
top:
LIST_FOREACH(inodedep, inodedephd, id_hash)
if (inum == inodedep->id_ino && fs == inodedep->id_fs)
@@ -1092,8 +1100,6 @@ top:
*/
LIST_HEAD(newblk_hashhead, newblk) *newblk_hashtbl;
u_long newblk_hash; /* size of hash table - 1 */
-#define NEWBLK_HASH(fs, inum) \
- (&newblk_hashtbl[((((register_t)(fs)) >> 13) + (inum)) & newblk_hash])
STATIC struct sema newblk_in_progress;
/*
@@ -1105,10 +1111,14 @@ STATIC int
newblk_lookup(struct fs *fs, daddr_t newblkno, int flags,
struct newblk **newblkpp)
{
+ SIPHASH_CTX ctx;
struct newblk *newblk;
struct newblk_hashhead *newblkhd;
- newblkhd = NEWBLK_HASH(fs, newblkno);
+ SipHash24_Init(&ctx, &softdep_hashkey);
+ SipHash24_Update(&ctx, &fs, sizeof(fs));
+ SipHash24_Update(&ctx, &newblkno, sizeof(newblkno));
+ newblkhd = &newblk_hashtbl[SipHash24_End(&ctx) & newblk_hash];
top:
LIST_FOREACH(newblk, newblkhd, nb_hash)
if (newblkno == newblk->nb_newblkno && fs == newblk->nb_fs)
@@ -1155,6 +1165,7 @@ softdep_initialize(void)
#else
max_softdeps = desiredvnodes * 4;
#endif
+ arc4random_buf(&softdep_hashkey, sizeof(softdep_hashkey));
pagedep_hashtbl = hashinit(desiredvnodes / 5, M_PAGEDEP, M_WAITOK,
&pagedep_hash);
sema_init(&pagedep_in_progress, "pagedep", PRIBIO, 0);
diff --git a/sys/ufs/ufs/ufs_quota.c b/sys/ufs/ufs/ufs_quota.c
index 3e0faa649e2..fd3258fa2d6 100644
--- a/sys/ufs/ufs/ufs_quota.c
+++ b/sys/ufs/ufs/ufs_quota.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ufs_quota.c,v 1.35 2014/10/13 03:46:33 guenther Exp $ */
+/* $OpenBSD: ufs_quota.c,v 1.36 2014/11/18 10:42:15 dlg Exp $ */
/* $NetBSD: ufs_quota.c,v 1.8 1996/02/09 22:36:09 christos Exp $ */
/*
@@ -53,6 +53,8 @@
#include <sys/queue.h>
+#include <crypto/siphash.h>
+
/*
* The following structure records disk usage for a user or group on a
* filesystem. There is one allocated for each quota that exists on any
@@ -805,9 +807,8 @@ qsync(struct mount *mp)
/*
* Code pertaining to management of the in-core dquot data structures.
*/
-#define DQHASH(dqvp, id) \
- (&dqhashtbl[((((long)(dqvp)) >> 8) + id) & dqhash])
LIST_HEAD(dqhash, dquot) *dqhashtbl;
+SIPHASH_KEY dqhashkey;
u_long dqhash;
/*
@@ -824,6 +825,7 @@ void
ufs_quota_init(void)
{
dqhashtbl = hashinit(desiredvnodes, M_DQUOT, M_WAITOK, &dqhash);
+ arc4random_buf(&dqhashkey, sizeof(dqhashkey));
TAILQ_INIT(&dqfreelist);
}
@@ -835,6 +837,7 @@ int
dqget(struct vnode *vp, u_long id, struct ufsmount *ump, int type,
struct dquot **dqp)
{
+ SIPHASH_CTX ctx;
struct proc *p = curproc;
struct dquot *dq;
struct dqhash *dqh;
@@ -851,7 +854,11 @@ dqget(struct vnode *vp, u_long id, struct ufsmount *ump, int type,
/*
* Check the cache first.
*/
- dqh = DQHASH(dqvp, id);
+ SipHash24_Init(&ctx, &dqhashkey);
+ SipHash24_Update(&ctx, &dqvp, sizeof(dqvp));
+ SipHash24_Update(&ctx, &id, sizeof(id));
+ dqh = &dqhashtbl[SipHash24_End(&ctx) & dqhash];
+
LIST_FOREACH(dq, dqh, dq_hash) {
if (dq->dq_id != id ||
dq->dq_vp != dqvp)