Skip to contentSkip to conversation

IPv6 Network Discovery Boundary Variable and Packed Structure

PATCH In review [email protected] 4 participants 9 messages May 18, 2023 – Jul 27, 2023 Networking

lore
Share & tools
lore
#0 lore raw

cover IPv6 Network Discovery Boundary Variable and Packed Structure

From: Ehsan Mohandesi <[email protected]>

This series addresses the following.
1. Coverity Issue (CID 450971): Loop boundary variables should be checked to be within appropriate limits.
2. Making the structure icmp6_ra_prefix_info packed because it contains network protocol data received from the network.

Ehsan Mohandesi (2):
net: ipv6: router advertisement message length should be within limits
net: ipv6: network protocol structures should be packed

 include/net6.h | 2 +-
 net/ndisc.c    | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/2 net: ipv6: router advertisement message length should be within limits

From: Ehsan Mohandesi <[email protected]>

The argument len passed to function process_ra is the length of the IPv6 router advertisement message and needs to be between 0 and MTU because it is assigned to remaining_option_len and used as a loop variable.

Addresses-Coverity-ID: 450971 ("TAINTED_SCALAR")

---
 net/ndisc.c | 2 ++
 1 file changed, 2 insertions(+)
net/ndisc.c +2 -0
index 0b27779..d1cec06 100644
@@ -382,6 +382,8 @@ int process_ra(struct ip6_hdr *ip6, int len)
 	unsigned char type = 0;
 	struct icmp6_ra_prefix_info *prefix = NULL;
 
+	if (len > ETH_MAX_MTU)
+		return -EMSGSIZE;
 	/* Ignore the packet if router lifetime is 0. */
 	if (!icmp->icmp6_rt_lifetime)
 		return -EOPNOTSUPP;
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] net: ipv6: router advertisement message length should be within limits

Quoted 29 lines · On Thu, 2023-05-18 at 11:24 -0700, [email protected] wrote:

From: Ehsan Mohandesi <[email protected]>

The argument len passed to function process_ra is the length of the IPv6
router advertisement message and needs to be between 0 and MTU because
it is assigned to remaining_option_len and used as a loop variable.

Addresses-Coverity-ID: 450971 ("TAINTED_SCALAR")

---
 net/ndisc.c | 2 ++
 1 file changed, 2 insertions(+)
net/ndisc.c +2 -1
index 0b27779..d1cec06 100644
@@ -382,6 +382,8 @@ int process_ra(struct ip6_hdr *ip6, int len)
        unsigned char type = 0;
        struct icmp6_ra_prefix_info *prefix = NULL;
 
+       if (len > ETH_MAX_MTU)
+               return -EMSGSIZE;
        /* Ignore the packet if router lifetime is 0. */
        if (!icmp->icmp6_rt_lifetime)
                return -EOPNOTSUPP;
--
Quoted 3 lines

1.8.3.1

Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] net: ipv6: router advertisement message length should be within limits

In reply to [email protected]
Quoted 27 lines · On Thu, May 18, 2023 at 9:24 PM <[email protected]> wrote:

From: Ehsan Mohandesi <[email protected]>

The argument len passed to function process_ra is the length of the IPv6 router advertisement message and needs to be between 0 and MTU because it is assigned to remaining_option_len and used as a loop variable.

Addresses-Coverity-ID: 450971 ("TAINTED_SCALAR")

---
 net/ndisc.c | 2 ++
 1 file changed, 2 insertions(+)
net/ndisc.c +2 -1
index 0b27779..d1cec06 100644
@@ -382,6 +382,8 @@ int process_ra(struct ip6_hdr *ip6, int len)
        unsigned char type = 0;
        struct icmp6_ra_prefix_info *prefix = NULL;
 
+       if (len > ETH_MAX_MTU)
+               return -EMSGSIZE;
        /* Ignore the packet if router lifetime is 0. */
        if (!icmp->icmp6_rt_lifetime)
                return -EOPNOTSUPP;
--
Quoted 2 lines

1.8.3.1

#4 lore raw

Re: [PATCH 1/2] net: ipv6: router advertisement message length should be within limits

In reply to [email protected]
Quoted 10 lines · On Thu, May 18, 2023 at 11:24:38AM -0700, [email protected] wrote:

From: Ehsan Mohandesi <[email protected]>

The argument len passed to function process_ra is the length of the IPv6 router advertisement message and needs to be between 0 and MTU because it is assigned to remaining_option_len and used as a loop variable.

Addresses-Coverity-ID: 450971 ("TAINTED_SCALAR")

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#5 lore raw

PATCH 2/2 net: ipv6: network protocol structures should be packed

In reply to [email protected]

From: Ehsan Mohandesi <[email protected]>

The structure icmp6_ra_prefix_info needs to be packed because it is read from a network stream.

---
 include/net6.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net6.h +1 -1
index beafc05..1e766aa 100644
@@ -204,7 +204,7 @@ struct icmp6_ra_prefix_info {
 	 * be initialized to zero by the sender and ignored by the receiver.
 	 */
 	struct in6_addr prefix;
-};
+} __packed;
 
 extern struct in6_addr const net_null_addr_ip6;	/* NULL IPv6 address */
 extern struct in6_addr net_gateway6;	/* Our gateways IPv6 address */
Signature · 1 line
1.8.3.1
Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] net: ipv6: network protocol structures should be packed

Quoted 24 lines · On Thu, 2023-05-18 at 11:24 -0700, [email protected] wrote:

From: Ehsan Mohandesi <[email protected]>

The structure icmp6_ra_prefix_info needs to be packed because it is read
from a network stream.

---
 include/net6.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net6.h +0 -0
index beafc05..1e766aa 100644
@@ -204,7 +204,7 @@ struct icmp6_ra_prefix_info {
         * be initialized to zero by the sender and ignored by the

receiver.

         */
        struct in6_addr prefix;
include/net6.h +1 -1
-};
+} __packed;
 
 extern struct in6_addr const net_null_addr_ip6;        /* NULL IPv6
Quoted 7 lines

address */
extern struct in6_addr net_gateway6; /* Our gateways IPv6 address
*/
--
1.8.3.1

Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] net: ipv6: network protocol structures should be packed

In reply to [email protected]
Quoted 25 lines · On Thu, May 18, 2023 at 9:24 PM <[email protected]> wrote:

From: Ehsan Mohandesi <[email protected]>

The structure icmp6_ra_prefix_info needs to be packed because it is read from a network stream.

---
 include/net6.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net6.h +1 -2
index beafc05..1e766aa 100644
@@ -204,7 +204,7 @@ struct icmp6_ra_prefix_info {
         * be initialized to zero by the sender and ignored by the receiver.
         */
        struct in6_addr prefix;
-};
+} __packed;
 
 extern struct in6_addr const net_null_addr_ip6;        /* NULL IPv6 address */
 extern struct in6_addr net_gateway6;   /* Our gateways IPv6 address */
--
Quoted 2 lines

1.8.3.1

#8 lore raw

Re: [PATCH 2/2] net: ipv6: network protocol structures should be packed

In reply to [email protected]
Quoted 8 lines · On Thu, May 18, 2023 at 11:24:39AM -0700, [email protected] wrote:

From: Ehsan Mohandesi <[email protected]>

The structure icmp6_ra_prefix_info needs to be packed because it is read from a network stream.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom