Repository navigation
net/inet: Check the option length of IPv6 multicast options. - #22376
Merged
Merged
Conversation
ipv6_setsockopt() checked only that value_len is not 0. Then IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP gave the value to mld_joingroup() and mld_leavegroup(), which read a full struct ipv6_mreq (20 bytes), and IPV6_MULTICAST_IF read an int. With a shorter option the kernel read past the end of the caller's buffer, and the call did not fail. Return EINVAL if value_len is less than sizeof(struct ipv6_mreq) for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP, and less than sizeof(int) for IPV6_MULTICAST_IF. MCAST_JOIN_GROUP in the same function and the IPv4 options in ipv4_setsockopt() already check the length. Linux also returns EINVAL for these lengths. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
xiaoxiang781216
approved these changes
Nov 26, 2026
|
GUIDINGLI
approved these changes
Nov 26, 2026
acassis
approved these changes
Nov 26, 2026
acassis
approved these changes
Nov 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ipv6_setsockopt()checked only that the option length is not 0. ForIPV6_JOIN_GROUPandIPV6_LEAVE_GROUPit then gave the value tomld_joingroup()/mld_leavegroup(), which read a fullstruct ipv6_mreq(20 bytes). ForIPV6_MULTICAST_IFit read anint. With a shorter option the kernel read past the end of the caller's buffer, and the call did not fail.Now these options return
EINVALwhen the length is less thansizeof(struct ipv6_mreq)orsizeof(int).MCAST_JOIN_GROUPin the same function and the IPv4 options inipv4_setsockopt()already check the length. Linux also returnsEINVALfor these lengths.Impact
setsockopt()with a shortIPV6_JOIN_GROUP,IPV6_LEAVE_GROUPorIPV6_MULTICAST_IFoption now fails withEINVAL. A call with the correct length does not change. No API, ABI or Kconfig change. The same in flat, protected and kernel builds and on all architectures.Testing
New checks in
test_mcast_optlen_ipv6ofcmocka_net_mcast(apache/nuttx-apps#4150): shortIPV6_JOIN_GROUP,IPV6_LEAVE_GROUPandIPV6_MULTICAST_IFmust fail withEINVAL.cmocka_net_mcaston sim:nsh with IPv6, UDP, loopback, ICMPv6 and MLD (CI image, apps with the new checks):test_mcast_optlen_ipv60 != -1attest_mcast_ipv6.c:211(the shortIPV6_JOIN_GROUPsucceeds)Builds with
-Werrorin the CI image (gcc 12.3): qemu-armv8a:netnsh and rv-virt:knetnsh64 (kernel) with IPv6, ICMPv6 and MLD; qemu-armv8a:netnsh, rv-virt:netnsh, rv-virt:knetnsh64; qemu-armv8a:knsh (kernel) with IPv4, IPv6, MLD.