linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v2] ipv4: don't set IPv6 only flags to IPv4 addresses
@ 2019-07-01 17:01 Matteo Croce
  2019-07-01 17:19 ` David Ahern
  2019-07-01 18:32 ` David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Matteo Croce @ 2019-07-01 17:01 UTC (permalink / raw)
  To: netdev; +Cc: linux-kernel, David S. Miller, Alexey Kuznetsov, Hideaki YOSHIFUJI

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>
---
 net/ipv4/devinet.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index c6bd0f7a020a..c5ebfa199794 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -62,6 +62,11 @@
 #include <net/net_namespace.h>
 #include <net/addrconf.h>
 
+#define IPV6ONLY_FLAGS	\
+		(IFA_F_NODAD | IFA_F_OPTIMISTIC | IFA_F_DADFAILED | \
+		 IFA_F_HOMEADDRESS | IFA_F_TENTATIVE | \
+		 IFA_F_MANAGETEMPADDR | IFA_F_STABLE_PRIVACY)
+
 static struct ipv4_devconf ipv4_devconf = {
 	.data = {
 		[IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
@@ -468,6 +473,9 @@ static int __inet_insert_ifa(struct in_ifaddr *ifa, struct nlmsghdr *nlh,
 	ifa->ifa_flags &= ~IFA_F_SECONDARY;
 	last_primary = &in_dev->ifa_list;
 
+	/* Don't set IPv6 only flags to IPv4 addresses */
+	ifa->ifa_flags &= ~IPV6ONLY_FLAGS;
+
 	for (ifap = &in_dev->ifa_list; (ifa1 = *ifap) != NULL;
 	     ifap = &ifa1->ifa_next) {
 		if (!(ifa1->ifa_flags & IFA_F_SECONDARY) &&
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net v2] ipv4: don't set IPv6 only flags to IPv4 addresses
  2019-07-01 17:01 [PATCH net v2] ipv4: don't set IPv6 only flags to IPv4 addresses Matteo Croce
@ 2019-07-01 17:19 ` David Ahern
  2019-07-01 18:20   ` David Ahern
  2019-07-01 18:32 ` David Miller
  1 sibling, 1 reply; 4+ messages in thread
From: David Ahern @ 2019-07-01 17:19 UTC (permalink / raw)
  To: Matteo Croce, netdev
  Cc: linux-kernel, David S. Miller, Alexey Kuznetsov, Hideaki YOSHIFUJI

On 7/1/19 11:01 AM, Matteo Croce wrote:
> 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>
> ---
>  net/ipv4/devinet.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
> index c6bd0f7a020a..c5ebfa199794 100644
> --- a/net/ipv4/devinet.c
> +++ b/net/ipv4/devinet.c
> @@ -62,6 +62,11 @@
>  #include <net/net_namespace.h>
>  #include <net/addrconf.h>
>  
> +#define IPV6ONLY_FLAGS	\
> +		(IFA_F_NODAD | IFA_F_OPTIMISTIC | IFA_F_DADFAILED | \
> +		 IFA_F_HOMEADDRESS | IFA_F_TENTATIVE | \
> +		 IFA_F_MANAGETEMPADDR | IFA_F_STABLE_PRIVACY)
> +
>  static struct ipv4_devconf ipv4_devconf = {
>  	.data = {
>  		[IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
> @@ -468,6 +473,9 @@ static int __inet_insert_ifa(struct in_ifaddr *ifa, struct nlmsghdr *nlh,
>  	ifa->ifa_flags &= ~IFA_F_SECONDARY;
>  	last_primary = &in_dev->ifa_list;
>  
> +	/* Don't set IPv6 only flags to IPv4 addresses */
> +	ifa->ifa_flags &= ~IPV6ONLY_FLAGS;
> +
>  	for (ifap = &in_dev->ifa_list; (ifa1 = *ifap) != NULL;
>  	     ifap = &ifa1->ifa_next) {
>  		if (!(ifa1->ifa_flags & IFA_F_SECONDARY) &&
> 

I guess at this point we can fail the address add, so this is the best
option. rtm_to_ifaddr could set a message in extack about invalid flags
- not fail the change, just warn the user that flags will be ignored.

Reviewed-by: David Ahern <dsahern@gmail.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net v2] ipv4: don't set IPv6 only flags to IPv4 addresses
  2019-07-01 17:19 ` David Ahern
@ 2019-07-01 18:20   ` David Ahern
  0 siblings, 0 replies; 4+ messages in thread
From: David Ahern @ 2019-07-01 18:20 UTC (permalink / raw)
  To: Matteo Croce, netdev
  Cc: linux-kernel, David S. Miller, Alexey Kuznetsov, Hideaki YOSHIFUJI

On 7/1/19 11:19 AM, David Ahern wrote:
> I guess at this point we can fail the address add, so this is the best
> option. 

bleh, that should be 'can not'

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net v2] ipv4: don't set IPv6 only flags to IPv4 addresses
  2019-07-01 17:01 [PATCH net v2] ipv4: don't set IPv6 only flags to IPv4 addresses Matteo Croce
  2019-07-01 17:19 ` David Ahern
@ 2019-07-01 18:32 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2019-07-01 18:32 UTC (permalink / raw)
  To: mcroce; +Cc: netdev, linux-kernel, kuznet, yoshfuji

From: Matteo Croce <mcroce@redhat.com>
Date: Mon,  1 Jul 2019 19:01:55 +0200

> 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>

Applied and queued up for -stable, thanks Matteo.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-07-01 18:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-01 17:01 [PATCH net v2] ipv4: don't set IPv6 only flags to IPv4 addresses Matteo Croce
2019-07-01 17:19 ` David Ahern
2019-07-01 18:20   ` David Ahern
2019-07-01 18:32 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).