This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 24f2db7fe8d net/inet: Check the option length of IPv6 multicast
options.
24f2db7fe8d is described below
commit 24f2db7fe8de51b5c63991b09d0cbb73f8d7116a
Author: Marco Casaroli <[email protected]>
AuthorDate: Thu Nov 26 06:26:17 2026 +0100
net/inet: Check the option length of IPv6 multicast options.
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 <[email protected]>
---
net/inet/ipv6_setsockopt.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/net/inet/ipv6_setsockopt.c b/net/inet/ipv6_setsockopt.c
index 13e402f3417..68fb61e4d0f 100644
--- a/net/inet/ipv6_setsockopt.c
+++ b/net/inet/ipv6_setsockopt.c
@@ -90,11 +90,19 @@ int ipv6_setsockopt(FAR struct socket *psock, int option,
/* Handle MLD-related socket options */
case IPV6_JOIN_GROUP: /* Join a multicast group */
- ret = mld_joingroup(value);
- break;
-
case IPV6_LEAVE_GROUP: /* Quit a multicast group */
- ret = mld_leavegroup(value);
+ if (value_len < sizeof(struct ipv6_mreq))
+ {
+ ret = -EINVAL;
+ }
+ else if (option == IPV6_JOIN_GROUP)
+ {
+ ret = mld_joingroup(value);
+ }
+ else
+ {
+ ret = mld_leavegroup(value);
+ }
break;
case MCAST_JOIN_GROUP: /* Join a multicast group (RFC 3678) */
@@ -147,8 +155,15 @@ int ipv6_setsockopt(FAR struct socket *psock, int option,
{
FAR struct net_driver_s *dev;
FAR struct udp_conn_s *conn = psock->s_conn;
- int ifindex = *(FAR int *)value;
+ int ifindex;
+
+ if (value_len < sizeof(int))
+ {
+ ret = -EINVAL;
+ break;
+ }
+ ifindex = *(FAR int *)value;
if (ifindex > 0)
{
dev = netdev_findbyindex(ifindex);