markj 7a979485ab Improve handling of control message truncation.
If a recvmsg(2) or recvmmsg(2) caller doesn't provide sufficient space
for all control messages, the kernel sets MSG_CTRUNC in the message
flags to indicate truncation of the control messages.  In the case
of SCM_RIGHTS messages, however, we were failing to dispose of the
rights that had already been externalized into the recipient's file
descriptor table.  Add a new function and mbuf type to handle this
cleanup task, and use it any time we fail to copy control messages
out to the recipient.  To simplify cleanup, control message truncation
is now only performed at control message boundaries.

The change also fixes a few related bugs:
- Rights could be leaked to the recipient process if an error occurred
  while copying out a message's contents.
- We failed to set MSG_CTRUNC if the truncation occurred on a control
  message boundary, e.g., if the caller received two control messages
  and provided only the exact amount of buffer space needed for the
  first.

PR:		131876
Reviewed by:	ed (previous version)
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D16561
2018-08-07 16:36:48 +00:00
..
2018-07-03 01:55:09 +00:00
2018-04-13 20:30:49 +00:00
2018-07-30 07:01:00 +00:00
2018-07-10 14:04:52 +00:00
2018-07-29 12:41:56 +00:00
2018-05-06 00:19:48 +00:00
2018-05-19 03:55:42 +00:00
2018-08-04 20:45:43 +00:00
2018-05-22 15:13:25 +00:00
2017-12-13 16:30:39 +00:00
2018-06-13 16:48:07 +00:00
2018-07-06 06:20:03 +00:00
2018-04-08 16:34:10 +00:00
2018-06-01 13:26:45 +00:00
2018-05-10 13:19:42 +00:00
2018-06-01 13:26:45 +00:00
2018-08-04 20:45:43 +00:00
2018-07-10 14:04:52 +00:00
2018-07-10 14:04:52 +00:00
2018-06-01 13:26:45 +00:00
2018-03-27 15:20:03 +00:00
2018-06-01 13:26:45 +00:00
2018-05-20 04:45:05 +00:00
2018-06-06 15:12:19 +00:00
2018-06-01 13:26:45 +00:00