Bug 250701 - [tty] [patch] Race condition between tty_wait_background() and doenterpgrp()
Summary: [tty] [patch] Race condition between tty_wait_background() and doenterpgrp()
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2020-10-28 19:47 UTC by Jakub Piecuch
Modified: 2022-10-17 13:47 UTC (History)
1 user (show)

See Also:


Attachments
Patch: check for process group change in tty_wait_background() (553 bytes, patch)
2020-10-28 19:47 UTC, Jakub Piecuch
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Piecuch 2020-10-28 19:47:39 UTC
Created attachment 219174 [details]
Patch: check for process group change in tty_wait_background()

The calling process's process group can change between PROC_UNLOCK(p) and PGRP_LOCK(pg) in tty_wait_background(), e.g. by a setpgid() call from another process. If that happens, the signal is not sent to the calling process, even if the prior checks determine that one should be sent.
The patch checks that the process group hasn't changed after acquiring the pgrp lock, and if it has, it redoes the checks.
Comment 1 commit-hook freebsd_committer freebsd_triage 2020-10-28 22:13:47 UTC
A commit references this bug:

Author: kib
Date: Wed Oct 28 22:12:47 UTC 2020
New revision: 367120
URL: https://svnweb.freebsd.org/changeset/base/367120

Log:
  Check for process group change in tty_wait_background().

  The calling process's process group can change between PROC_UNLOCK(p)
  and PGRP_LOCK(pg) in tty_wait_background(), e.g. by a setpgid() call
  from another process. If that happens, the signal is not sent to the
  calling process, even if the prior checks determine that one should be
  sent.  Re-check that the process group hasn't changed after acquiring
  the pgrp lock, and if it has, redo the checks.

  PR:	250701
  Submitted by:	Jakub Piecuch <j.piecuch96@gmail.com>
  MFC after:	2 weeks

Changes:
  head/sys/kern/tty.c
Comment 2 commit-hook freebsd_committer freebsd_triage 2020-11-11 00:43:28 UTC
A commit references this bug:

Author: kib
Date: Wed Nov 11 00:43:13 UTC 2020
New revision: 367582
URL: https://svnweb.freebsd.org/changeset/base/367582

Log:
  MFC r367120:
  Check for process group change in tty_wait_background().

  PR:	250701

Changes:
_U  stable/12/
  stable/12/sys/kern/tty.c
Comment 3 Graham Perrin freebsd_committer freebsd_triage 2022-10-17 12:39:07 UTC
Keyword: 

    patch
or  patch-ready

– in lieu of summary line prefix: 

    [patch]

* bulk change for the keyword
* summary lines may be edited manually (not in bulk). 

Keyword descriptions and search interface: 

    <https://bugs.freebsd.org/bugzilla/describekeywords.cgi>