Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

wext: Pull ioctl permission checking out into helper function.

Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

David S. Miller and committed by
David S. Miller
67dd7608 d88174e4

+15 -7
+15 -7
net/wireless/wext.c
··· 1061 1061 return -EOPNOTSUPP; 1062 1062 } 1063 1063 1064 + /* If command is `set a parameter', or `get the encoding parameters', 1065 + * check if the user has the right to do it. 1066 + */ 1067 + static int wext_permission_check(unsigned int cmd) 1068 + { 1069 + if ((IW_IS_SET(cmd) || cmd == SIOCGIWENCODE || cmd == SIOCGIWENCODEEXT) 1070 + && !capable(CAP_NET_ADMIN)) 1071 + return -EPERM; 1072 + 1073 + return 0; 1074 + } 1075 + 1064 1076 /* entry point from dev ioctl */ 1065 1077 int wext_handle_ioctl(struct net *net, struct ifreq *ifr, unsigned int cmd, 1066 1078 void __user *arg) 1067 1079 { 1068 - int ret; 1080 + int ret = wext_permission_check(cmd); 1069 1081 1070 - /* If command is `set a parameter', or 1071 - * `get the encoding parameters', check if 1072 - * the user has the right to do it */ 1073 - if ((IW_IS_SET(cmd) || cmd == SIOCGIWENCODE || cmd == SIOCGIWENCODEEXT) 1074 - && !capable(CAP_NET_ADMIN)) 1075 - return -EPERM; 1082 + if (ret) 1083 + return ret; 1076 1084 1077 1085 dev_load(net, ifr->ifr_name); 1078 1086 rtnl_lock();