Avoid fault when receiving zero length packets

The manpage for recvmsg says -1 will be returned on error, Zero indicates an
"orderly shutdown", presumably only in case of stream sockets.
Further, UNIX Network Programming, Vol 1 says ".. a return value of 0 from
recvfrom is acceptable for a datagram protocol"

Such packets have been observed in the wild, aimed at PTP's multicast
address and port, possibly related to malformed management queries.

Patch to properly check return from recvmesg and not trigger the fault
codepath. Instead, such packets are treated as "Bad Message" the same as
non-zero but still too-short UDP payloads.

Signed-off-by: David Mirabito <davidjm@arista.com>
master
David Mirabito via Linuxptp-devel 2019-03-19 13:42:48 +11:00 committed by Richard Cochran
parent 1b7a1e2cda
commit 6b61ba29c7
2 changed files with 2 additions and 2 deletions

2
port.c
View File

@ -2563,7 +2563,7 @@ static enum fsm_event bc_event(struct port *p, int fd_index)
msg->hwts.type = p->timestamping;
cnt = transport_recv(p->trp, fd, msg);
if (cnt <= 0) {
if (cnt < 0) {
pr_err("port %hu: recv message failed", portnum(p));
msg_put(msg);
return EV_FAULT_DETECTED;

2
sk.c
View File

@ -359,7 +359,7 @@ int sk_receive(int fd, void *buf, int buflen,
}
cnt = recvmsg(fd, &msg, flags);
if (cnt < 1)
if (cnt < 0)
pr_err("recvmsg%sfailed: %m",
flags == MSG_ERRQUEUE ? " tx timestamp " : " ");