nfs-utils: 2 CWE-407 defects, MOAD 0002-0005 CLEAN

nfs-utils-0001: client_lookup() non-FQDN branch O(N) linked list
  scan per call in support/export/client.c:289. With N unique
  wildcard/netgroup/subnet clients, export_read totals O(N^2).
  Fix: hash table for hostname lookup. 119x at N=4000.

nfs-utils-0002: get_exportlist() in utils/mountd/mountd.c,
  lookup_or_create_elist_entry O(E) path scan + insert_group
  O(G) dedup scan, both per export = O(E^2) total. Fix: hash
  tables for path lookup and group dedup. 73x at N=4000.

MOAD-0002 (intertangle): clientlist/exportlist globals are standard
  single-threaded daemon design, single execution context. CLEAN.
MOAD-0003 (leaked context): no __thread or pthread_getspecific. CLEAN.
MOAD-0004 (logged secret): gssd logs keytab paths and principal
  names (not credentials). No key material logged. CLEAN.
MOAD-0005 (thundering herd): caches protected by ple_lock mutex
  in gssd, single-threaded event loop in mountd. CLEAN.
This commit is contained in:
russell@unturf.com 2026-03-31 13:19:01 -04:00
parent 3001d5fcf9
commit 294ab0a792
24 changed files with 1872 additions and 0 deletions

View file

@ -0,0 +1,34 @@
--- a/utils/mountd/mountd.c
+++ b/utils/mountd/mountd.c
@@ -536,6 +536,15 @@
* 2. insert_group: linear scan of ex_groups linked list for
* duplicate group names, O(G) per insert = O(E*G) total.
*
+ * Fix: replace linked list scans with hash tables.
+ * - lookup_or_create_elist_entry: hash table keyed by e_path
+ * - insert_group: hash set per exportnode for group names
+ *
+ * Impact: NFS servers with thousands of exports (common in
+ * large HPC/enterprise deployments) experience slow MOUNT
+ * EXPORT responses. Doubling exports quadruples response time.
+ */
+/*
* Original code:
*
* static exportnode *lookup_or_create_elist_entry(exports *elist, nfs_export *exp)
@@ -558,6 +567,15 @@
* g->gr_next = e->ex_groups;
* e->ex_groups = g;
* }
+ *
+ * Patched: use GLib hash table or POSIX hsearch_r for path lookup,
+ * and a per-exportnode hash set for group dedup. Since mountd already
+ * links against libc, hsearch_r is available at zero dependency cost.
+ *
+ * Alternatively, since HASH_TABLE_SIZE (1021) already exists in
+ * exportfs.h for the export hash table, we can reuse the same
+ * strtoint() hash function from export.c to bucket paths, giving
+ * O(1) amortized lookup without adding new dependencies.
*/
static exportnode *lookup_or_create_elist_entry(exports *elist, nfs_export *exp)