[Bug]: libc/net: getifaddrs() drops and leaks secondary IPv6 addresses and leaves dangling ifa_name and uninitialized netmask/dstaddr pointers

オープン
#22,937 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@yashgoyal0110 がすでに取り組んでいます。

2026年12月5日 から。

  • #22941 @yashgoyal0110 による — オープン

評価

この issue はまだ評価されていません。

説明

Is there an existing issue for this?
  • I have searched the existing issues
Current Behavior

getifaddrs() and getmutil_ipv6addr() in libs/libc/net/lib_getifaddrs.c have several bugs:

  1. Secondary IPv6 addresses (eth0:0, eth0:1, ...) are overwritten and leaked when followed by another network interface:
    In getifaddrs() (line 350), getmutil_ipv6addr(sockfd, &req, myaddrs) appends secondary IPv6 address nodes to myaddrs->addrs.ifa_next and returns the new tail pointer of the linked list. However, getifaddrs() only checks if (getmutil_ipv6addr(sockfd, &req, myaddrs) == NULL) and discards the returned tail pointer, leaving myaddrs pointing to the primary IPv6 node. On the next interface iteration (i + 1), myaddrs->addrs.ifa_next = lib_zalloc(sizeof(*myaddrs)); (line 235) overwrites myaddrs->addrs.ifa_next, detaching and leaking all secondary IPv6 nodes for the previous interface.
  2. Dangling/cross-node ifa_name, missing sin6_scope_id, and invalid ifa_netmask / ifa_dstaddr / ifa_broadaddr pointers in getmutil_ipv6addr():
    In getmutil_ipv6addr() (lines 122–130), after memcpy(ifaddr->addrs.ifa_next, ifaddr, sizeof(struct myifaddrs)):
    • ifaddr->addrs.ifa_name is never updated to ifaddr->name, so it points into the previous node's name buffer.
    • ((FAR struct sockaddr_in6 *)&ifaddr->addr)->sin6_scope_id is not set to the interface index.
    • ifaddr->addrs.ifa_netmask, ifa_dstaddr, ifa_broadaddr, and ifa_data are unconditionally set to &ifaddr->netmask, &ifaddr->dstaddr, &ifaddr->broadaddr, and &ifaddr->hwaddr even when the interface has no destination/broadcast/hardware address or a different netmask on the alias eth0:index, instead of querying SIOCGLIFNETMASK / SIOCGLIFDSTADDR / SIOCGLIFBRDADDR for req and only setting pointers that exist.
  3. Primary IPv6 node after IPv4 node uses req.lifr_name after IPv4 ioctls and does not skip unspecified (0.0.0.0 / ::) addresses:
    When an interface has both IPv4 and IPv6 enabled, myaddrs->name should preserve the base interface name across all ioctls, and getmutil_ipv6addr() should restore req->lifr_name or query per-alias netmask/destination addresses cleanly.
Expected Behavior
  • getifaddrs() should assign myaddrs = getmutil_ipv6addr(sockfd, &req, myaddrs, i); so subsequent interfaces append to the true tail of the linked list without leaking secondary IPv6 nodes.
  • getmutil_ipv6addr() should set ifaddr->addrs.ifa_name = ifaddr->name, set sin6_scope_id = ifindex, query SIOCGLIFNETMASK / SIOCGLIFDSTADDR / SIOCGLIFBRDADDR for each secondary IPv6 alias, and only populate ifa_netmask, ifa_dstaddr/ifa_broadaddr, and ifa_data when valid.
Steps To Reproduce
  1. Configure an interface eth0 with multiple IPv6 addresses (CONFIG_NETDEV_MAX_IPv6_ADDR > 1) followed by another interface eth1 (higher ifindex).
  2. Call getifaddrs(&ifa) -> eth1 overwrites eth0's ifa_next, losing and leaking eth0's secondary IPv6 addresses.
Relevant log output
getifaddrs(): secondary IPv6 addresses on interface 1 overwritten and leaked when interface 2 is added
Architecture

all

Issue Area

C Library

主要言語
C
スター
4.1k
フォーク
1.8k
平均マージ
1日 2時間
マージ済み PR(30日)
881

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/nuttx のほかの issue

apache/nuttx の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。