Skip to content

Commit 0efd6f2

Browse files
teknoravergregkh
authored andcommitted
ipv4: don't set IPv6 only flags to IPv4 addresses
[ Upstream commit 2e60546 ] Avoid the situation where an IPV6 only flag is applied to an IPv4 address: # ip addr add 192.0.2.1/24 dev dummy0 nodad home mngtmpaddr noprefixroute # ip -4 addr show dev dummy0 2: dummy0: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000 inet 192.0.2.1/24 scope global noprefixroute dummy0 valid_lft forever preferred_lft forever Or worse, by sending a malicious netlink command: # ip -4 addr show dev dummy0 2: dummy0: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000 inet 192.0.2.1/24 scope global nodad optimistic dadfailed home tentative mngtmpaddr noprefixroute stable-privacy dummy0 valid_lft forever preferred_lft forever Signed-off-by: Matteo Croce <mcroce@redhat.com> Reviewed-by: David Ahern <dsahern@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4d285dc commit 0efd6f2

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

net/ipv4/devinet.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@
6767

6868
#include "fib_lookup.h"
6969

70+
#define IPV6ONLY_FLAGS \
71+
(IFA_F_NODAD | IFA_F_OPTIMISTIC | IFA_F_DADFAILED | \
72+
IFA_F_HOMEADDRESS | IFA_F_TENTATIVE | \
73+
IFA_F_MANAGETEMPADDR | IFA_F_STABLE_PRIVACY)
74+
7075
static struct ipv4_devconf ipv4_devconf = {
7176
.data = {
7277
[IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
@@ -453,6 +458,9 @@ static int __inet_insert_ifa(struct in_ifaddr *ifa, struct nlmsghdr *nlh,
453458
ifa->ifa_flags &= ~IFA_F_SECONDARY;
454459
last_primary = &in_dev->ifa_list;
455460

461+
/* Don't set IPv6 only flags to IPv4 addresses */
462+
ifa->ifa_flags &= ~IPV6ONLY_FLAGS;
463+
456464
for (ifap = &in_dev->ifa_list; (ifa1 = *ifap) != NULL;
457465
ifap = &ifa1->ifa_next) {
458466
if (!(ifa1->ifa_flags & IFA_F_SECONDARY) &&

0 commit comments

Comments
 (0)