From patchwork Fri Feb 11 18:46:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Carter X-Patchwork-Id: 12743758 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E903BC433F5 for ; Fri, 11 Feb 2022 18:47:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231239AbiBKSrE (ORCPT ); Fri, 11 Feb 2022 13:47:04 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232268AbiBKSrE (ORCPT ); Fri, 11 Feb 2022 13:47:04 -0500 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC7CF337 for ; Fri, 11 Feb 2022 10:47:02 -0800 (PST) Received: by mail-qk1-x735.google.com with SMTP id o10so9093896qkg.0 for ; Fri, 11 Feb 2022 10:47:02 -0800 (PST) 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=NQ9dLE4qRCZ8PE+mGm5akTvNPqhS4+bDbb1b5kZNXMQ=; b=oCQfmzNaSko79hHOsIlsRz38dWe9Q8UFHZoAacwx7w9FwRMq0/N7XGY2HLq/Jekmbc OkubU7HfDtrZMYDmvgonHD1utiAcR4LvqSsWDAsIS0Z6XdjlDulkJJKs9arySVnMWP6L f3UHPI5VPzOOy8MctcKikNdGti8agirpq+/9tKWxZPiG3XnEysBgQIm83yx8JJBXB8eG J5Fe1R9AxZkQavN8vLW9EZmrb1jvuWkD1pkgF2ngQjki+TFUWzN1MMaNr8USGE8+TxTc qEwSbnWcPGrFaMROOZSbjyA1Lo6PDD8hRZPVVithSffKZpeiPfOVwUV9LRcB7sspsjbj A/tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=NQ9dLE4qRCZ8PE+mGm5akTvNPqhS4+bDbb1b5kZNXMQ=; b=ECDWLBi/h9fB59m8qgGQyy25Wc+wcvR2mXSEWuXmNSzcdrYYDADr+BNUDVj1ZlmpHE /GEsaE/h301dh/O3+ZE+7koqvHe7HWcJaLoGS/QUrm9BEg0ChnDBjxoy0upQgIjdarFq YeD4joVM/vpOFfu7yZpOgVN1oAUDiMJPRQwLBD8wHsk78N9w+14XAHN16AmAkUWxYv1a li7qyzjb+hvNpBw7dLRbm+Ajwlzc/X50LdHigJi2xGUqSVcUYmTOOEvoZ6XS8IPwTgDM J8sdtfds35evKj/2mji7FdWPPidwXPg9Agr3e82j+Lf91nvD3r8G+COJDrGllE16tLa1 DfZQ== X-Gm-Message-State: AOAM533ZjN9pIYnOZH2Y+7sApj11YX9BVrjQf2zx3UGIPJy+ODrCGZKN ZropeWAj9M8ZUca9cVxn6Mn0evhKd4M= X-Google-Smtp-Source: ABdhPJy1yjCsScotrOSNvwh6wSyWp4F0ZLz8Im9TS1U21JSqIn1A9LUv5QBqU5kUB86qjHVHYKzihA== X-Received: by 2002:a37:bfc3:: with SMTP id p186mr650299qkf.440.1644605221693; Fri, 11 Feb 2022 10:47:01 -0800 (PST) Received: from localhost.localdomain (c-69-250-217-147.hsd1.md.comcast.net. [69.250.217.147]) by smtp.gmail.com with ESMTPSA id t1sm13668767qtc.48.2022.02.11.10.47.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Feb 2022 10:47:01 -0800 (PST) From: James Carter To: selinux@vger.kernel.org Cc: James Carter Subject: [PATCH 1/2] libsepol/cil: Don't add constraint if there are no permissions Date: Fri, 11 Feb 2022 13:46:49 -0500 Message-Id: <20220211184650.535016-1-jwcart2@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Since CIL allows permission expressions, it is possible for the expression to evaluate to no permissions. If this is the case, then don't add the constraint. Signed-off-by: James Carter --- libsepol/cil/src/cil_binary.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libsepol/cil/src/cil_binary.c b/libsepol/cil/src/cil_binary.c index 4ac8ce8d..468fb595 100644 --- a/libsepol/cil/src/cil_binary.c +++ b/libsepol/cil/src/cil_binary.c @@ -2823,6 +2823,12 @@ int cil_constrain_to_policydb_helper(policydb_t *pdb, const struct cil_db *db, s goto exit; } + if (sepol_constrain->permissions == 0) { + /* No permissions, so don't insert rule. */ + free(sepol_constrain); + return SEPOL_OK; + } + rc = __cil_constrain_expr_to_sepol_expr(pdb, db, expr, &sepol_expr); if (rc != SEPOL_OK) { goto exit; From patchwork Fri Feb 11 18:46:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Carter X-Patchwork-Id: 12743759 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C9A8C433EF for ; Fri, 11 Feb 2022 18:47:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232268AbiBKSrF (ORCPT ); Fri, 11 Feb 2022 13:47:05 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232627AbiBKSrE (ORCPT ); Fri, 11 Feb 2022 13:47:04 -0500 Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E9E6338 for ; Fri, 11 Feb 2022 10:47:03 -0800 (PST) Received: by mail-qk1-x72f.google.com with SMTP id c189so9025274qkg.11 for ; Fri, 11 Feb 2022 10:47:03 -0800 (PST) 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=eoR2YH5tbQH+EU/rWRLndsquDyZ5lUN1Re0063fNjZs=; b=NxB4Xn9RbDDY6+rPnE4Yys46WfhDA/ihZJ8VD01DfI0s1H/nckiMjhXYUxcZhhZruv ep8xreWGez7NWmZbDCBNTXGVW184lCtM6MOqot0ZumgLhRER+E48rGKDs6m7AHOvrBia QLlFXj7YBlHlaV5w69FOE+Yx86ttK6Uf9b8qV3mz7JBV8+FCQzhWti8cshUwWaqBaJ1O 2xk7a6CbsfedivlR2dvIsLm1JNHlwlFejkkPs4rHczePESqGlsPMuRTCura3ILWDSTnm EwfQkz9l3EPO2gxgnCM2gJHE3H2l4OCozzTfax23Ic/QuI5hMX9wGCJV5O14PbNsOfyn M2Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eoR2YH5tbQH+EU/rWRLndsquDyZ5lUN1Re0063fNjZs=; b=wp2h5OWRjncyj+sENR4oEYTYCfQ0YmmYmfQvasiXXPfBTWFuKyfH0xEn5Wd6bPLKan 0T5L+sGQeLKZuKmfaRcOv9gulJysNiXn6CNYNs3u/lpDTo9W/lSpADHU3t8C92IYZMUU kYDxJNOHX2+0FA+05C2K+ppUhtM20AdYiAZ/0R7EBROp3NnbpybMBYGmdCDdhA7RC5FC r86HIDSiWOziyuILB8D0hJ55x1mZC3qDGV8X1BioJ3Elw+9BNQgy4xVQfOVeypq04U6l bVMPazzqwuWDfPnF8a8hw1tAU9UZFDFhZq7zWJT8SkVKhgM7/CmhO+PpWc2OMPPKRP0G MsYA== X-Gm-Message-State: AOAM530YnmwiK+ts5AZS/xtheGPaztOhGL7xstT6BFAEiRcPNijlu82N qE5aR7QEWzr2A84heQiONDbHXbcA5k8= X-Google-Smtp-Source: ABdhPJzZRq+xOn1WniwXwkhtfML8j0emVTfJ5FLIlhAxE14AUnLKOS6dPUsLeDGbcOEpBWvWW5DWbQ== X-Received: by 2002:a05:620a:b42:: with SMTP id x2mr1455220qkg.362.1644605222416; Fri, 11 Feb 2022 10:47:02 -0800 (PST) Received: from localhost.localdomain (c-69-250-217-147.hsd1.md.comcast.net. [69.250.217.147]) by smtp.gmail.com with ESMTPSA id t1sm13668767qtc.48.2022.02.11.10.47.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Feb 2022 10:47:01 -0800 (PST) From: James Carter To: selinux@vger.kernel.org Cc: James Carter Subject: [PATCH 2/2] libsepol: Don't write out constraint if it has no permissions Date: Fri, 11 Feb 2022 13:46:50 -0500 Message-Id: <20220211184650.535016-2-jwcart2@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220211184650.535016-1-jwcart2@gmail.com> References: <20220211184650.535016-1-jwcart2@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org When writing a conf file or CIL policy out from a kernel binary, do not write out a constraint rule if it has no permissions. Signed-off-by: James Carter --- libsepol/src/kernel_to_cil.c | 3 +++ libsepol/src/kernel_to_conf.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/libsepol/src/kernel_to_cil.c b/libsepol/src/kernel_to_cil.c index 693206d2..869f6940 100644 --- a/libsepol/src/kernel_to_cil.c +++ b/libsepol/src/kernel_to_cil.c @@ -282,6 +282,9 @@ static int class_constraint_rules_to_strs(struct policydb *pdb, char *classkey, struct strs *strs; for (curr = constraint_rules; curr != NULL; curr = curr->next) { + if (curr->permissions == 0) { + continue; + } expr = constraint_expr_to_str(pdb, curr->expr, &is_mls); if (!expr) { rc = -1; diff --git a/libsepol/src/kernel_to_conf.c b/libsepol/src/kernel_to_conf.c index 52b6c60f..3544f73d 100644 --- a/libsepol/src/kernel_to_conf.c +++ b/libsepol/src/kernel_to_conf.c @@ -277,6 +277,9 @@ static int class_constraint_rules_to_strs(struct policydb *pdb, char *classkey, int rc = 0; for (curr = constraint_rules; curr != NULL; curr = curr->next) { + if (curr->permissions == 0) { + continue; + } expr = constraint_expr_to_str(pdb, curr->expr, &is_mls); if (!expr) { rc = -1;