From patchwork Tue Sep 7 19:58:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Carter X-Patchwork-Id: 12479275 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.8 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_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 DFB13C433F5 for ; Tue, 7 Sep 2021 19:58:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BACF661132 for ; Tue, 7 Sep 2021 19:58:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346125AbhIGT76 (ORCPT ); Tue, 7 Sep 2021 15:59:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346120AbhIGT75 (ORCPT ); Tue, 7 Sep 2021 15:59:57 -0400 Received: from mail-qt1-x82c.google.com (mail-qt1-x82c.google.com [IPv6:2607:f8b0:4864:20::82c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24DB7C061575 for ; Tue, 7 Sep 2021 12:58:51 -0700 (PDT) Received: by mail-qt1-x82c.google.com with SMTP id u4so454293qta.2 for ; Tue, 07 Sep 2021 12:58:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=f/8TFe6tAHzDHnDetSM2X0UNNumWSsyLm0/Xi77Z/zs=; b=lsR4kpWSWbSyzfvCOK+dt32Bxm7f5qNF6N16QpUbrrEdN/XgSxc5zVqlveWhnhgRbz zqbKt0yTc+apM0h8rfAk16wMUn8dFldxbtSbFCEaqQZUiNNtvOhTsmJvCs4NfRcPkk1a HnK24CZCIaRpUnidlfQmAQje93LvB5JLMgw9RQNMpPeLiqM3hqQ0MpxwOl6uFpdh7idc H7/bRbjVdeeYYzWQjaU0nwAwkB/I65WyLxuHCR5UkueanxTXuG1V+PbJa3zuz6DNMyrM al1ifJtE/+aYJrD8kcm6gxyycWlYllZTU3WMxjAtFKStwSFCNDrKFwne08+W3pMDqvyd Vs9w== 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:mime-version :content-transfer-encoding; bh=f/8TFe6tAHzDHnDetSM2X0UNNumWSsyLm0/Xi77Z/zs=; b=bpTS1nxJisoq8VsGNbETrKPb7uaNiD2uG52CxnryALKsqlSvmMBn2UHGd3Im6pHUXo jScGFqlV7inLS7/ATW9m0sU6In5AN4YONVd3WYZw6m5p30D5cdMUHJM3xRVrZJwO1s+R RoUscVmMZZZiT/QxIXEtudEuIWsX5EvgC0OWTTZKKtNCiXkyBIZU/fVCOYVvNehLWHfx qg24oum8LeNGeyhSZ1TGbnVYs/wflIh9zgYgctJFtWYTfvc+k2i6GuWHoTX2l8eAK5Nw LgjrnZWrpT2K98w0vOfv9gnNArBTLRLngJsAQyQj7U4WKZFREMCn9EoLfVzAbcuxJWwl IcjA== X-Gm-Message-State: AOAM530GBxsficaKD/P1DKcf5WA1IIGXs0KQ6U9++Yi4gEDqkMOmM3ml gflBvU9hg9cg8f6ih8ZPVTOA/Ynyueg= X-Google-Smtp-Source: ABdhPJxRTmj0HxKluaFFr2oga4WFL0VSrMEALLcQ5Ja2qm32lGG9gQ9ksq4XhdL6C/aAri++FODxCw== X-Received: by 2002:ac8:7194:: with SMTP id w20mr117854qto.217.1631044730227; Tue, 07 Sep 2021 12:58:50 -0700 (PDT) Received: from localhost.localdomain (c-73-200-157-122.hsd1.md.comcast.net. [73.200.157.122]) by smtp.gmail.com with ESMTPSA id s187sm38181qkf.34.2021.09.07.12.58.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 12:58:49 -0700 (PDT) From: James Carter To: selinux@vger.kernel.org Cc: nicolas.iooss@m4x.org, James Carter Subject: [PATCH 1/2] libsepol/cil: Add function to get number of items in a stack Date: Tue, 7 Sep 2021 15:58:44 -0400 Message-Id: <20210907195845.809083-1-jwcart2@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Add the function, cil_stack_number_of_items(), to return the number of items in the stack. Signed-off-by: James Carter --- libsepol/cil/src/cil_stack.c | 5 +++++ libsepol/cil/src/cil_stack.h | 1 + 2 files changed, 6 insertions(+) diff --git a/libsepol/cil/src/cil_stack.c b/libsepol/cil/src/cil_stack.c index bbfb961a..70a77bc1 100644 --- a/libsepol/cil/src/cil_stack.c +++ b/libsepol/cil/src/cil_stack.c @@ -67,6 +67,11 @@ int cil_stack_is_empty(struct cil_stack *stack) return (stack->pos == -1); } +int cil_stack_number_of_items(struct cil_stack *stack) +{ + return stack->pos + 1; +} + void cil_stack_push(struct cil_stack *stack, enum cil_flavor flavor, void *data) { stack->pos++; diff --git a/libsepol/cil/src/cil_stack.h b/libsepol/cil/src/cil_stack.h index b78535ac..0e3eff66 100644 --- a/libsepol/cil/src/cil_stack.h +++ b/libsepol/cil/src/cil_stack.h @@ -52,6 +52,7 @@ void cil_stack_destroy(struct cil_stack **stack); void cil_stack_empty(struct cil_stack *stack); int cil_stack_is_empty(struct cil_stack *stack); +int cil_stack_number_of_items(struct cil_stack *stack); void cil_stack_push(struct cil_stack *stack, enum cil_flavor flavor, void *data); struct cil_stack_item *cil_stack_pop(struct cil_stack *stack); From patchwork Tue Sep 7 19:58:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Carter X-Patchwork-Id: 12479277 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.8 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_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 631F6C433F5 for ; Tue, 7 Sep 2021 19:58:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 442AD6113E for ; Tue, 7 Sep 2021 19:58:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346120AbhIGT76 (ORCPT ); Tue, 7 Sep 2021 15:59:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346121AbhIGT76 (ORCPT ); Tue, 7 Sep 2021 15:59:58 -0400 Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0E26C061575 for ; Tue, 7 Sep 2021 12:58:51 -0700 (PDT) Received: by mail-qt1-x832.google.com with SMTP id r21so406037qtw.11 for ; Tue, 07 Sep 2021 12:58:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kikxJsiZECX+/20A5hB+AJMdToQzH555QISBkOb8U48=; b=IZCBKD/RecLHGyXYEOOOdJZ4+VxaiOCeNCHMMHdzhsj7f0XoLA2B9WedRlCzkT2Cur QGBUJ1DTxOAu5zQN2vRXIiwd2XrOZuqH37OsrJg5llN8ePNTx5/TJJ2LpRMjul5zxTqv WE/xbEnOWAbp6coM2OxXUGpNwrAcUU4romOvuUedUuvKX9ijYc/gNe2ypzUYByKX84dW Z1jJ10M8Uc9j4mP7p1srl6aakwrMUw90QSyl07GBZ3o+qxeJxdF93x5/GhRV9ZTdH0rV O8Kw4I794JyVuhPKpeQ/IxdFmbQfYZpWs2uRPK85wfHhUS3k5oAERB9tr4FfEtFOR5u2 3plw== 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=kikxJsiZECX+/20A5hB+AJMdToQzH555QISBkOb8U48=; b=MmlE6lZ/emuYEQrduKPnvLNkXYHSkSGf8FmEwHUlId6R5cYpAcIEo6vaSgB/fvAP4I VzTO5S6cFXGHy/HgYDpqoC/x2lm7zOM0lsGkfL8rS5+5ZbBgERyN9VjEgyLIlSD/y+IG cYvYTWpDUrHaXdT8kKeOj88kLEid1LPaT+DEqlBYzEId9RJixLgcQUakVheY+++epBZJ rRIyZ9frA3o5LxffaevuK1Av3ajVK7Q7S4rxPlLU/VEkPJzSHj4j757/f/+T70yxX396 AfZuAvPwvE6n2isatmqUxza/b3MjUlEraeOvk/eN94roFjujjNWCosInoaAj7igBKpJ8 Gl/Q== X-Gm-Message-State: AOAM533EKfYZOMsLDTdBc5VlC6O/P3sw7qzvrucqF+ZvcECGYWqUfufr DznGxkoiVkCBOPKVVqaDGAlQQw79A0w= X-Google-Smtp-Source: ABdhPJyZszkyWGqv9Iq1l0bLToj7nxkb1wKhC1tCZiDdQUwwULRpLKRUQS3WOV3/H+fCtBoF76HbiA== X-Received: by 2002:a05:622a:2c3:: with SMTP id a3mr129046qtx.41.1631044730758; Tue, 07 Sep 2021 12:58:50 -0700 (PDT) Received: from localhost.localdomain (c-73-200-157-122.hsd1.md.comcast.net. [73.200.157.122]) by smtp.gmail.com with ESMTPSA id s187sm38181qkf.34.2021.09.07.12.58.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 12:58:50 -0700 (PDT) From: James Carter To: selinux@vger.kernel.org Cc: nicolas.iooss@m4x.org, James Carter Subject: [PATCH 2/2] libsepol/cil: Limit the number of active line marks Date: Tue, 7 Sep 2021 15:58:45 -0400 Message-Id: <20210907195845.809083-2-jwcart2@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210907195845.809083-1-jwcart2@gmail.com> References: <20210907195845.809083-1-jwcart2@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org A line mark functions like an open parenthesis, so the number of active line marks should be limited like the number of open parenthesis. This issue was found by the secilc-fuzzer. Signed-off-by: James Carter Acked-by: Nicolas Iooss --- libsepol/cil/src/cil_parser.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libsepol/cil/src/cil_parser.c b/libsepol/cil/src/cil_parser.c index a967b9ed..5375d49a 100644 --- a/libsepol/cil/src/cil_parser.c +++ b/libsepol/cil/src/cil_parser.c @@ -131,6 +131,10 @@ static int add_hll_linemark(struct cil_tree_node **current, uint32_t *hll_offset *current = (*current)->parent; } else { push_hll_info(stack, *hll_offset, *hll_expand); + if (cil_stack_number_of_items(stack) > CIL_PARSER_MAX_EXPR_DEPTH) { + cil_log(CIL_ERR, "Number of active line marks exceeds limit of %d\n", CIL_PARSER_MAX_EXPR_DEPTH); + goto exit; + } create_node(&node, *current, tok.line, *hll_offset, NULL); insert_node(node, *current);