Page MenuHomeFreeBSD

getpgrp(2), getsid(2): allow to call on zombies
ClosedPublic

Authored by kib on Jul 22 2026, 9:51 AM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Aug 20, 5:20 PM
Unknown Object (File)
Thu, Aug 20, 2:22 AM
Unknown Object (File)
Tue, Aug 18, 12:00 PM
Unknown Object (File)
Fri, Aug 14, 12:28 AM
Unknown Object (File)
Thu, Aug 13, 8:57 PM
Unknown Object (File)
Wed, Aug 12, 5:53 AM
Unknown Object (File)
Wed, Aug 12, 5:11 AM
Unknown Object (File)
Tue, Aug 11, 11:32 PM
Subscribers

Details

Reviewers
markj
kevans
kib
Summary

Also be more protective in getsid().

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

kib requested review of this revision.Jul 22 2026, 9:51 AM

Why?

sys/kern/kern_prot.c
247–250

There is no corresponding check p->p_pgrp != NULL in sys_getpgid() above.

I suspect it's impossible to have a NULL p->p_pgrp or p->p_pgrp->pg_session.

Why?

https://gitlab.haskell.org/ghc/ghc/-/work_items/27512#note_686988
> But the hypothesis here is that getpgid on a zombie process fails, probably ESRCH.
sys/kern/kern_prot.c
247–250

For p_pgrp yes, it is only cleared on reap.
But for the pg_session, I am not sure. What makes me wonder is the number of checks for p->p_session != NULL in the tree.

sys/kern/kern_prot.c
247–250

Yeah, it's not very clear to me either. I suspect it is always non-NULL. e.g., pgdelete() will unconditionally dereference pg_session.

252
kib marked 2 inline comments as done.Jul 22 2026, 10:01 PM
kib added inline comments.
sys/kern/kern_prot.c
247–250

I dropped the p_pgrp check, but kept pg_session. I think this should follow the existing pattern for now, and cleaned with the global sweep.

kib marked 2 inline comments as done.

Return error.

markj added inline comments.
sys/kern/kern_prot.c
252

Also need to initialize error to 0 for the pid == 0 case.

This revision is now accepted and ready to land.Jul 23 2026, 1:21 PM
This revision now requires review to proceed.Jul 23 2026, 3:13 PM
This revision is now accepted and ready to land.Jul 23 2026, 11:53 PM