From patchwork Mon Mar 23 13:10:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 1263256 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=f2asgbEI; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48qNPg1fjPz9sSQ for ; Sun, 29 Mar 2020 02:46:46 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 8AB1C877E0; Sat, 28 Mar 2020 15:46:44 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nxY7iBtsbtcE; Sat, 28 Mar 2020 15:46:39 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 6B89A87BC0; Sat, 28 Mar 2020 15:46:39 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5BD12C1D87; Sat, 28 Mar 2020 15:46:39 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1A5FBC0177 for ; Sat, 28 Mar 2020 15:46:37 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 0ABB38826F for ; Sat, 28 Mar 2020 15:46:37 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4dIjnNgCsbnW for ; Sat, 28 Mar 2020 15:46:35 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pj1-f67.google.com (mail-pj1-f67.google.com [209.85.216.67]) by hemlock.osuosl.org (Postfix) with ESMTPS id E7D3F84F80 for ; Sat, 28 Mar 2020 15:46:35 +0000 (UTC) Received: by mail-pj1-f67.google.com with SMTP id np9so5236859pjb.4 for ; Sat, 28 Mar 2020 08:46:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7T0gpUg1KYguFzYbM6Ar8rC1c+eZds8dxyLFu0Xgo10=; b=f2asgbEI6ieB4Ellt7Dy+LgThprY4DwL6LP2pb1mHFUt/fhb1amGL5S1VHCf9IDkVY yDnTd0JDJcLG7InQoZcEysqBVWBbiHtb4BjYOzSk6z61B5GDJms6wurNd5/Cu86YTyTp R2nH70bBQUVyXAHkgBGI3s4BChjOTmn9IGL/59MYYI0ucy/qHpKGxx2l+eqqSSq81ZsJ MPjYobP5g2NNBZ8AvryADDiwV+q/XwbZZwG96hR3oIX1digTh8ABSep4AceewWNoO+0h WceB+ECejsuulKK2mQxvPPnVliGFAs3xUjzv6i0sSeQtfFBp6vKpuGVp/fD28NXeofq1 /nYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7T0gpUg1KYguFzYbM6Ar8rC1c+eZds8dxyLFu0Xgo10=; b=YBPuRnLx3KGkt6woKNJ9sU4q2Viao259mqnrxQ7hzHHNce/mB6YxuhOHYLVehffGDY A+fFPUyp+AcBhVjZKsZ0fd4JiyCOYKSjM7T79VvD/liyfq7hMtcx2cf+NVuTjZsTI9vr wftYMppUaKuNea1hc3wfGTREiePfIb4IrBVMqF9KNGa5Jy3p18EeiiODbbg5+PoYIg2a 7n8nE5992Ck0zF6EUbJOYHKI6eDOH5cqau0nh1MmNr6qcNyGfGD/Ok4tzSypqA1f5Cw2 p41mH63HKoevMIIi/QHaOc6j59DdVBLfeyyme5gZHHxJIsW2NSP2L/fC151hKb0eh+fP RGiw== X-Gm-Message-State: ANhLgQ03Vp250jJo5ObslH+PJlFafSK+DkbBBHHRAHO6by8+yXF56Msk 6soCFzXW2/btbX2IgWNUh5c= X-Google-Smtp-Source: ADFU+vuXMBfgXsUSdwm9V8vkQDauHQHz2qMbbvGESUoHFAu2q7sZwPho4nmk6FJhUfBHgMWuMwfhmA== X-Received: by 2002:a17:90a:1784:: with SMTP id q4mr5387627pja.174.1585410395479; Sat, 28 Mar 2020 08:46:35 -0700 (PDT) Received: from local.opencloud.tech.localdomain ([115.171.63.184]) by smtp.gmail.com with ESMTPSA id q185sm6375218pfb.154.2020.03.28.08.46.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Mar 2020 08:46:35 -0700 (PDT) From: xiangxia.m.yue@gmail.com To: pshelar@ovn.org Date: Mon, 23 Mar 2020 21:10:38 +0800 Message-Id: <1584969039-74113-2-git-send-email-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1584969039-74113-1-git-send-email-xiangxia.m.yue@gmail.com> References: <1584969039-74113-1-git-send-email-xiangxia.m.yue@gmail.com> MIME-Version: 1.0 Cc: dev@openvswitch.org, netdev@vger.kernel.org Subject: [ovs-dev] [PATCH net-next v1 2/3] net: openvswitch: set max limitation to meters X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Tonghao Zhang 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 Cc: Andy Zhou Signed-off-by: Tonghao Zhang --- 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;