From patchwork Wed Apr 15 14:39:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Odin Ugedal X-Patchwork-Id: 221161 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03662C2BA19 for ; Wed, 15 Apr 2020 14:41:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D5B4F20857 for ; Wed, 15 Apr 2020 14:41:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ugedal.com header.i=@ugedal.com header.b="GFyKxmqq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S370875AbgDOOll (ORCPT ); Wed, 15 Apr 2020 10:41:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S370803AbgDOOkU (ORCPT ); Wed, 15 Apr 2020 10:40:20 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 087CFC061A0C for ; Wed, 15 Apr 2020 07:40:20 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id y4so3932475ljn.7 for ; Wed, 15 Apr 2020 07:40:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ugedal.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PPPoOHuTP2XeQ/6TCikOSxG1v+BI76w53F3xk1k1YO0=; b=GFyKxmqqV+OizwXib8+LVNcmYURIdssoBzfuSEFg/gn6ini9DKnH/sGYbl8uOLPpHE sn0O/ag5ArrJ37q4vZzVMZ/YvkIKrghidjv6DfWGjAukKOJYGPdHuyWgOz/Y3KzFq1VO tDaq/cw9REMeUIfyM1du6SQhKLB3/a2j/6C3JJJzeMm7yf0Tby1Ka04X4ZvYF7NRpmbA vMXD9hYyCdBRNU8q97/HOAF2jE8YWzSDwg4MtaExSoZsisTlZy5lc7RrcDGBKgZ1uah2 k38i3zgD+wsDZG59HQQ9r4Bb8Z9nVw2/MZr8T3VT57ikPWO4taVFwmIp/DqsAG4COx+g CrPQ== 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=PPPoOHuTP2XeQ/6TCikOSxG1v+BI76w53F3xk1k1YO0=; b=r3VeUcR1QCMkikzvy9HNVWHcP2xRRewxS+TnBCa3r5MxfeIra5z22m+df8ljQog2zw O+gWW5l8Saxu1WgQxEzHAjuWaAaxOABhlAPMmMnkEPWy5Hpr5DVgPsZd1+PbPOOu4NbQ YrGT5gEEQMCILO3Q49zKBeIvxVITf59U2SaC30QvnQFIUIn6EJ6rzGlKbtNd+YCa38l1 7ianyxstSMcdFRHAMMxYDyjp8W2P5R/F3aLmPpE97FZguAIqL4JChrKggXlI0D1EkDuB MmhQcbJy3JZN2qpcOckSzzwKhT5jyyvbC2SYiGjBAZ2RrFCa9tu227RqY/HEPrhed9zS bjHA== X-Gm-Message-State: AGi0PuZggCGDZJ8o6LjTGSXRrT81xlHM5Qcuj558k8UwlnKqZe9HNkSv mlDWX54UuCNtnHf3nVX7Egagew== X-Google-Smtp-Source: APiQypK5JP3Ht4iPrHWBECEz1DxlANp525yqoEF4q1TuVErvPYZjMzV3uOUIzfru4ptp71xCIU5Psg== X-Received: by 2002:a2e:854e:: with SMTP id u14mr3456476ljj.95.1586961618493; Wed, 15 Apr 2020 07:40:18 -0700 (PDT) Received: from xps13.home ([2001:4649:7d40:0:4415:c24b:59d6:7e4a]) by smtp.gmail.com with ESMTPSA id l22sm1860327lja.74.2020.04.15.07.40.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 07:40:17 -0700 (PDT) From: Odin Ugedal To: toke@redhat.com, netdev@vger.kernel.org Cc: Odin Ugedal Subject: [PATCH 1/3] q_cake: Make fwmark uint instead of int Date: Wed, 15 Apr 2020 16:39:34 +0200 Message-Id: <20200415143936.18924-2-odin@ugedal.com> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200415143936.18924-1-odin@ugedal.com> References: <20200415143936.18924-1-odin@ugedal.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This will help avoid overflow, since setting it to 0xffffffff would result in -1 when converted to integer, resulting in being "-1", setting the fwmark to 0x00. Signed-off-by: Odin Ugedal --- tc/q_cake.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tc/q_cake.c b/tc/q_cake.c index 3c78b176..9ebb270c 100644 --- a/tc/q_cake.c +++ b/tc/q_cake.c @@ -97,6 +97,7 @@ static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv, unsigned int interval = 0; unsigned int diffserv = 0; unsigned int memlimit = 0; + unsigned int fwmark = 0; unsigned int target = 0; __u64 bandwidth = 0; int ack_filter = -1; @@ -107,7 +108,6 @@ static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv, int autorate = -1; int ingress = -1; int overhead = 0; - int fwmark = -1; int wash = -1; int nat = -1; int atm = -1; @@ -335,15 +335,12 @@ static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv, return -1; } } else if (strcmp(*argv, "fwmark") == 0) { - unsigned int fwm; - NEXT_ARG(); - if (get_u32(&fwm, *argv, 0)) { + if (get_u32(&fwmark, *argv, 0)) { fprintf(stderr, "Illegal value for \"fwmark\": \"%s\"\n", *argv); return -1; } - fwmark = fwm; } else if (strcmp(*argv, "help") == 0) { explain(); return -1; @@ -388,7 +385,7 @@ static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv, if (memlimit) addattr_l(n, 1024, TCA_CAKE_MEMORY, &memlimit, sizeof(memlimit)); - if (fwmark != -1) + if (fwmark) addattr_l(n, 1024, TCA_CAKE_FWMARK, &fwmark, sizeof(fwmark)); if (nat != -1) From patchwork Wed Apr 15 14:39:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Odin Ugedal X-Patchwork-Id: 221162 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 741F5C2BA19 for ; Wed, 15 Apr 2020 14:41:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4BF5920857 for ; Wed, 15 Apr 2020 14:41:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ugedal.com header.i=@ugedal.com header.b="pruLdR10" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S370832AbgDOOkg (ORCPT ); Wed, 15 Apr 2020 10:40:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S370818AbgDOOkW (ORCPT ); Wed, 15 Apr 2020 10:40:22 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17BB2C061A0E for ; Wed, 15 Apr 2020 07:40:22 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id h25so3917820lja.10 for ; Wed, 15 Apr 2020 07:40:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ugedal.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RO6kouuowzfuF2lpmzEcqaiqY+vQEzweKZj87S/u2/E=; b=pruLdR10uQo3JVc2Zd3eB+VtKMoCOlq05rp1pGDn/ssEXOd9r/0xyJtgt6+PuycT9Z BRdiBieS52BmvkbGf0AvOZlINn90Rm6ScNqax8jnGfjMF73rqzTTERCsuuAyaT9ulNSa V1kg++IhArmJc7pxi8RRNXDZSVKW0QwkPyKe7tQ8Vc/6JWDAbg8F1rvulwmy8I2I6Ai5 UMHGjSI/hSpA0huIZHk+5ng81hMiTw7wRt9EkupTSR7IR7PSK+ji4c3wyDHU3AHqvhN6 aLfyKexyeaaqHAQrpqQRJihl/aP2GdSEMlNAxhlJx5e77kt13D10ZN7xgkcFSDqyW72C ZufQ== 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=RO6kouuowzfuF2lpmzEcqaiqY+vQEzweKZj87S/u2/E=; b=jWBJV86I6Y10qVBtWTtk2/SUOuKZx9wht/lO7N2Ak5aCHODFW2SVZS3avWGhvARK1e lfd54rxf82aJsRsQja3cIT7j0kBN4/JwqGi5jtujftK1wMIEP8XPxEPSxdys+JnEN/2C NUGHHvHEx9JDnZviLkBa08XkFl6bmSS1R1cRpFNBOPfdj9BzbrUtUOVtkm8i9tW+JvKr GAC+xIkhHD54dcpvezh6gR3YHvfDRu+H0emR3inTmFQ5fjmqmPHpDTUe2N/M3rxtKhzY FlIa8jnAMPKP8iX/ngzbQ096aVagl0CbQk4ZUV1ape3wHs2PErP7eIn5tAGWID7WTrcd Vxjw== X-Gm-Message-State: AGi0Pua/6sMRv+ldyACtSjhxrCR0RkU9M32WhMK1pW0LdkOchC0TtFnN KB+z6yivkD2cSXkEzFv3R9iKFg== X-Google-Smtp-Source: APiQypI/uOQdNB7OoXoRtSE4LH8L4k2+cECEjdk7Gsye8NA4hOt1lFwZQAV/8AugbkSe7n4CXOo6Zw== X-Received: by 2002:a2e:93d7:: with SMTP id p23mr3612568ljh.9.1586961620548; Wed, 15 Apr 2020 07:40:20 -0700 (PDT) Received: from xps13.home ([2001:4649:7d40:0:4415:c24b:59d6:7e4a]) by smtp.gmail.com with ESMTPSA id l22sm1860327lja.74.2020.04.15.07.40.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 07:40:20 -0700 (PDT) From: Odin Ugedal To: toke@redhat.com, netdev@vger.kernel.org Cc: Odin Ugedal Subject: [PATCH 2/3] q_cake: properly print memlimit Date: Wed, 15 Apr 2020 16:39:35 +0200 Message-Id: <20200415143936.18924-3-odin@ugedal.com> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200415143936.18924-1-odin@ugedal.com> References: <20200415143936.18924-1-odin@ugedal.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Load memlimit so that it will be printed if it isn't set to zero. Also add a space to properly print it. Signed-off-by: Odin Ugedal --- tc/q_cake.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tc/q_cake.c b/tc/q_cake.c index 9ebb270c..12d648d7 100644 --- a/tc/q_cake.c +++ b/tc/q_cake.c @@ -520,6 +520,10 @@ static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) RTA_PAYLOAD(tb[TCA_CAKE_RTT]) >= sizeof(__u32)) { interval = rta_getattr_u32(tb[TCA_CAKE_RTT]); } + if (tb[TCA_CAKE_MEMORY] && + RTA_PAYLOAD(tb[TCA_CAKE_MEMORY]) >= sizeof(__u32)) { + memlimit = rta_getattr_u32(tb[TCA_CAKE_MEMORY]); + } if (tb[TCA_CAKE_FWMARK] && RTA_PAYLOAD(tb[TCA_CAKE_FWMARK]) >= sizeof(__u32)) { fwmark = rta_getattr_u32(tb[TCA_CAKE_FWMARK]); @@ -572,7 +576,7 @@ static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) if (memlimit) { print_uint(PRINT_JSON, "memlimit", NULL, memlimit); - print_string(PRINT_FP, NULL, "memlimit %s", + print_string(PRINT_FP, NULL, "memlimit %s ", sprint_size(memlimit, b1)); } From patchwork Thu Apr 16 14:08:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Odin Ugedal X-Patchwork-Id: 221123 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AADF9C2BB55 for ; Thu, 16 Apr 2020 14:37:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C00B21927 for ; Thu, 16 Apr 2020 14:37:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ugedal.com header.i=@ugedal.com header.b="bZmFjNrT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731262AbgDPOhz (ORCPT ); Thu, 16 Apr 2020 10:37:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1732826AbgDPOIb (ORCPT ); Thu, 16 Apr 2020 10:08:31 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2623C061A0C for ; Thu, 16 Apr 2020 07:08:30 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id j3so7503933ljg.8 for ; Thu, 16 Apr 2020 07:08:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ugedal.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=G5ggDZ1v3A6kQc3OJTARyj3Ghh9ae4R1QQxarRtXKZQ=; b=bZmFjNrT2PhYv0+GlJPOFRCUdoklRITtflU0d2ClsY/L119cmZ6oCS6JGB669NtYG5 oWJl+Z3Qr57IBKjZeYIZOvUnd+tOLz1Gz9rssrfBvbuPQzLKnCi11U2VYEtO/eB4GTmk 2yM2sasTR6ygWvgDEn++hO6ccxlzFhL+sccyiU6OzmKmKN5RfZfxJkLdgVHSXTeEWtxW sRLdSNmyoM2pmg2IZmw6fM1JgIC4cPysfEFSpWjxOcS53PMT3fP6RsR7YFFo+8Qhe5mW 0r0JvBOHCdFOGRhXFM502j140YYh00C8AKLXP1qZ3uuAmQvAdquqHNVHOzjutcSCnWR7 FcYw== 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=G5ggDZ1v3A6kQc3OJTARyj3Ghh9ae4R1QQxarRtXKZQ=; b=hjZZlQ45M0y+c4AXLQDNN4U/HfiiK4vMyI3CxXPsApm+kKYPiD4hdqOoYuMIo19alk 6HWC3H+CaOm5QyKEoEYdv4n4Fx26uoMGq40tWQ/aCd+Y1dnR1pUQYEJRK9QPCIWVRnPG UYUX7tyXutLbzZYcy7sE9toEJSzYrraSplU/quaA6YfHVA68XFBDLdRAtyqTO8Ygc0ZZ Cc/uqVQRcxfHgkqf9dFNjt1fdj6mDmNItCsSTGrlfMaQjddgWcSEm8XSo2r72TgXCn3x BKkX3g+TRXQP0N3XgmZvz66h/hJKdEi0ayZgKxM+E+THGakUKsRx38TQe9TIYfllZL3z /nkg== X-Gm-Message-State: AGi0PuaV/XQwz0s5MFuk5ofEEwpKNJjofeb0PG+oe5qoIQN66AaEmDfR QvG/xm6l13qqW9GfVbJP+B2Gd3/i/T5aCJFx X-Google-Smtp-Source: APiQypKd2NSnBObWH0beElbeH7n9hUrQlvVPCw1QPrHOeNrV9J0Ms1UiMMr1iOH0pS1hnHJKk2F3Kw== X-Received: by 2002:a2e:9ac9:: with SMTP id p9mr6590141ljj.222.1587046109122; Thu, 16 Apr 2020 07:08:29 -0700 (PDT) Received: from xps13.home ([2001:4649:7d40:0:4415:c24b:59d6:7e4a]) by smtp.gmail.com with ESMTPSA id i20sm16137868lfe.15.2020.04.16.07.08.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Apr 2020 07:08:28 -0700 (PDT) From: Odin Ugedal To: odin@ugedal.com Cc: netdev@vger.kernel.org, toke@redhat.com Subject: [PATCH v2 3/3] tc_util: detect overflow in get_size Date: Thu, 16 Apr 2020 16:08:14 +0200 Message-Id: <20200416140814.171242-1-odin@ugedal.com> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200415143936.18924-1-odin@ugedal.com> References: <20200415143936.18924-1-odin@ugedal.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This detects overflow during parsing of value using get_size: eg. running: $ tc qdisc add dev lo root cake memlimit 11gb currently gives a memlimit of "3072Mb", while with this patch it errors with 'illegal value for "memlimit": "11gb"', since memlinit is an unsigned integer. Signed-off-by: Odin Ugedal Acked-by: Toke Høiland-Jørgensen --- tc/tc_util.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tc/tc_util.c b/tc/tc_util.c index 5f13d729..68938fb0 100644 --- a/tc/tc_util.c +++ b/tc/tc_util.c @@ -385,6 +385,11 @@ int get_size(unsigned int *size, const char *str) } *size = sz; + + /* detect if an overflow happened */ + if (*size != floor(sz)) + return -1; + return 0; }