dcavalca / rpms / linuxptp

Forked from rpms/linuxptp 2 years ago
Clone

Blame SOURCES/linuxptp-zerolength.patch

e6f414
commit 6b61ba29c78e26109426429c6d6b354f6e4443cd
e6f414
Author: David Mirabito via Linuxptp-devel <linuxptp-devel@lists.sourceforge.net>
e6f414
Date:   Tue Mar 19 13:42:48 2019 +1100
e6f414
e6f414
    Avoid fault when receiving zero length packets
e6f414
    
e6f414
    The manpage for recvmsg says -1 will be returned on error, Zero indicates an
e6f414
    "orderly shutdown", presumably only in case of stream sockets.
e6f414
    Further, UNIX Network Programming, Vol 1 says ".. a return value of 0 from
e6f414
    recvfrom is acceptable for a datagram protocol"
e6f414
    
e6f414
    Such packets have been observed in the wild, aimed at PTP's multicast
e6f414
    address and port, possibly related to malformed management queries.
e6f414
    
e6f414
    Patch to properly check return from recvmesg and not trigger the fault
e6f414
    codepath. Instead, such packets are treated as "Bad Message" the same as
e6f414
    non-zero but still too-short UDP payloads.
e6f414
    
e6f414
    Signed-off-by: David Mirabito <davidjm@arista.com>
e6f414
e6f414
diff --git a/port.c b/port.c
e6f414
index ad9554f..9264211 100644
e6f414
--- a/port.c
e6f414
+++ b/port.c
e6f414
@@ -2563,7 +2563,7 @@ static enum fsm_event bc_event(struct port *p, int fd_index)
e6f414
 	msg->hwts.type = p->timestamping;
e6f414
 
e6f414
 	cnt = transport_recv(p->trp, fd, msg);
e6f414
-	if (cnt <= 0) {
e6f414
+	if (cnt < 0) {
e6f414
 		pr_err("port %hu: recv message failed", portnum(p));
e6f414
 		msg_put(msg);
e6f414
 		return EV_FAULT_DETECTED;
e6f414
diff --git a/sk.c b/sk.c
e6f414
index 30162eb..93ba77a 100644
e6f414
--- a/sk.c
e6f414
+++ b/sk.c
e6f414
@@ -359,7 +359,7 @@ int sk_receive(int fd, void *buf, int buflen,
e6f414
 	}
e6f414
 
e6f414
 	cnt = recvmsg(fd, &msg, flags);
e6f414
-	if (cnt < 1)
e6f414
+	if (cnt < 0)
e6f414
 		pr_err("recvmsg%sfailed: %m",
e6f414
 		       flags == MSG_ERRQUEUE ? " tx timestamp " : " ");
e6f414