From e9c96727e7e42c0ef6ff8edf79087b81a5fb5082 Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Mon, 13 Jun 2022 19:46:36 +0900 Subject: Fix listing of interfaces with ID > 255 get_ifi_info_linuxv6 only reads up to 2 hexadecimal characters for interface indexes, so interface indexes above 255 cannot be used. Use %x instead of %02x to remove this limitation. This is what upstream used up to version 878.270.2, after which mdnsresponder stopped using /proc to list interfaces. Only the interface index reading is changed to keep the change minimal. Test: atest NsdManagerTest --rerun-until-failure 100 Bug: 235797641 Change-Id: Iddca5052e7d76bc7878f0442acb9ccd67cbb620f --- mDNSPosix/mDNSUNP.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mDNSPosix/mDNSUNP.c b/mDNSPosix/mDNSUNP.c index 5379b6b..f5d0c52 100755 --- a/mDNSPosix/mDNSUNP.c +++ b/mDNSPosix/mDNSUNP.c @@ -106,7 +106,7 @@ struct ifi_info *get_ifi_info_linuxv6(int family, int doaliases) goto gotError; } while (fscanf(fp, - "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %15s\n", + "%4s%4s%4s%4s%4s%4s%4s%4s %x %02x %02x %02x %15s\n", addr[0],addr[1],addr[2],addr[3], addr[4],addr[5],addr[6],addr[7], &index, &plen, &scope, &flags, ifname) != EOF) { -- cgit v1.2.3 From e5434e1b07089809ca46b65276f8de612f4ba715 Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Tue, 14 Jun 2022 17:05:57 +0900 Subject: Avoid undefined behavior with high interface index Behavior of bitwise left shift is undefined when the right operator is greater than the number of bits in the left operand; so the code relied on undefined behavior when interface indexes were >= 32. Just use a boolean instead, as the result was only used as a boolean. Also do not limit reads in if_inet6 to 1 byte for address flags, scope value, and prefix length, as there is no good reason to do so, and this is in line with more recent upstream versions and the interface index read. In practice prefix length, scope value and interface flags should not be above 255 so this should be a no-op. Bug: 235797641 Test: atest NsdManagerTest --rerun-until-failure 50 Change-Id: I41fae1900400779cecb715e8cfb1e662b88fd41d --- mDNSPosix/mDNSPosix.c | 22 +++++++++------------- mDNSPosix/mDNSUNP.c | 2 +- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c index 8960c93..28f4e06 100644 --- a/mDNSPosix/mDNSPosix.c +++ b/mDNSPosix/mDNSPosix.c @@ -1102,14 +1102,14 @@ mDNSlocal void PrintNetLinkMsg(const struct nlmsghdr *pNLMsg) } #endif -mDNSlocal mDNSu32 ProcessRoutingNotification(int sd) +mDNSlocal mDNSBool ProcessRoutingNotification(int sd) // Read through the messages on sd and if any indicate that any interface records should // be torn down and rebuilt, return affected indices as a bitmask. Otherwise return 0. { ssize_t readCount; char buff[4096]; struct nlmsghdr *pNLMsg = (struct nlmsghdr*) buff; - mDNSu32 result = 0; + mDNSBool result = mDNSfalse; // The structure here is more complex than it really ought to be because, // unfortunately, there's no good way to size a buffer in advance large @@ -1144,10 +1144,9 @@ mDNSlocal mDNSu32 ProcessRoutingNotification(int sd) #endif // Process the NetLink message - if (pNLMsg->nlmsg_type == RTM_GETLINK || pNLMsg->nlmsg_type == RTM_NEWLINK) - result |= 1 << ((struct ifinfomsg*) NLMSG_DATA(pNLMsg))->ifi_index; - else if (pNLMsg->nlmsg_type == RTM_DELADDR || pNLMsg->nlmsg_type == RTM_NEWADDR) - result |= 1 << ((struct ifaddrmsg*) NLMSG_DATA(pNLMsg))->ifa_index; + if (pNLMsg->nlmsg_type == RTM_GETLINK || pNLMsg->nlmsg_type == RTM_NEWLINK || + pNLMsg->nlmsg_type == RTM_DELADDR || pNLMsg->nlmsg_type == RTM_NEWADDR) + result = mDNStrue; // Advance pNLMsg to the next message in the buffer if ((pNLMsg->nlmsg_flags & NLM_F_MULTI) != 0 && pNLMsg->nlmsg_type != NLMSG_DONE) @@ -1191,14 +1190,14 @@ mDNSlocal void PrintRoutingSocketMsg(const struct ifa_msghdr *pRSMsg) } #endif -mDNSlocal mDNSu32 ProcessRoutingNotification(int sd) +mDNSlocal mDNSBool ProcessRoutingNotification(int sd) // Read through the messages on sd and if any indicate that any interface records should // be torn down and rebuilt, return affected indices as a bitmask. Otherwise return 0. { ssize_t readCount; char buff[4096]; struct ifa_msghdr *pRSMsg = (struct ifa_msghdr*) buff; - mDNSu32 result = 0; + mDNSBool result = mDNSfalse; readCount = read(sd, buff, sizeof buff); if (readCount < (ssize_t) sizeof(struct ifa_msghdr)) @@ -1212,10 +1211,7 @@ mDNSlocal mDNSu32 ProcessRoutingNotification(int sd) if (pRSMsg->ifam_type == RTM_NEWADDR || pRSMsg->ifam_type == RTM_DELADDR || pRSMsg->ifam_type == RTM_IFINFO) { - if (pRSMsg->ifam_type == RTM_IFINFO) - result |= 1 << ((struct if_msghdr*) pRSMsg)->ifm_index; - else - result |= 1 << pRSMsg->ifam_index; + result = mDNStrue; } return result; @@ -1228,7 +1224,7 @@ mDNSlocal void InterfaceChangeCallback(int fd, short filter, void *context) { IfChangeRec *pChgRec = (IfChangeRec*) context; fd_set readFDs; - mDNSu32 changedInterfaces = 0; + mDNSBool changedInterfaces = mDNSfalse; struct timeval zeroTimeout = { 0, 0 }; (void)fd; // Unused diff --git a/mDNSPosix/mDNSUNP.c b/mDNSPosix/mDNSUNP.c index f5d0c52..0e3632b 100755 --- a/mDNSPosix/mDNSUNP.c +++ b/mDNSPosix/mDNSUNP.c @@ -106,7 +106,7 @@ struct ifi_info *get_ifi_info_linuxv6(int family, int doaliases) goto gotError; } while (fscanf(fp, - "%4s%4s%4s%4s%4s%4s%4s%4s %x %02x %02x %02x %15s\n", + "%4s%4s%4s%4s%4s%4s%4s%4s %x %x %x %x %15s\n", addr[0],addr[1],addr[2],addr[3], addr[4],addr[5],addr[6],addr[7], &index, &plen, &scope, &flags, ifname) != EOF) { -- cgit v1.2.3 From b93f834c15082e31719987db8bd1167f3d45b6e6 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Fri, 24 Jun 2022 14:56:20 +0900 Subject: Set min_sdk_version This was done via the hard-coded list in build/soong. Bug: 158059172 Test: m Change-Id: I50bb1965908beb694a3b417268beb0d8c510b3bd --- Android.bp | 1 + 1 file changed, 1 insertion(+) diff --git a/Android.bp b/Android.bp index ff8eec8..0aba986 100644 --- a/Android.bp +++ b/Android.bp @@ -175,6 +175,7 @@ cc_library { static_libs: ["libcutils"], shared_libs: ["liblog"], + min_sdk_version: "apex_inherit", apex_available: [ "//apex_available:platform", "com.android.adbd", -- cgit v1.2.3 From 0a1101c3db8e2a4b014080979dfba3c8392443ae Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Fri, 24 Jun 2022 14:56:20 +0900 Subject: Set min_sdk_version This was done via the hard-coded list in build/soong. Bug: 158059172 Test: m Merged-In: I50bb1965908beb694a3b417268beb0d8c510b3bd Change-Id: I50bb1965908beb694a3b417268beb0d8c510b3bd --- Android.bp | 1 + 1 file changed, 1 insertion(+) diff --git a/Android.bp b/Android.bp index ff8eec8..0aba986 100644 --- a/Android.bp +++ b/Android.bp @@ -175,6 +175,7 @@ cc_library { static_libs: ["libcutils"], shared_libs: ["liblog"], + min_sdk_version: "apex_inherit", apex_available: [ "//apex_available:platform", "com.android.adbd", -- cgit v1.2.3 From a51a7b3327ed4010c09058e707180a5575f80e95 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Fri, 24 Jun 2022 14:56:20 +0900 Subject: Set min_sdk_version This was done via the hard-coded list in build/soong. Bug: 158059172 Test: m Merged-In: I50bb1965908beb694a3b417268beb0d8c510b3bd Change-Id: I50bb1965908beb694a3b417268beb0d8c510b3bd (cherry picked from commit 100644d2af7e8c4c2840f446931f49d7710274da) --- Android.bp | 1 + 1 file changed, 1 insertion(+) diff --git a/Android.bp b/Android.bp index ff8eec8..0aba986 100644 --- a/Android.bp +++ b/Android.bp @@ -175,6 +175,7 @@ cc_library { static_libs: ["libcutils"], shared_libs: ["liblog"], + min_sdk_version: "apex_inherit", apex_available: [ "//apex_available:platform", "com.android.adbd", -- cgit v1.2.3 From b63cb20590d8f4576d2d4be36cfca9c5b6a197f7 Mon Sep 17 00:00:00 2001 From: Ante Date: Fri, 24 Feb 2023 18:40:56 +0000 Subject: Fix UWB start/stop ranging causing mDNS drop Current mDNS implementation closes and re-opens all of the network interfaces when any of the existing interfaces changes. Since UWB on start/stop ranging modifies its interface, mDNS detects that as a significant enough change to restart all of its interfaces. This change prevents that behaviour since the UWB interface is not related to anything what mDNS does. If the detected interface change is neither an IPv4 or IPv6 capable interface and if the interface type is ARPHRD_IEEE802154 which is the IEEE 802.15.4 PHY and MAC standard that UWB uses, then mDNS will ignore it. Bug:265207453 Test: Verified manually after this fix is applied interfaces no longer restart on UWB start/stop ranging. Change-Id: I1c070d989769752fda92bbe9308ca5bfc7c2d3e5 --- mDNSPosix/mDNSPosix.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c index 28f4e06..fe899a6 100644 --- a/mDNSPosix/mDNSPosix.c +++ b/mDNSPosix/mDNSPosix.c @@ -55,6 +55,7 @@ #if USES_NETLINK #include +#include #include #include #else // USES_NETLINK @@ -1144,9 +1145,18 @@ mDNSlocal mDNSBool ProcessRoutingNotification(int sd) #endif // Process the NetLink message - if (pNLMsg->nlmsg_type == RTM_GETLINK || pNLMsg->nlmsg_type == RTM_NEWLINK || - pNLMsg->nlmsg_type == RTM_DELADDR || pNLMsg->nlmsg_type == RTM_NEWADDR) + if (pNLMsg->nlmsg_type == RTM_GETLINK || pNLMsg->nlmsg_type == RTM_DELADDR || + pNLMsg->nlmsg_type == RTM_NEWADDR) + { result = mDNStrue; + } + else if (pNLMsg->nlmsg_type == RTM_NEWLINK) + { + // Fix for UWB start/stop causing mdns drop. See b/265207453 + struct ifinfomsg *pIfInfo = (struct ifinfomsg*) NLMSG_DATA(pNLMsg); + if (pIfInfo->ifi_family != AF_UNSPEC || pIfInfo->ifi_type != ARPHRD_IEEE802154) + result = mDNStrue; + } // Advance pNLMsg to the next message in the buffer if ((pNLMsg->nlmsg_flags & NLM_F_MULTI) != 0 && pNLMsg->nlmsg_type != NLMSG_DONE) -- cgit v1.2.3 From 21d030fe4342697f1e99cdf57edce1948d7e0733 Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Tue, 14 Jun 2022 17:05:57 +0900 Subject: Avoid undefined behavior with high interface index Cherry-pick from aosp/2125173 Behavior of bitwise left shift is undefined when the right operator is greater than the number of bits in the left operand; so the code relied on undefined behavior when interface indexes were >= 32. Just use a boolean instead, as the result was only used as a boolean. Also do not limit reads in if_inet6 to 1 byte for address flags, scope value, and prefix length, as there is no good reason to do so, and this is in line with more recent upstream versions and the interface index read. In practice prefix length, scope value and interface flags should not be above 255 so this should be a no-op. Bug: 235797641 Test: atest NsdManagerTest --rerun-until-failure 50 Change-Id: I41fae1900400779cecb715e8cfb1e662b88fd41d Merged-In: I41fae1900400779cecb715e8cfb1e662b88fd41d --- mDNSPosix/mDNSPosix.c | 22 +++++++++------------- mDNSPosix/mDNSUNP.c | 2 +- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c index 8960c93..28f4e06 100644 --- a/mDNSPosix/mDNSPosix.c +++ b/mDNSPosix/mDNSPosix.c @@ -1102,14 +1102,14 @@ mDNSlocal void PrintNetLinkMsg(const struct nlmsghdr *pNLMsg) } #endif -mDNSlocal mDNSu32 ProcessRoutingNotification(int sd) +mDNSlocal mDNSBool ProcessRoutingNotification(int sd) // Read through the messages on sd and if any indicate that any interface records should // be torn down and rebuilt, return affected indices as a bitmask. Otherwise return 0. { ssize_t readCount; char buff[4096]; struct nlmsghdr *pNLMsg = (struct nlmsghdr*) buff; - mDNSu32 result = 0; + mDNSBool result = mDNSfalse; // The structure here is more complex than it really ought to be because, // unfortunately, there's no good way to size a buffer in advance large @@ -1144,10 +1144,9 @@ mDNSlocal mDNSu32 ProcessRoutingNotification(int sd) #endif // Process the NetLink message - if (pNLMsg->nlmsg_type == RTM_GETLINK || pNLMsg->nlmsg_type == RTM_NEWLINK) - result |= 1 << ((struct ifinfomsg*) NLMSG_DATA(pNLMsg))->ifi_index; - else if (pNLMsg->nlmsg_type == RTM_DELADDR || pNLMsg->nlmsg_type == RTM_NEWADDR) - result |= 1 << ((struct ifaddrmsg*) NLMSG_DATA(pNLMsg))->ifa_index; + if (pNLMsg->nlmsg_type == RTM_GETLINK || pNLMsg->nlmsg_type == RTM_NEWLINK || + pNLMsg->nlmsg_type == RTM_DELADDR || pNLMsg->nlmsg_type == RTM_NEWADDR) + result = mDNStrue; // Advance pNLMsg to the next message in the buffer if ((pNLMsg->nlmsg_flags & NLM_F_MULTI) != 0 && pNLMsg->nlmsg_type != NLMSG_DONE) @@ -1191,14 +1190,14 @@ mDNSlocal void PrintRoutingSocketMsg(const struct ifa_msghdr *pRSMsg) } #endif -mDNSlocal mDNSu32 ProcessRoutingNotification(int sd) +mDNSlocal mDNSBool ProcessRoutingNotification(int sd) // Read through the messages on sd and if any indicate that any interface records should // be torn down and rebuilt, return affected indices as a bitmask. Otherwise return 0. { ssize_t readCount; char buff[4096]; struct ifa_msghdr *pRSMsg = (struct ifa_msghdr*) buff; - mDNSu32 result = 0; + mDNSBool result = mDNSfalse; readCount = read(sd, buff, sizeof buff); if (readCount < (ssize_t) sizeof(struct ifa_msghdr)) @@ -1212,10 +1211,7 @@ mDNSlocal mDNSu32 ProcessRoutingNotification(int sd) if (pRSMsg->ifam_type == RTM_NEWADDR || pRSMsg->ifam_type == RTM_DELADDR || pRSMsg->ifam_type == RTM_IFINFO) { - if (pRSMsg->ifam_type == RTM_IFINFO) - result |= 1 << ((struct if_msghdr*) pRSMsg)->ifm_index; - else - result |= 1 << pRSMsg->ifam_index; + result = mDNStrue; } return result; @@ -1228,7 +1224,7 @@ mDNSlocal void InterfaceChangeCallback(int fd, short filter, void *context) { IfChangeRec *pChgRec = (IfChangeRec*) context; fd_set readFDs; - mDNSu32 changedInterfaces = 0; + mDNSBool changedInterfaces = mDNSfalse; struct timeval zeroTimeout = { 0, 0 }; (void)fd; // Unused diff --git a/mDNSPosix/mDNSUNP.c b/mDNSPosix/mDNSUNP.c index f5d0c52..0e3632b 100755 --- a/mDNSPosix/mDNSUNP.c +++ b/mDNSPosix/mDNSUNP.c @@ -106,7 +106,7 @@ struct ifi_info *get_ifi_info_linuxv6(int family, int doaliases) goto gotError; } while (fscanf(fp, - "%4s%4s%4s%4s%4s%4s%4s%4s %x %02x %02x %02x %15s\n", + "%4s%4s%4s%4s%4s%4s%4s%4s %x %x %x %x %15s\n", addr[0],addr[1],addr[2],addr[3], addr[4],addr[5],addr[6],addr[7], &index, &plen, &scope, &flags, ifname) != EOF) { -- cgit v1.2.3 From 9576bf06401ba22da50f8b64105a54971cea209b Mon Sep 17 00:00:00 2001 From: Ante Date: Fri, 24 Feb 2023 18:40:56 +0000 Subject: Fix UWB start/stop ranging causing mDNS drop Cherry-pick from aosp/2463529 Current mDNS implementation closes and re-opens all of the network interfaces when any of the existing interfaces changes. Since UWB on start/stop ranging modifies its interface, mDNS detects that as a significant enough change to restart all of its interfaces. This change prevents that behaviour since the UWB interface is not related to anything what mDNS does. If the detected interface change is neither an IPv4 or IPv6 capable interface and if the interface type is ARPHRD_IEEE802154 which is the IEEE 802.15.4 PHY and MAC standard that UWB uses, then mDNS will ignore it. Bug:265207453 Test: Verified manually after this fix is applied interfaces no longer restart on UWB start/stop ranging. Change-Id: I1c070d989769752fda92bbe9308ca5bfc7c2d3e5 Merged-In: I1c070d989769752fda92bbe9308ca5bfc7c2d3e5 --- mDNSPosix/mDNSPosix.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c index 28f4e06..fe899a6 100644 --- a/mDNSPosix/mDNSPosix.c +++ b/mDNSPosix/mDNSPosix.c @@ -55,6 +55,7 @@ #if USES_NETLINK #include +#include #include #include #else // USES_NETLINK @@ -1144,9 +1145,18 @@ mDNSlocal mDNSBool ProcessRoutingNotification(int sd) #endif // Process the NetLink message - if (pNLMsg->nlmsg_type == RTM_GETLINK || pNLMsg->nlmsg_type == RTM_NEWLINK || - pNLMsg->nlmsg_type == RTM_DELADDR || pNLMsg->nlmsg_type == RTM_NEWADDR) + if (pNLMsg->nlmsg_type == RTM_GETLINK || pNLMsg->nlmsg_type == RTM_DELADDR || + pNLMsg->nlmsg_type == RTM_NEWADDR) + { result = mDNStrue; + } + else if (pNLMsg->nlmsg_type == RTM_NEWLINK) + { + // Fix for UWB start/stop causing mdns drop. See b/265207453 + struct ifinfomsg *pIfInfo = (struct ifinfomsg*) NLMSG_DATA(pNLMsg); + if (pIfInfo->ifi_family != AF_UNSPEC || pIfInfo->ifi_type != ARPHRD_IEEE802154) + result = mDNStrue; + } // Advance pNLMsg to the next message in the buffer if ((pNLMsg->nlmsg_flags & NLM_F_MULTI) != 0 && pNLMsg->nlmsg_type != NLMSG_DONE) -- cgit v1.2.3