kern: pwd_hold_proc() might dereference the NULL p_pd
pdunshare() calls pdescfree(), which stores NULL into p->p_pd, and only
then stores the new pwddesc. pwd_hold_proc() running in that window gets
NULL from pdhold() and dereferences it. pwd_hold_proc() assumed p_pd is
never NULL for a held process. Similarly, fork_norfproc() calls
pdescfree() before installing a new pwddesc for the current process
(rfork(RFCFDG) without RFPROC).
Close the gap with pdswap(), which publishes the new pwddesc before
releasing the old one.
Reported by: llm-postcr, markj
Reviewed by: markj
Fixes: 85c855d31b18 ("fd: add pwd_hold_proc")
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D61934
kern/kern_descrip.c: add pdswap() helper
It stores the new pwddesc into the target process's p_pd, then runs the
tail of pdescfree() on the old one.
Reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D61934
security/gnome-keyring: Restore HAVE_CMSGCRED lost in meson conversion
gnome-keyring 48.0 switched from autotools to meson and dropped the
setting of HAVE_CMSGCRED, which meant an unintended code-path was chosen
that broke communication in specific setups (i.e. mine, with using
pam_gnome_keyring.so and being in more than 1 group breaks the
LOCAL_CREDS fallback as it supplies a too small buffer).
Fix this, which also obsoletes the existing patch for that file.
This allows me to only enter my password once, instead of twice to
unlock the keyring for Firefox or Chromium when logging in via LightDM.
PR: 279669
Approved by: gnome (maintainer timeout)
Pull Request: https://github.com/freebsd/freebsd-ports/pull/671
ntsync(4): do not leak the priv when devfs_set_cdevpriv() fails
ntsync_open() ignored the error from devfs_set_cdevpriv(). The call
fails when the device is opened without a file, for instance by
ktrace(2), which opens the trace file with vn_open() and a NULL fp,
and only then checks the vnode type. The priv was attached to
nothing, so its destructor never ran and it leaked. The device node
is mode 0666, so any user could leak a priv with each ktrace(2) call.
Free the priv and return the error.
Fixes: 03ca6dbdb80d ("ntsync(4)")
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
ntsync(4): fix double free and leak of the per-open priv
ntsync_free_priv() took the priv lock again to test closed and
objs_cnt, after its caller had updated them and dropped the lock.
Once the priv was closed with no objects left, every caller that got
there saw that state. Two threads closing the last two objects, or a
thread closing the last object while another closed the device file,
could both free the priv, or one could lock it after the other had
freed it. Make the decision in the same critical section that
changes closed or objs_cnt, so that only the thread making the
transition frees the priv.
Also, closed was only set by d_close. The cdevsw does not specify
D_TRACKCLOSE, so devfs calls d_close only on the last close of the
device. When the device was opened more than once, every priv except
the one closed last was never marked closed and leaked. Set closed
from the cdevpriv destructor instead, which runs once for each open
file, when the file is closed or the device is destroyed. Remove
d_close, which is no longer needed.
[5 lines not shown]