OSDN Git Service

Merge 4.4.168 into android-4.4
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / drivers / net / tun.c
index 63778be..6032ec8 100644 (file)
@@ -1192,11 +1192,13 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
        switch (tun->flags & TUN_TYPE_MASK) {
        case IFF_TUN:
                if (tun->flags & IFF_NO_PI) {
-                       switch (skb->data[0] & 0xf0) {
-                       case 0x40:
+                       u8 ip_version = skb->len ? (skb->data[0] >> 4) : 0;
+
+                       switch (ip_version) {
+                       case 4:
                                pi.proto = htons(ETH_P_IP);
                                break;
-                       case 0x60:
+                       case 6:
                                pi.proto = htons(ETH_P_IPV6);
                                break;
                        default:
@@ -1470,7 +1472,9 @@ static void tun_setup(struct net_device *dev)
  */
 static int tun_validate(struct nlattr *tb[], struct nlattr *data[])
 {
-       return -EINVAL;
+       /* NL_SET_ERR_MSG(extack,
+                      "tun/tap creation via rtnetlink is not supported."); */
+       return -EOPNOTSUPP;
 }
 
 static struct rtnl_link_ops tun_link_ops __read_mostly = {
@@ -1679,6 +1683,9 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
 
                if (!dev)
                        return -ENOMEM;
+               err = dev_get_valid_name(net, dev, name);
+               if (err < 0)
+                       goto err_free_dev;
 
                dev_net_set(dev, net);
                dev->rtnl_link_ops = &tun_link_ops;
@@ -2066,6 +2073,10 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
                        ret = -EFAULT;
                        break;
                }
+               if (sndbuf <= 0) {
+                       ret = -EINVAL;
+                       break;
+               }
 
                tun->sndbuf = sndbuf;
                tun_set_sndbuf(tun);