Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c46b981e authored by Chiachang Wang's avatar Chiachang Wang
Browse files

Avoid incorrect nlmsg_type in returned INetDiagMessage

The target parsing mechanism focuses on SOCK_DIAG_BY_FAMILY.
The returned message with unexpected messages will cause
the parsing mechanism does not work as intended. Thus,
skip parsing on incorrect message.

Bug: 145275899
Bug: 142035706
Test: atest NetworkStackTests NetworkStackNextTests
Change-Id: I73ab979c735268551a54b0a88de18c6d1a2068c4
parent 4336b91f
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.net.netlink.NetlinkConstants.INET_DIAG_MEMINFO;
import static android.net.netlink.NetlinkConstants.NLA_ALIGNTO;
import static android.net.netlink.NetlinkConstants.NLMSG_DONE;
import static android.net.netlink.NetlinkConstants.SOCKDIAG_MSG_HEADER_SIZE;
import static android.net.netlink.NetlinkConstants.SOCK_DIAG_BY_FAMILY;
import static android.net.netlink.StructNlMsgHdr.NLM_F_DUMP;
import static android.net.netlink.StructNlMsgHdr.NLM_F_REQUEST;
import static android.net.util.DataStallUtils.CONFIG_MIN_PACKETS_THRESHOLD;
@@ -180,8 +181,15 @@ public class TcpSocketTracker {
                    }
                    final int nlmsgLen = nlmsghdr.nlmsg_len;
                    log("pollSocketsInfo: nlmsghdr=" + nlmsghdr);
                    // End of the message. Stop parsing.
                    if (nlmsghdr.nlmsg_type == NLMSG_DONE) break;

                    if (nlmsghdr.nlmsg_type != SOCK_DIAG_BY_FAMILY) {
                        Log.e(TAG, "Expect to get family " + family
                                + " SOCK_DIAG_BY_FAMILY message but get " + nlmsghdr.nlmsg_type);
                        break;
                    }

                    if (isValidInetDiagMsgSize(nlmsgLen)) {
                        // Get the socket cookie value. Composed by two Integers value.
                        // Corresponds to inet_diag_sockid in
+2 −2
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ public class TcpSocketTrackerTest {
    private static final String DIAG_MSG_HEX =
            // struct nlmsghdr.
            "00000058" +      // length = 88
            "0020" +         // type = SOCK_DIAG_BY_FAMILY
            "0014" +         // type = SOCK_DIAG_BY_FAMILY
            "0103" +         // flags = NLM_F_REQUEST | NLM_F_DUMP
            "00000000" +     // seqno
            "00000000" +     // pid (0 == kernel)
@@ -83,7 +83,7 @@ public class TcpSocketTrackerTest {
    private static final String SOCK_DIAG_TCP_INET_HEX =
            // struct nlmsghdr.
            "00000114" +        // length = 276
            "0020" +            // type = SOCK_DIAG_BY_FAMILY
            "0014" +            // type = SOCK_DIAG_BY_FAMILY
            "0103" +            // flags = NLM_F_REQUEST | NLM_F_DUMP
            "00000000" +        // seqno
            "00000000" +        // pid (0 == kernel)