Skip to content

Commit 4b153ca

Browse files
committed
Merge tag 'mac80211-for-davem-2017-06-16' of git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211
Johannes Berg says: ==================== Here's just the fix for that ancient bug: * remove wext calling ndo_do_ioctl, since nobody needs that now and it makes the type change easier * use struct iwreq instead of struct ifreq almost everywhere in wireless extensions code * copy only struct iwreq from userspace in dev_ioctl for the wireless extensions, since it's smaller than struct ifreq ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 46f8cd9 + 68dd02d commit 4b153ca

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

include/net/wext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
struct net;
77

88
#ifdef CONFIG_WEXT_CORE
9-
int wext_handle_ioctl(struct net *net, struct ifreq *ifr, unsigned int cmd,
9+
int wext_handle_ioctl(struct net *net, struct iwreq *iwr, unsigned int cmd,
1010
void __user *arg);
1111
int compat_wext_handle_ioctl(struct net *net, unsigned int cmd,
1212
unsigned long arg);
1313

1414
struct iw_statistics *get_wireless_stats(struct net_device *dev);
1515
int call_commit_handler(struct net_device *dev);
1616
#else
17-
static inline int wext_handle_ioctl(struct net *net, struct ifreq *ifr, unsigned int cmd,
17+
static inline int wext_handle_ioctl(struct net *net, struct iwreq *iwr, unsigned int cmd,
1818
void __user *arg)
1919
{
2020
return -EINVAL;

net/core/dev_ioctl.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,22 @@ int dev_ioctl(struct net *net, unsigned int cmd, void __user *arg)
410410
if (cmd == SIOCGIFNAME)
411411
return dev_ifname(net, (struct ifreq __user *)arg);
412412

413+
/*
414+
* Take care of Wireless Extensions. Unfortunately struct iwreq
415+
* isn't a proper subset of struct ifreq (it's 8 byte shorter)
416+
* so we need to treat it specially, otherwise applications may
417+
* fault if the struct they're passing happens to land at the
418+
* end of a mapped page.
419+
*/
420+
if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) {
421+
struct iwreq iwr;
422+
423+
if (copy_from_user(&iwr, arg, sizeof(iwr)))
424+
return -EFAULT;
425+
426+
return wext_handle_ioctl(net, &iwr, cmd, arg);
427+
}
428+
413429
if (copy_from_user(&ifr, arg, sizeof(struct ifreq)))
414430
return -EFAULT;
415431

@@ -559,9 +575,6 @@ int dev_ioctl(struct net *net, unsigned int cmd, void __user *arg)
559575
ret = -EFAULT;
560576
return ret;
561577
}
562-
/* Take care of Wireless Extensions */
563-
if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST)
564-
return wext_handle_ioctl(net, &ifr, cmd, arg);
565578
return -ENOTTY;
566579
}
567580
}

net/wireless/wext-core.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -914,21 +914,20 @@ int call_commit_handler(struct net_device *dev)
914914
* Main IOCTl dispatcher.
915915
* Check the type of IOCTL and call the appropriate wrapper...
916916
*/
917-
static int wireless_process_ioctl(struct net *net, struct ifreq *ifr,
917+
static int wireless_process_ioctl(struct net *net, struct iwreq *iwr,
918918
unsigned int cmd,
919919
struct iw_request_info *info,
920920
wext_ioctl_func standard,
921921
wext_ioctl_func private)
922922
{
923-
struct iwreq *iwr = (struct iwreq *) ifr;
924923
struct net_device *dev;
925924
iw_handler handler;
926925

927926
/* Permissions are already checked in dev_ioctl() before calling us.
928927
* The copy_to/from_user() of ifr is also dealt with in there */
929928

930929
/* Make sure the device exist */
931-
if ((dev = __dev_get_by_name(net, ifr->ifr_name)) == NULL)
930+
if ((dev = __dev_get_by_name(net, iwr->ifr_name)) == NULL)
932931
return -ENODEV;
933932

934933
/* A bunch of special cases, then the generic case...
@@ -957,9 +956,6 @@ static int wireless_process_ioctl(struct net *net, struct ifreq *ifr,
957956
else if (private)
958957
return private(dev, iwr, cmd, info, handler);
959958
}
960-
/* Old driver API : call driver ioctl handler */
961-
if (dev->netdev_ops->ndo_do_ioctl)
962-
return dev->netdev_ops->ndo_do_ioctl(dev, ifr, cmd);
963959
return -EOPNOTSUPP;
964960
}
965961

@@ -977,7 +973,7 @@ static int wext_permission_check(unsigned int cmd)
977973
}
978974

979975
/* entry point from dev ioctl */
980-
static int wext_ioctl_dispatch(struct net *net, struct ifreq *ifr,
976+
static int wext_ioctl_dispatch(struct net *net, struct iwreq *iwr,
981977
unsigned int cmd, struct iw_request_info *info,
982978
wext_ioctl_func standard,
983979
wext_ioctl_func private)
@@ -987,9 +983,9 @@ static int wext_ioctl_dispatch(struct net *net, struct ifreq *ifr,
987983
if (ret)
988984
return ret;
989985

990-
dev_load(net, ifr->ifr_name);
986+
dev_load(net, iwr->ifr_name);
991987
rtnl_lock();
992-
ret = wireless_process_ioctl(net, ifr, cmd, info, standard, private);
988+
ret = wireless_process_ioctl(net, iwr, cmd, info, standard, private);
993989
rtnl_unlock();
994990

995991
return ret;
@@ -1039,18 +1035,18 @@ static int ioctl_standard_call(struct net_device * dev,
10391035
}
10401036

10411037

1042-
int wext_handle_ioctl(struct net *net, struct ifreq *ifr, unsigned int cmd,
1038+
int wext_handle_ioctl(struct net *net, struct iwreq *iwr, unsigned int cmd,
10431039
void __user *arg)
10441040
{
10451041
struct iw_request_info info = { .cmd = cmd, .flags = 0 };
10461042
int ret;
10471043

1048-
ret = wext_ioctl_dispatch(net, ifr, cmd, &info,
1044+
ret = wext_ioctl_dispatch(net, iwr, cmd, &info,
10491045
ioctl_standard_call,
10501046
ioctl_private_call);
10511047
if (ret >= 0 &&
10521048
IW_IS_GET(cmd) &&
1053-
copy_to_user(arg, ifr, sizeof(struct iwreq)))
1049+
copy_to_user(arg, iwr, sizeof(struct iwreq)))
10541050
return -EFAULT;
10551051

10561052
return ret;
@@ -1107,7 +1103,7 @@ int compat_wext_handle_ioctl(struct net *net, unsigned int cmd,
11071103
info.cmd = cmd;
11081104
info.flags = IW_REQUEST_FLAG_COMPAT;
11091105

1110-
ret = wext_ioctl_dispatch(net, (struct ifreq *) &iwr, cmd, &info,
1106+
ret = wext_ioctl_dispatch(net, &iwr, cmd, &info,
11111107
compat_standard_call,
11121108
compat_private_call);
11131109

0 commit comments

Comments
 (0)