casaroli opened a new pull request, #22376:
URL: https://github.com/apache/nuttx/pull/22376

   ## Summary
   
   `ipv6_setsockopt()` checked only that the option length is not 0. For 
`IPV6_JOIN_GROUP` and `IPV6_LEAVE_GROUP` it then gave the value to 
`mld_joingroup()` / `mld_leavegroup()`, which read a full `struct ipv6_mreq` 
(20 bytes). For `IPV6_MULTICAST_IF` it read an `int`. 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 `EINVAL` when the length is less than 
`sizeof(struct ipv6_mreq)` or `sizeof(int)`. `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.
   
   ## Impact
   
   `setsockopt()` with a short `IPV6_JOIN_GROUP`, `IPV6_LEAVE_GROUP` or 
`IPV6_MULTICAST_IF` option now fails with `EINVAL`. 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_ipv6` of `cmocka_net_mcast` 
(apache/nuttx-apps#NNNN): short `IPV6_JOIN_GROUP`, `IPV6_LEAVE_GROUP` and 
`IPV6_MULTICAST_IF` must fail with `EINVAL`.
   
   `cmocka_net_mcast` on sim:nsh with IPv6, UDP, loopback, ICMPv6 and MLD (CI 
image, apps with the new checks):
   
   | | master 28db4789c34 | this PR |
   |---|---|---|
   | `test_mcast_optlen_ipv6` | FAIL: `0 != -1` at `test_mcast_ipv6.c:211` (the 
short `IPV6_JOIN_GROUP` succeeds) | pass |
   | other 5 cases | pass | pass |
   
   Builds with `-Werror` in 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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to