ethtool: Fix potential kernel buffer overflow in ETHTOOL_GRXCLSRLALL
[firefly-linux-kernel-4.4.55.git] / net / core / ethtool.c
index 4c12ddb5f5ee43ab546278ba5527c2e10939824b..2c21f7aef9a2b50a0346c3e30b270af7b0105f26 100644 (file)
@@ -244,8 +244,9 @@ static int ethtool_get_rxnfc(struct net_device *dev, void __user *useraddr)
 
        if (info.cmd == ETHTOOL_GRXCLSRLALL) {
                if (info.rule_cnt > 0) {
-                       rule_buf = kmalloc(info.rule_cnt * sizeof(u32),
-                                          GFP_USER);
+                       if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
+                               rule_buf = kmalloc(info.rule_cnt * sizeof(u32),
+                                                  GFP_USER);
                        if (!rule_buf)
                                return -ENOMEM;
                }