lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1584969039-74113-2-git-send-email-xiangxia.m.yue@gmail.com>
Date:   Mon, 23 Mar 2020 21:10:38 +0800
From:   xiangxia.m.yue@...il.com
To:     pshelar@....org
Cc:     netdev@...r.kernel.org, dev@...nvswitch.org,
        Tonghao Zhang <xiangxia.m.yue@...il.com>,
        Andy Zhou <azhou@....org>
Subject: [PATCH net-next v1 2/3] net: openvswitch: set max limitation to meters

From: Tonghao Zhang <xiangxia.m.yue@...il.com>

Don't allow user to create meter unlimitedly, which
may cause to consume a large amount of kernel memory.
The 200,000 meters may be fine in general case.

Cc: Pravin B Shelar <pshelar@....org>
Cc: Andy Zhou <azhou@....org>
Signed-off-by: Tonghao Zhang <xiangxia.m.yue@...il.com>
---
 net/openvswitch/meter.c | 14 +++++++++-----
 net/openvswitch/meter.h |  3 ++-
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/net/openvswitch/meter.c b/net/openvswitch/meter.c
index 98003b201b45..5efd48e024f0 100644
--- a/net/openvswitch/meter.c
+++ b/net/openvswitch/meter.c
@@ -256,7 +256,7 @@ static int ovs_meter_cmd_features(struct sk_buff *skb, struct genl_info *info)
 	if (IS_ERR(reply))
 		return PTR_ERR(reply);
 
-	if (nla_put_u32(reply, OVS_METER_ATTR_MAX_METERS, U32_MAX) ||
+	if (nla_put_u32(reply, OVS_METER_ATTR_MAX_METERS, DP_MAX_METERS) ||
 	    nla_put_u32(reply, OVS_METER_ATTR_MAX_BANDS, DP_MAX_BANDS))
 		goto nla_put_failure;
 
@@ -284,13 +284,17 @@ static int ovs_meter_cmd_features(struct sk_buff *skb, struct genl_info *info)
 
 static struct dp_meter *dp_meter_create(struct nlattr **a)
 {
+	u32 meter_id = nla_get_u32(a[OVS_METER_ATTR_ID]);
+	struct dp_meter_band *band;
+	struct dp_meter *meter;
 	struct nlattr *nla;
-	int rem;
 	u16 n_bands = 0;
-	struct dp_meter *meter;
-	struct dp_meter_band *band;
+	int rem;
 	int err;
 
+	if (meter_id > DP_MAX_METERS)
+		return ERR_PTR(-EFBIG);
+
 	/* Validate attributes, count the bands. */
 	if (!a[OVS_METER_ATTR_BANDS])
 		return ERR_PTR(-EINVAL);
@@ -304,7 +308,7 @@ static struct dp_meter *dp_meter_create(struct nlattr **a)
 	if (!meter)
 		return ERR_PTR(-ENOMEM);
 
-	meter->id = nla_get_u32(a[OVS_METER_ATTR_ID]);
+	meter->id = meter_id;
 	meter->used = div_u64(ktime_get_ns(), 1000 * 1000);
 	meter->kbps = a[OVS_METER_ATTR_KBPS] ? 1 : 0;
 	meter->keep_stats = !a[OVS_METER_ATTR_CLEAR];
diff --git a/net/openvswitch/meter.h b/net/openvswitch/meter.h
index bc84796d7d4d..9ff7a9200d0d 100644
--- a/net/openvswitch/meter.h
+++ b/net/openvswitch/meter.h
@@ -17,7 +17,8 @@
 #include "flow.h"
 struct datapath;
 
-#define DP_MAX_BANDS		1
+#define DP_MAX_METERS	(200000ULL)
+#define DP_MAX_BANDS	1
 
 struct dp_meter_band {
 	u32 type;
-- 
2.23.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ