From patchwork Tue Aug 10 18:05:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Carter X-Patchwork-Id: 12429323 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 8A762C4320E for ; Tue, 10 Aug 2021 18:21:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6B2A46056C for ; Tue, 10 Aug 2021 18:21:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235011AbhHJSWI (ORCPT ); Tue, 10 Aug 2021 14:22:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237212AbhHJSWB (ORCPT ); Tue, 10 Aug 2021 14:22:01 -0400 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F7EBC07AF5A for ; Tue, 10 Aug 2021 11:05:44 -0700 (PDT) Received: by mail-qk1-x730.google.com with SMTP id f23so7080840qkk.13 for ; Tue, 10 Aug 2021 11:05:44 -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=xpxPrrTiM5SRC2n12ZPGSGD0+g4rIv6oPky8lykdC70=; b=ixuwpJ9HSKbT2gv7k1GoBT2mIPjXUa9RxHYCWWMLPkfMwZI2TvZ3o1oLynGRSRDkMc UCAv1/cpe+KTgk/uSeKqTq9PEep5/KHtU9tWEVgG2vUhJfo4+SYVvnji1boFuG8SDQSy p2uC4/s341LndvF9vG/jyLNNxR8dfFoBiMKNv1agK3WLQVIbfnfJHs/pqgEZ2dubAcGE b0jTT+QYhRNjO2zcmW/EauEWqW+ON+hsgw8Em7ztzR7XzLdsgyHBNF5uJlMbB41hTiTO ngIUK+fYZMPWAZPuiXTiJFWrHdDbIUU/i3etDTKebo9f5yY/a3VVKG4kVGNN8aPc25/9 lWAA== 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=xpxPrrTiM5SRC2n12ZPGSGD0+g4rIv6oPky8lykdC70=; b=HOB1RGNf0KnALDJmklGQQn3LYeaFssraHhfhsQTLYqLNcSqhHWMbS5GjfTC6C9ihu8 y2/43aym/NFLxiudRZbd9Nga9NqjBSnwuGtT4NIfNcSfmK26QnBcsnvFPfVkc2xnzAt+ ptTeP0PyfNGViKTVd8RUmtFJg0/Km83tYhrNVwkC8U+SD7bEQtxaqikcWpl34jG1VEGs yHb20phOR5084YBshfIeWnGsInUDAKo67hNOZivYKnmhdxcUO1Zf17wAIwMZbWPDo3ED oDzHVRMxshNFLFhweKOpC9VZhfg3Ka/HIDXFwz2H5gjXnidrD6KjEuJbmXPEsWSX5igF DT8A== X-Gm-Message-State: AOAM532o1vtdGpaz82BnnqAj+AZtAjh6efzrv+KIi26POv8YvSg2AyV4 6JpZbtTZQ/jnJNCOAPLO3kjfHLWaFWb3Jg== X-Google-Smtp-Source: ABdhPJwhFO0xDkUjFC1Xwq9kNptgUPiVYwY2XEy86ZeKrFkQBnrt1qBjm+mOFDBynk+wgzuu64ZUMA== X-Received: by 2002:a37:43ca:: with SMTP id q193mr29989388qka.459.1628618743421; Tue, 10 Aug 2021 11:05:43 -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 m16sm3057415qki.19.2021.08.10.11.05.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Aug 2021 11:05:43 -0700 (PDT) From: James Carter To: selinux@vger.kernel.org Cc: James Carter Subject: [PATCH 1/8] libsepol/cil: Check syntax of src_info statement Date: Tue, 10 Aug 2021 14:05:30 -0400 Message-Id: <20210810180537.669439-2-jwcart2@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210810180537.669439-1-jwcart2@gmail.com> References: <20210810180537.669439-1-jwcart2@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Every rule other than src_info has their syntax checked when building the AST. It wasn't considered necessary for src_info rules because they were expected to always be generated by the parser and aren't part of the CIL language. But there is no check preventing them from occurring in a policy and the secilc fuzzer found some bugs by using src_info rules in a policy. This caused some syntax checking to be added. Since the parse AST from secil2tree will contain src_info rules and since the goal is to be able to compile the output of secil2tree, it makes sense to check the syntax of src_info rules in the same way that all of the other rules are checked. Check the syntax of src_info statements in the same way every other rule is checked. Signed-off-by: James Carter --- libsepol/cil/src/cil_build_ast.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/libsepol/cil/src/cil_build_ast.c b/libsepol/cil/src/cil_build_ast.c index 9da90883..5e65a266 100644 --- a/libsepol/cil/src/cil_build_ast.c +++ b/libsepol/cil/src/cil_build_ast.c @@ -6075,12 +6075,24 @@ void cil_destroy_mls(struct cil_mls *mls) int cil_gen_src_info(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node) { - /* No need to check syntax, because this is auto generated */ + int rc = SEPOL_ERR; + enum cil_syntax syntax[] = { + CIL_SYN_STRING, + CIL_SYN_STRING, + CIL_SYN_STRING, + CIL_SYN_N_LISTS | CIL_SYN_END, + CIL_SYN_END + }; + int syntax_len = sizeof(syntax)/sizeof(*syntax); struct cil_src_info *info = NULL; - if (parse_current->next == NULL || parse_current->next->next == NULL) { - cil_tree_log(parse_current, CIL_ERR, "Bad "); - return SEPOL_ERR; + if (parse_current == NULL || ast_node == NULL) { + goto exit; + } + + rc = __cil_verify_syntax(parse_current, syntax, syntax_len); + if (rc != SEPOL_OK) { + goto exit; } cil_src_info_init(&info); @@ -6092,6 +6104,10 @@ int cil_gen_src_info(struct cil_tree_node *parse_current, struct cil_tree_node * ast_node->flavor = CIL_SRC_INFO; return SEPOL_OK; + +exit: + cil_tree_log(parse_current, CIL_ERR, "Bad src info"); + return rc; } void cil_destroy_src_info(struct cil_src_info *info)