Skip to content

Commit 3c89a5e

Browse files
authored
Merge pull request #2833 from acmcodercom/pidreuseattack
fixes: pid reuse attack when kill a exec process (release/1.1)
2 parents 0bb672d + 190c910 commit 3c89a5e

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

linux/proc/exec.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func (e *execProcess) setExited(status int) {
8989
e.status = status
9090
e.exited = time.Now()
9191
e.parent.platform.ShutdownConsole(context.Background(), e.console)
92+
e.pid = -1
9293
close(e.waitBlock)
9394
}
9495

@@ -115,7 +116,7 @@ func (e *execProcess) resize(ws console.WinSize) error {
115116

116117
func (e *execProcess) kill(ctx context.Context, sig uint32, _ bool) error {
117118
pid := e.pid
118-
if pid != 0 {
119+
if pid > 0 {
119120
if err := unix.Kill(pid, syscall.Signal(sig)); err != nil {
120121
return errors.Wrapf(checkKillError(err), "exec kill error")
121122
}
@@ -212,10 +213,14 @@ func (e *execProcess) Status(ctx context.Context) (string, error) {
212213
}
213214
e.mu.Lock()
214215
defer e.mu.Unlock()
215-
// if we don't have a pid then the exec process has just been created
216+
// if we don't have a pid(pid=0) then the exec process has just been created
216217
if e.pid == 0 {
217218
return "created", nil
218219
}
220+
// if we have a pid=-1 then the exec process has just been stopped
221+
if e.pid == -1 {
222+
return "stopped", nil
223+
}
219224
// if we have a pid and it can be signaled, the process is running
220225
if err := unix.Kill(e.pid, 0); err == nil {
221226
return "running", nil

0 commit comments

Comments
 (0)