Repository navigation
Conversation
A server could keep returning valid READDIR replies while sshfs retained the complete listing. The default cache could then duplicate those entries and retain a full child path for each one, allowing ordinary enumerations to exhaust client memory. Limit each SSHFS snapshot to 64 MiB. Keep that error sticky for the directory handle, clear partial snapshots, and drain completed async replies. Also bound readdir-derived cache nodes and retained directory entries globally while still returning uncached entries to FUSE.
| old_size = node != NULL ? node->dir_size : 0; | ||
| retained_count = cache.dir_count - old_count; | ||
| retained_size = cache.dir_size - old_size; | ||
| if (dir_count > cache.max_size || |
There was a problem hiding this comment.
Please reclaim expired data before node lookup and admission in both cache_add_dir() and the limited attribute path, then re-check the budgets. Cleanup must respond to a full cache while honoring min_clean_interval: admission stops at max_size, but the sweep requires size > max_size. In a fake-clock probe with three expired nodes after 30 seconds, head and reorder-only read a new directory twice; base reads it once.
| retained_count = cache.dir_count - old_count; | ||
| retained_size = cache.dir_size - old_size; | ||
| if (dir_count > cache.max_size || | ||
| retained_count > cache.max_size - dir_count || |
There was a problem hiding this comment.
Please free expired listing arrays and refund dir_count/dir_size independently of valid stat/link data, before this check. cache_clean_entry() only tests node->valid, so stat refreshes can keep expired listings charged indefinitely. In a fake-clock probe, an expired eight-entry listing still consumes a ten-entry budget after cleanup, preventing a five-entry directory from being cached. Moving cleanup earlier does not fix this.
| ch->dir = NULL; | ||
| ch->dir_size = 0; | ||
| } | ||
| if (!err && ch->dir != NULL) { |
There was a problem hiding this comment.
Please keep bounded attribute updates independent of ch->dir. Dropping the optional listing array currently skips updates even for existing nodes, adding avoidable backend getattr calls. With a three-node budget, a cached fifth child's expired attributes remain stale after a five-entry listing. Calling cache_add_attr_internal(..., 1) for successfully delivered entries refreshes that node without increasing the table size.
Limited readdir admission could reject new data while expired nodes or directory arrays still consumed the corresponding budget. Attribute refreshes also stopped after the optional listing array was discarded. Sweep expired state before bounded admissions, release expired directory arrays independently of other valid node data, and keep bounded attribute refreshes active even when the listing is not cached.
sshfs_readdir() builds a complete in-memory snapshot before returning entries to FUSE. An authenticated server can keep returning valid READDIR replies and grow that snapshot without bound. With the default directory cache, cache_dirfill() also duplicates entries and retains a full child path for each attribute, so ordinary enumeration of a malicious tree can exhaust client memory.
Cap each SSHFS directory snapshot at 64 MiB of accounted entry storage. Oversized snapshots fail with ENOMEM and remain failed for that directory handle, preventing automatic retries from rebuilding the allocation. Completed asynchronous replies are drained without retaining their entries.
Limit readdir-derived cache nodes to dcache_max_size and enforce aggregate count and 64 MiB byte budgets for cached directory arrays. Entries that do not fit the cache budget are still returned to FUSE; they are simply not retained in the optional cache.