From mboxrd@z Thu Jan 1 00:00:00 1970 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_NONE,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 692EBC11F69 for ; Thu, 1 Jul 2021 06:19:09 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E23B061424 for ; Thu, 1 Jul 2021 06:19:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E23B061424 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4C36683298; Thu, 1 Jul 2021 08:17:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Uz5Atiev"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0F0D383251; Thu, 1 Jul 2021 08:16:51 +0200 (CEST) Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id EC40F83258 for ; Thu, 1 Jul 2021 08:16:27 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qv1-xf29.google.com with SMTP id fi7so1887453qvb.0 for ; Wed, 30 Jun 2021 23:16:27 -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=gaRO/GDk7N8Ri1FUGJ4kNQQOJ1Hu3IDUd4HjCJ0LS2g=; b=Uz5Atiev5jbRDSk1JsJof8iEHEaZxGUNy/KkkI1yofTOpUHYUAWR6gMJqwdX6Hz50V GMq0OEBEaEzi2ILdQURWAjw33z8ZoFw2vvUdfwIB0AUJzLB1+8SSR5HbBLOOg9pM34b+ 2RZQJEcUgE/OxoRBO8paIixFaLL8faqsrQKticA7dGGCQrQNV1QNuypZnHrniF0hI/S9 QSYI42pv8F0wWTg/ElpiVta80rpg9JQTEdEHbLkgpgBgMHidhFgTiMs36K5a0dvZiy6q iE1g3RSn6wW75vt7CHQZaLjb8hyVYqgqG4U9vINh3ONZnpwJMDAULUxw+ELFluzpTBW6 6lXg== 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=gaRO/GDk7N8Ri1FUGJ4kNQQOJ1Hu3IDUd4HjCJ0LS2g=; b=Jk38bTKUnz3lCJRKyr1FIS+rltJMjOghuEsWngCgKMLoGlo7n2DAazSUEFLbyknCOZ SRSiIkMBf6zyeRWOt8KiPvKyCXNbJF+y6buaZrvqVK8LD2bsWyBBMakHkpL3OdWUfmFs 747A/YfuSAVYQeavqO1GZW97jzMzSv2juODq+MqZl82+4qdjfdRfwqhZiXkUJaHTqt6R 7QKSY/oyFTTZFcDNgLhW8AUNyAlRiIKcn3k19JAjSV/GgAtVZLpvzlPDW0FI8SHnoSHG 1rWEvVuIpsvltlcfHkqGqQGESxs77wnNjsJhcNXHK0QkOQcfzCwPzm1UIiGsA1XtzhgU KWkg== X-Gm-Message-State: AOAM532AqL5MpYkSR2sKYaP+ik+5TA7vovii25Np+oxhfui3p4zEbBHX fgwgM5veLNO1Tr16EcLGtIfdJyisvdU= X-Google-Smtp-Source: ABdhPJz57/JZAD3pL5eLn2Xoz2HIsH2UWQMcdJmsvYzus1l4egB0aPFtBxkXtShWvCHApHZYVbiSzQ== X-Received: by 2002:a05:6214:17d2:: with SMTP id cu18mr41051914qvb.48.1625120186623; Wed, 30 Jun 2021 23:16:26 -0700 (PDT) Received: from godwin.fios-router.home (pool-74-96-87-9.washdc.fios.verizon.net. [74.96.87.9]) by smtp.gmail.com with ESMTPSA id g21sm1684673qts.90.2021.06.30.23.16.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 23:16:26 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de, Tom Rini Cc: =?UTF-8?q?Marek=20Beh=C3=BAn?= , Wolfgang Denk , Simon Glass , Roland Gaudig , Heinrich Schuchardt , Kostas Michalopoulos , Sean Anderson Subject: [RFC PATCH 16/28] cli: lil: Convert LIL_ENABLE_RECLIMIT to KConfig Date: Thu, 1 Jul 2021 02:15:59 -0400 Message-Id: <20210701061611.957918-17-seanga2@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210701061611.957918-1-seanga2@gmail.com> References: <20210701061611.957918-1-seanga2@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean This adds a configuration option to set the recursion limit. I've set it to a (conservative) 1000 by default. In addition, there is an option to turn it off for a very minor space savings and performance increase. Signed-off-by: Sean Anderson --- Do we need this? Perhaps it should default to 0. cmd/Kconfig | 8 ++++++++ common/cli_lil.c | 10 ++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cmd/Kconfig b/cmd/Kconfig index 28a387b380..7c8962cfc2 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -53,6 +53,14 @@ config LIL_POOLS use more memory but will cause considerably less memory fragmentation and improve the script execution performance. +config LIL_RECLIMIT + int "LIL function recursion limit" + default 1000 + help + Enable limiting recursive calls to lil_parse - this can be used to + avoid call stack overflows and is also useful when running through an + automated fuzzer like AFL. Set to 0 to disable the recursion limit. + endif endif diff --git a/common/cli_lil.c b/common/cli_lil.c index 750a085f63..6c05531441 100644 --- a/common/cli_lil.c +++ b/common/cli_lil.c @@ -17,10 +17,6 @@ #include #include -/* Enable limiting recursive calls to lil_parse - this can be used to avoid call stack - * overflows and is also useful when running through an automated fuzzer like AFL */ -/*#define LIL_ENABLE_RECLIMIT 10000*/ - #define HASHMAP_CELLS 256 #define HASHMAP_CELLMASK 0xFF @@ -1198,12 +1194,10 @@ struct lil_value *lil_parse(struct lil *lil, const char *code, size_t codelen, lil_skip_spaces(lil); lil->parse_depth++; -#ifdef LIL_ENABLE_RECLIMIT - if (lil->parse_depth > LIL_ENABLE_RECLIMIT) { - lil_set_error(lil, LIL_ERR_DEPTH, "Too many recursive calls"); + if (CONFIG_LIL_RECLIMIT && lil->parse_depth > CONFIG_LIL_RECLIMIT) { + lil_set_error(lil, LIL_ERR_DEPTH, "recursion limit reached"); goto cleanup; } -#endif if (lil->parse_depth == 1) lil->err = LIL_ERR_NONE; -- 2.32.0