Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devlxd: Fix crash due to concurrent pidMapper map access #14771

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lxd/devlxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,9 @@ func hoistReq(f func(*Daemon, instance.Instance, http.ResponseWriter, *http.Requ
request.SetCtxValue(r, request.CtxProtocol, auth.AuthenticationMethodDevLXD)

conn := ucred.GetConnFromContext(r.Context())
cred, ok := pidMapper.m[conn.(*net.UnixConn)]
if !ok {

cred := pidMapper.GetConnUcred(conn.(*net.UnixConn))
if cred == nil {
http.Error(w, errPIDNotInContainer.Error(), http.StatusInternalServerError)
return
}
Expand Down Expand Up @@ -439,6 +440,14 @@ func (m *ConnPidMapper) ConnStateHandler(conn net.Conn, state http.ConnState) {
}
}

// GetConnUcred returns a previously stored ucred associated to a connection.
// Returns nil if no ucred found for the connection.
func (m *ConnPidMapper) GetConnUcred(conn *net.UnixConn) *unix.Ucred {
m.mLock.Lock()
defer m.mLock.Unlock()
return pidMapper.m[conn]
}

var errPIDNotInContainer = errors.New("Process ID not found in container")

func findContainerForPid(pid int32, s *state.State) (instance.Container, error) {
Expand Down
Loading