Subject: [PATCH] nethost: ipv4 more correct loopback device handling. From: Eric W. Biederman Date: 1134241610 -0700 Always detect the loopback devince with IFF_LOOBACK. Don't allow putting addresses for other hosts on the loopback device. --- net/ipv4/devinet.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-) 6553b6aca63ece06d193dfb0d5fdeb1b231bf261 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 0b8e7ca..28db04d 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -183,7 +183,7 @@ static void in_dev_rcu_put(struct rcu_he static void inethost_destroy(struct nethost *host) { - /* FIXME is the lock correct in this function? */ + /* FIXME is the locking correct in this function? */ struct net_device *dev; if (!host) return; @@ -342,6 +342,13 @@ static int inet_insert_ifa(struct in_ifa return 0; } + /* Deny adding addresses owned by other hosts to the loopback device */ + if ((ifa->ifa_dev->dev->flags & IFF_LOOPBACK) && + (ifa->ifa_dev->dev != &ifa->ifa_host->loopback_dev)) { + inet_free_ifa(ifa); + return -EINVAL; + } + ifa->ifa_flags &= ~IFA_F_SECONDARY; last_primary = &in_dev->ifa_list; @@ -1050,7 +1057,7 @@ static int inetdev_event(struct notifier ASSERT_RTNL(); if (!in_dev) { - if (event == NETDEV_REGISTER && dev->type == ARPHRD_LOOPBACK) { + if (event == NETDEV_REGISTER && (dev->flags & IFF_LOOPBACK)) { in_dev = inetdev_init(dev); if (!in_dev) panic("devinet: Failed to create loopback\n"); @@ -1068,7 +1075,7 @@ static int inetdev_event(struct notifier case NETDEV_UP: if (dev->mtu < 68) break; - if (dev->type == ARPHRD_LOOPBACK) { + if (dev->flags & IFF_LOOPBACK) { struct in_ifaddr *ifa; if ((ifa = inet_alloc_ifa()) != NULL) { ifa->ifa_host = loopback_host(dev); -- 1.0.GIT