At least netgraph calls pr_sockaddr and pr_peeraddr from within epoch (see ng_ksocket_rcvmsg -> NGM_KSOCKET_GETPEERNAME), which immediately panics with invariants due to malloc(..., M_WAITOK) performed there.
I think a second set of ops should be added which accepts passing a preallocated buffer, even something on-stack.
struct sockaddr has a small upper bound size, so this is very feasible.
Illustrative patch below. If network is ok with it, I'll make it operational.
Note that callers only need to allocate
__offsetof(struct sockaddr, sa_data) + SOCK_MAXADDRLEN
bytes. This can be hidden away in struct sockaddr_max or perhaps just a macro indicating the size.
Alternatively a set of routines which take malloc flags can be added, but imo this only adds a failure point (malloc returning NULL) which does not have to exist.
Comments? Note I don't care for specific names, just the mechanism.