Repository navigation
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
bb47b79 to
fc7f231
Compare
rminnich
left a comment
There was a problem hiding this comment.
can we find some way to NOT embed the private key. This is asking for trouble.
Maybe I'm missing something. But they're very easy to generate dynamically.
Replace client's forked CPU9P implementation with hugelgupf/p9's
fsimpl/localfs (which includes {dev, ino} QID collision avoidance
and full SetAttr/WriteAt/Readdir/Lock parity).
Note: this removes the exported CPU9P struct and narrows NewCPU9P(root)
to return p9.Attacher. NewCPU9P fails closed on an empty root,
unconditionally sets unix.O_NOCTTY on Unix, translates 9P2000.L wire
open flags (O_APPEND, O_TRUNC, O_SYNC, plus Unix O_NONBLOCK,
O_DIRECTORY, O_NOFOLLOW) into host os.OpenFile flags across OSes and
architectures, and rejects cross-implementation Link/RenameAt with EXDEV.
Also move default c.fileServer initialization from Cmd.Start into
Cmd.Dial before starting the 9P server goroutine, and bump go.mod to
go 1.26.0 as required by the updated hugelgupf/p9 and golang.org/x
dependencies.
Signed-off-by: Barret Rhoden <brho@google.com>
- Remove the duplicate c.SessionIn.Close() closer from c.closers; the stdin copy goroutine owns closing SessionIn and c.session.Close() already closes the channel, eliminating a data race on x/crypto/ssh.channel.sentEOF. - Call verbose() synchronously before spawning the stdout and stderr copy goroutines in Cmd.Start so detached goroutines do not read the package-global verbose hook concurrently with client.SetVerbose. - Fix !sameFD(c.Stdout, os.Stderr) to !sameFD(c.Stderr, os.Stderr) so Cmd.Start does not close os.Stderr. Signed-off-by: Barret Rhoden <brho@google.com>
- Remove embedded static SSH keys (server/key.go) and generate ephemeral
Ed25519 host and client keys per test in server/server_linux_test.go
with 0600 permissions.
- Move the Linux-only SSH key/config test helpers from server_test.go
into server_linux_test.go.
- Fix broken/racy daemon tests in server/server_linux_test.go and
server/server_test.go: pass TestDaemonConnectHelper flags cleanly to
client.Command, set c.Stdin and c.Env in both TestDaemonSession and
TestDaemonConnect (plus WithNameSpace("") and GOMAXPROCS/SetVerbose
cleanup in TestDaemonSession), remove racy c.SessionIn.Close() calls,
register -remote and -port9p in TestMain, synchronize SSH server and
handler shutdown with serveTestSSH, and save/restore package-global v
via setTestVerbose in the verbose-logging server tests.
Signed-off-by: Barret Rhoden <brho@google.com>
fc7f231 to
64ac4aa
Compare
|
(from gemini) @rminnich Addressed all review feedback and force-pushed a clean 7-commit stack (
|
| // or variants. This lets us use a listen deadline. | ||
| if c.Ninep { | ||
| if c.fileServer == nil { | ||
| c.fileServer = NewCPU9P(c.Root) |
There was a problem hiding this comment.
where is NewCPU9P defined? somewhere in the client package?
There was a problem hiding this comment.
(from gemini) It's defined in the same client package at client/cpu9p.go:46 (added in commit 1). It wraps hugelgupf/p9/fsimpl/localfs.Attacher(root) to fail closed on root == "" (instead of exporting "/") and translate Linux 9P2000.L wire open flags (O_APPEND, O_TRUNC, O_SYNC, O_NONBLOCK, etc.) to host OS flags.
| return attr.Mode.FileType(), nil | ||
| } | ||
|
|
||
| // checkPath walks from the attached root one component at a time to ensure no |
There was a problem hiding this comment.
can you explain more about this and the need for the extra root FID?
There was a problem hiding this comment.
(from gemini) Because upstream localfs stores only a path string l.path (not a pinned dirfd), a fid walked while /export/d was a directory silently follows /export/d if it is later unlinked and replaced with a symlink to /etc. checkPath re-walks every component of f.relPath from "/" one step at a time and verifies all intermediates are TypeDir (plus the leaf type). The extra cloned root FID (filter9PRoot via f.Walk(nil) at Attach time) is needed because (a) filter9PFile only speaks p9.File (no host paths), (b) the client can clunk its own root fid while keeping descendant fids open, and (c) re-calling localfs.Attacher.Attach() on every op calls syscall.Umask(0). Downside: O(depth) Lstat syscalls per unopened path-based op; fixed at the root in hugelgupf/p9#138.
| type filter9PAttacher struct { | ||
| p9.Attacher | ||
| allow allowList | ||
| mu sync.RWMutex |
There was a problem hiding this comment.
i see this mutex used a lot - what exactly does it protect?
There was a problem hiding this comment.
(from gemini) filter9PAttacher.mu protects three things: (1) check-then-use atomicity between checkPath and backing localfs path-based syscalls against concurrent 9P mutations (upstream p9.Server's per-pathNode opMu and renameMu don't cover target locking in Tlink, descendant locking in Tunlinkat, or xattr clunks), (2) f.relPath (mutated in Renamed, read everywhere else), and (3) f.root.file teardown in Close() against concurrent checkPath walks. Note the real downsides: it is a coarse attacher-wide RWMutex (widening stalls on blocking opens) and still cannot close TOCTOU against unrelated local host processes. Moving confinement into localfs itself (opened as hugelgupf/p9#138, plus server locking fixes in hugelgupf/p9#137) is the clean root fix.
| case pathExported: | ||
| // Reject symlinks and special files (FIFOs, sockets, devices) | ||
| // before opening so a blocking open(2) cannot hold attacher.mu | ||
| // and deadlock the 9P server. |
There was a problem hiding this comment.
blocking opens causing a deadlock is mildly worrisome. why are we holding attacher.mu, and what is the scenario where this deadlocks?
There was a problem hiding this comment.
(from gemini) This is the worst trade-off in filter9p.go. attacher.mu.RLock() is held across f.File.Open to stop a concurrent 9P UnlinkAt+Symlink/RenameAt between checkPath and localfs's os.OpenFile. Without checkRegularOrDir, if goroutine A blocks in Open(O_RDONLY) on a FIFO under RLock(), any mutating op B blocks on Lock(), which causes Go's sync.RWMutex to block all new RLocks — including goroutine C trying to Open(O_WRONLY) the other end of the FIFO to unblock A (and server disconnect hangs in cs.stop()). Upstream p9.Server's tlopen.handle already has a narrower version of this deadlock because it holds server.renameMu.RLock() across ref.file.Open (triggered if any Trename/Trenameat/Tremove/Tlink arrives); filter9p widens it to any mutation or final Close. Even with checkRegularOrDir (which bans FIFOs/devices), a hung NFS/FUSE mount can still stall RLock(). Pushing confinement into localfs (hugelgupf/p9#138) eliminates the need for attacher.mu/checkPath/checkRegularOrDir in any wrapper.
| return f.File.Readlink() | ||
| } | ||
|
|
||
| // Walk implements p9.File.Walk. |
There was a problem hiding this comment.
what's the strategy of Walk with respect to Open? Open has checks based on relPath. what are the goals of Walk? don't let clients walk to non-ancestor/non-allowed paths? or to make sure relPath is accurate? something else?
is there even a use case for letting someone walk to a non-exported/non-ancestor path?
we do want to be resilient to someone poking around for names, so i get that we want some checks in walk. (the ability to walk, even if you can't open, is still an info leak, and we might want to block other ops that don't require Open).
There was a problem hiding this comment.
(from gemini) Right — there is no use case for walking to a disallowed path, and Walk blocks it up front with os.ErrNotExist before touching the backing FS (preventing existence/QID/xattr probing and ensuring no disallowed fid ever exists). Walk also keeps relPath canonical (clamping ".." at "/") and steps one component at a time checking TypeDir so intermediate symlinks are never traversed. Open still needs classify(relPath) + checkPath because Walk legitimately hands out fids that must be restricted at Open time: (1) ancestor dirs (e.g. "/" and "/usr" for -namespace=/usr/bin) must be walkable/stat-able/filtered-Readdir-able, so Open restricts them to read-only and verifies checkDir (also preventing opening /etc/shadow if -namespace=/etc/shadow/sub); (2) symlinks inside exported dirs must be walkable for Lstat/Readlink/UnlinkAt, so Open rejects them because localfs.Local.Open calls os.OpenFile without O_NOFOLLOW; and (3) an ancestor could have been swapped for a symlink between Walk and Open.
| curPath = next | ||
| } | ||
|
|
||
| // Never traverse out of a non-directory or stale fid behind a symlink. |
There was a problem hiding this comment.
can you explain more about the symlink business?
There was a problem hiding this comment.
(from gemini) Three symlink escapes in upstream hugelgupf/p9 + localfs: (1) Stale-fid intermediate-symlink escape (zero race needed): walk /export/d/shadow -> fidS, unlink shadow and d, symlink d -> /etc, then call Tlink(exportDir, fidS, "stolen") — upstream p9.Server's tlink never checks refTarget.isDeleted() (fixed in hugelgupf/p9#137) and localfs calls os.Link on the stale path string (fixed in hugelgupf/p9#138), hard-linking host /etc/shadow into /export/stolen (Tgetattr also allows deleted fids). (2) Leaf symlinks: symlinks inside exported dirs are allowed for Readlink, but upstream localfs Open/SetAttr/*Xattr and macOS Link follow leaf symlinks on the host (fixed in hugelgupf/p9#138). (3) Multi-component localfs.Local.Walk(["sym_etc", "shadow"]) joins paths and Lstats without rejecting intermediate symlinks (fixed in hugelgupf/p9#138).
64ac4aa to
2836090
Compare
|
(from gemini) Split this PR down to the first 3 commits ( The |
Replaces the client's forked
CPU9Pimplementation withgithub.com/hugelgupf/p9/fsimpl/localfs, fixesCmd.Start/CloseI/O races, and cleans up static test keys and daemon test races.The
-namespaceexport filtering (filter9p,NewFilterFS,-unsafe-export, and export-isolation tests) was split out tobrho/cpu:namespace-filterwhile generic 9P server andlocalfsconfinement fixes land upstream in hugelgupf/p9#137 and hugelgupf/p9#138 (once merged,go.modhere can bump to thatp9revision).Commits (
25e47fef..28360906)25e47fef—client: replace custom CPU9P with hugelgupf/p9/fsimpl/localfsCPU9Pcopy (client/cpu9p*.go,client/getattr_*.go,client/cpu_*.go) in favor ofgithub.com/hugelgupf/p9/fsimpl/localfs(gaining{dev, ino}QID collision avoidance andSetAttr/WriteAt/Readdir/Lockparity), and bumpsgo.modtogo 1.26.0.NewCPU9P(root)to returnp9.Attacher(failing closed on emptyroot, unconditionally settingunix.O_NOCTTYon Unix, translating 9P2000.L wire open flags to hostos.OpenFileflags across OSes/architectures, and returningEXDEVon cross-implementationLink/RenameAt), and moves defaultc.fileServerinit fromCmd.StarttoCmd.Dial.ccb73978—client: fix Cmd.Start/Close I/O races and stderr close bugc.SessionIn.Close()closer (fixingx/crypto/sshsentEOFrace), evaluatesverbose()synchronously before spawning stdout/stderr goroutines, and fixes!sameFD(c.Stderr, os.Stderr).28360906—server: use ephemeral SSH keys and fix daemon test racesserver/key.go) and generates ephemeral Ed25519 keys per test (0600) inserver/server_linux_test.go.TestDaemonSession,TestDaemonConnect,TestMain, and SSH server/handler teardown synchronization (serveTestSSH,setTestVerbose).Testing
GOWORK=off go test -race -count=1 ./client/... ./cmds/... ./mount/... ./server/... ./session/... ./vm/...: PASS (unprivileged/tool-gated subtests skip as expected; untoucheddspackage has a pre-existing-raceissue onupstream/main)GOWORK=off go vet ./...: PASSgo vet ./client ./cmds/decpuandgo test -c ./clientforwindows/amd64,darwin/amd64, andfreebsd/amd64: PASS