]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ipv4: Check !in_dev earlier for ioctl(SIOCSIFADDR).
authorKuniyuki Iwashima <kuniyu@amazon.com>
Fri, 9 Aug 2024 23:54:02 +0000 (16:54 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 Oct 2024 10:00:18 +0000 (12:00 +0200)
[ Upstream commit e3af3d3c5b26c33a7950e34e137584f6056c4319 ]

dev->ip_ptr could be NULL if we set an invalid MTU.

Even then, if we issue ioctl(SIOCSIFADDR) for a new IPv4 address,
devinet_ioctl() allocates struct in_ifaddr and fails later in
inet_set_ifa() because in_dev is NULL.

Let's move the check earlier.

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Link: https://patch.msgid.link/20240809235406.50187-2-kuniyu@amazon.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/ipv4/devinet.c

index d09f557eaa7790baf83cf567bf7874d32f010de0..73effd2d2994abbe6dcc2aac99fb3e635e1b17f8 100644 (file)
@@ -574,10 +574,6 @@ static int inet_set_ifa(struct net_device *dev, struct in_ifaddr *ifa)
 
        ASSERT_RTNL();
 
-       if (!in_dev) {
-               inet_free_ifa(ifa);
-               return -ENOBUFS;
-       }
        ipv4_devconf_setall(in_dev);
        neigh_parms_data_state_setall(in_dev->arp_parms);
        if (ifa->ifa_dev != in_dev) {
@@ -1184,6 +1180,8 @@ int devinet_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr)
 
                if (!ifa) {
                        ret = -ENOBUFS;
+                       if (!in_dev)
+                               break;
                        ifa = inet_alloc_ifa();
                        if (!ifa)
                                break;