Skip to contentSkip to conversation

ipx: call ipxitf_put() in ioctl error path

PATCH Applied Dan Carpenter 3 participants 3 messages May 2, 2017 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 ipx: call ipxitf_put() in ioctl error path

We should call ipxitf_put() if the copy_to_user() fails.

net/ipx/af_ipx.c +2 -3
index 8a9219ff2e77..fa31ef29e3fa 100644
@@ -1168,11 +1168,10 @@ static int ipxitf_ioctl(unsigned int cmd, void __user *arg)
 		sipx->sipx_network	= ipxif->if_netnum;
 		memcpy(sipx->sipx_node, ipxif->if_node,
 			sizeof(sipx->sipx_node));
-		rc = -EFAULT;
+		rc = 0;
 		if (copy_to_user(arg, &ifr, sizeof(ifr)))
-			break;
+			rc = -EFAULT;
 		ipxitf_put(ipxif);
-		rc = 0;
 		break;
 	}
 	case SIOCAIPXITFCRT:
#3 lore raw
In reply to Dan Carpenter
Quoted 13 lines · Dan Carpenter

We should call ipxitf_put() if the copy_to_user() fails.

net/ipx/af_ipx.c +0 -0
index 8a9219ff2e77..fa31ef29e3fa 100644
@@ -1168,11 +1168,10 @@ static int ipxitf_ioctl(unsigned int cmd, void __user *arg)
                sipx->sipx_network      = ipxif->if_netnum;
                memcpy(sipx->sipx_node, ipxif->if_node,
                        sizeof(sipx->sipx_node));

net/ipx/af_ipx.c static int ipxitf_ioctl(unsigned int cmd, void __user *arg) · line 1177

Quoted 10 lines
net/ipx/af_ipx.c +2 -3
-               rc = -EFAULT;
+               rc = 0;
                if (copy_to_user(arg, &ifr, sizeof(ifr)))
-                       break;
+                       rc = -EFAULT;
                ipxitf_put(ipxif);
-               rc = 0;
                break;
        }
        case SIOCAIPXITFCRT:

This refcount overflow flaw (and resulting use-after-free) appears to be reachable from unprivileged userspace, though I think it requires an interface already be configured, so this is likely not much risk to most users. Someone more familiar with IPX should double-check...

And, of course, I should point out this flaw would have been blocked entirely by using refcount_t:
https://lkml.org/lkml/2017/3/17/193

And if it didn't require a configured interface, it would be mitigated with module autoload blocking:
https://lkml.org/lkml/2017/4/19/1088

(Yes, yes, I know both are still being worked on, but this is a good example to show another case where they'd have been useful.)

-Kees

Signature · 2 lines
Kees Cook
Pixel Security