Page MenuHomeFreeBSD

libcasper/libnv: various error handling changes
Needs ReviewPublic

Authored by kevans on Aug 8 2019, 9:27 PM.
Tags
None
Referenced Files
Unknown Object (File)
Feb 22 2024, 10:21 AM
Unknown Object (File)
Jan 11 2024, 11:49 AM
Unknown Object (File)
Jan 11 2024, 11:49 AM
Unknown Object (File)
Dec 20 2023, 2:02 AM
Unknown Object (File)
Oct 26 2023, 2:07 AM
Unknown Object (File)
Jul 3 2023, 11:14 PM
Unknown Object (File)
Jun 19 2023, 10:09 PM
Unknown Object (File)
Jan 25 2023, 2:18 PM
Subscribers

Details

Reviewers
markj
oshogbo
Summary

casper(3):
If nvlout is an error state before we attempt to send it, rebuild with just the final error to be passed back. This can happen for various reasons, but most of them seem to be either EMFILE/ENFILE/ENOMEM issues that would naturally clear up by creating a more minimal nvlist with a single nvpair. Regardless, we must try- libnv will not send out an nvlist that's in an error state.

cap_fileargs(3):
Attempt to handle EMFILE/ENFILE style errors in fileargs_add_cache. In one error case, the nvlist_add_nvlist(nvlout, fname, new) was setting EMFILE on nvlout and causing the send to later fail.

libnv(3):
recvmsg can kick back EMSGSIZE if the SCM_RIGHTS transfer can't happen due to EMFILE/ENFILE. Drain the recv buf if we've hit EMSGSIZE so that subsequent transfers can work as expected, rather than the current domino effect.

I'm not sure any of it's the most correct; the libnv(3) change could/should probably only drain enough bytes to hold the cmsg that can't happen (nfds * CMSG_SPACE(sizeof(int)) + sizeof(struct msghdr).

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 25760

Event Timeline

the libnv(3) change could/should probably only drain enough bytes to hold the cmsg that can't happen (nfds * CMSG_SPACE(sizeof(int)) + sizeof(struct msghdr).

I say that, but the subsequent buf_drain only ever reads one byte from the socket after the resulting EMSGSIZE.

Plugs a potential nvlist/fd leak in fileargs_add_cache. The fd is moved into new if it succeeds, and new is cloned into nvlout with the fd dup'd. Destroy new after nvlist_add whether it failed or not to plug it.

Leaving buf_drain alone for now -- it seems like we might periodically have more than one message queued that needs to be flushed, but it's not immediately clear to me. libnv has a somewhat rigid protocol to follow with this socket, so the current approach should generally be safe.