dcavalca / rpms / linuxptp

Forked from rpms/linuxptp 2 years ago
Clone

Blame SOURCES/linuxptp-zerolength.patch

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