diff options
| author | miller <millerresearch@gmail.com> | 2023-03-07 15:15:10 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-03-09 00:51:36 +0000 |
| commit | fc45eb388d3693e35b1aa97cb553d2a5083c8b2f (patch) | |
| tree | 75208ff52e2fb587404a5ea1056986a305a19a91 /src/syscall/syscall_plan9.go | |
| parent | d6fa0d2ef3fc29c38af2675d395a089cc73af996 (diff) | |
| download | go-fc45eb388d3693e35b1aa97cb553d2a5083c8b2f.tar.xz | |
syscall: avoid race in plan9 while syncing Chdir across goroutines
Because each M in Plan 9 runs in a separate OS process with its
own current working directory, a Chdir call in one goroutine needs
to be propagated to other goroutines before a subsequent syscall
with a local pathname (see #9428). This is done by function
syscall.Fixwd, but there is still a race if a goroutine is
preempted and rescheduled on a different M between calling Fixwd
and executing the syscall which it protects. By locking the
goroutine to its OS thread from the start of Fixwd to the end of
the protected syscall, this race can be prevented.
Fixes #58802.
Change-Id: I89c0e43ef4544b5bfb5db7d2158f13f24b42e1f6
Reviewed-on: https://go-review.googlesource.com/c/go/+/474055
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/syscall/syscall_plan9.go')
| -rw-r--r-- | src/syscall/syscall_plan9.go | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/src/syscall/syscall_plan9.go b/src/syscall/syscall_plan9.go index ca286c8c97..92414709ef 100644 --- a/src/syscall/syscall_plan9.go +++ b/src/syscall/syscall_plan9.go @@ -13,6 +13,7 @@ package syscall import ( "internal/oserror" + "runtime" "unsafe" ) @@ -301,7 +302,9 @@ func Await(w *Waitmsg) (err error) { } func Unmount(name, old string) (err error) { - fixwd(name, old) + if fixwd(name, old) { + defer runtime.UnlockOSThread() + } oldp, err := BytePtrFromString(old) if err != nil { return err @@ -384,49 +387,63 @@ func Getgroups() (gids []int, err error) { //sys open(path string, mode int) (fd int, err error) func Open(path string, mode int) (fd int, err error) { - fixwd(path) + if fixwd(path) { + defer runtime.UnlockOSThread() + } return open(path, mode) } //sys create(path string, mode int, perm uint32) (fd int, err error) func Create(path string, mode int, perm uint32) (fd int, err error) { - fixwd(path) + if fixwd(path) { + defer runtime.UnlockOSThread() + } return create(path, mode, perm) } //sys remove(path string) (err error) func Remove(path string) error { - fixwd(path) + if fixwd(path) { + defer runtime.UnlockOSThread() + } return remove(path) } //sys stat(path string, edir []byte) (n int, err error) func Stat(path string, edir []byte) (n int, err error) { - fixwd(path) + if fixwd(path) { + defer runtime.UnlockOSThread() + } return stat(path, edir) } //sys bind(name string, old string, flag int) (err error) func Bind(name string, old string, flag int) (err error) { - fixwd(name, old) + if fixwd(name, old) { + defer runtime.UnlockOSThread() + } return bind(name, old, flag) } //sys mount(fd int, afd int, old string, flag int, aname string) (err error) func Mount(fd int, afd int, old string, flag int, aname string) (err error) { - fixwd(old) + if fixwd(old) { + defer runtime.UnlockOSThread() + } return mount(fd, afd, old, flag, aname) } //sys wstat(path string, edir []byte) (err error) func Wstat(path string, edir []byte) (err error) { - fixwd(path) + if fixwd(path) { + defer runtime.UnlockOSThread() + } return wstat(path, edir) } |
