dcavalca / rpms / linuxptp

Forked from rpms/linuxptp 2 years ago
Clone

Blame SOURCES/linuxptp-zerolength.patch

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