From patchwork Wed Nov 24 19:08:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 12637459 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 16C94C433F5 for ; Wed, 24 Nov 2021 19:08:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350903AbhKXTLe (ORCPT ); Wed, 24 Nov 2021 14:11:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242927AbhKXTLd (ORCPT ); Wed, 24 Nov 2021 14:11:33 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81089C061574 for ; Wed, 24 Nov 2021 11:08:23 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id e3so14986016edu.4 for ; Wed, 24 Nov 2021 11:08:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=SQAykfFeb480DYd2vbO+CXZfu4SweCc2LVREB//N0RI=; b=hxbOE5xQr8go8bTFvcB8vncRNT9/Prb5RRh5iyw9H141i7dylz6kqNkddIBDltQYgB +MinGWi7TIm78cxelY4FCyx0jfAt7FH0HTWJ5/cu1B2wMd1BKSu75z+ioC+YoewBOH2H s0EoBk71VE76N+w1DzxwEmgznIPIa0+8meHzXFH5gLypt5+Um7UA8eWQFeql3lIjk/sa J0HwOX4sfQ5/jycjU/lK6zx+nvThNFqXtGkFbDuAmwKUoqAq4GNNU0h8i3CnfXQ+ReEC 6Uyq3empp8qXT0yb3fqlv+DIxy0MANnpAhn8HF72tR3Y7r5apz5BYfHnmc4aEa0aDKF3 fKIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SQAykfFeb480DYd2vbO+CXZfu4SweCc2LVREB//N0RI=; b=l6AYpg77bGyD0tAz0Y3D6lsdLD6xvvwHIoeEAl2VmLF59nQ6Ik5grCxkslPMVPCZ9z hQDyx8auMlzjIaZgNBBv4sF85+RxKHRWMiwE2rwoCuxCz0PCbWv86XkZ12mx1CNHqZE/ cIkvwf9M2KN5Rz6xOj/jnc/0545Pk1C2mfwAnxzVLUg68x7+N4NVihvHyv3lrxpaWo6p 7U7TPz9Jv9zvNYbprniTpKRuKrpPVLAvl0GUyMtJZ2bR2LnUQ8awJpXiA3zVnG1+mE19 tZDnJubtkd2pFx36VecWOKqi7EsOMKHA7iv+6fQAaZPZTSIAicpI5JeLQST1FRRW3wU0 cnkQ== X-Gm-Message-State: AOAM530Q3+zVD1GJvwrWTvAbquBg9qf132KtPhtOQAdSjXiOsyhhb0K5 jPJFXEAVH+22D3xlbrdBz7GJOj1hG5gF5A== X-Google-Smtp-Source: ABdhPJzh/OtOVaSauYnkaKH4U7j3MwhJf8YelsiW3TC0aq9OHC43n6SB4Z35dpMSR7HQvPBY/Wdv2g== X-Received: by 2002:a17:906:7955:: with SMTP id l21mr24823912ejo.6.1637780901936; Wed, 24 Nov 2021 11:08:21 -0800 (PST) Received: from debianHome.localdomain (dynamic-077-008-186-056.77.8.pool.telefonica.de. [77.8.186.56]) by smtp.gmail.com with ESMTPSA id p3sm339256ejy.94.2021.11.24.11.08.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 11:08:21 -0800 (PST) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [RFC PATCH v2 1/4] libsepol: introduce ebitmap_subtract() Date: Wed, 24 Nov 2021 20:08:12 +0100 Message-Id: <20211124190815.12757-1-cgzones@googlemail.com> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211123190704.14341-1-cgzones@googlemail.com> References: <20211123190704.14341-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Add a subtract method for ebitmaps. Signed-off-by: Christian Göttsche --- v2: - add shortcut for empty ebitmaps --- libsepol/include/sepol/policydb/ebitmap.h | 1 + libsepol/src/ebitmap.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/libsepol/include/sepol/policydb/ebitmap.h b/libsepol/include/sepol/policydb/ebitmap.h index 81d0c7a6..daca67a2 100644 --- a/libsepol/include/sepol/policydb/ebitmap.h +++ b/libsepol/include/sepol/policydb/ebitmap.h @@ -83,6 +83,7 @@ static inline int ebitmap_node_get_bit(const ebitmap_node_t * n, unsigned int bi extern int ebitmap_cmp(const ebitmap_t * e1, const ebitmap_t * e2); extern int ebitmap_or(ebitmap_t * dst, const ebitmap_t * e1, const ebitmap_t * e2); extern int ebitmap_union(ebitmap_t * dst, const ebitmap_t * e1); +extern int ebitmap_subtract(ebitmap_t *dst, const ebitmap_t *e1); extern int ebitmap_and(ebitmap_t *dst, const ebitmap_t *e1, const ebitmap_t *e2); extern int ebitmap_xor(ebitmap_t *dst, const ebitmap_t *e1, const ebitmap_t *e2); extern int ebitmap_not(ebitmap_t *dst, const ebitmap_t *e1, unsigned int maxbit); diff --git a/libsepol/src/ebitmap.c b/libsepol/src/ebitmap.c index 1de3816a..80f0e201 100644 --- a/libsepol/src/ebitmap.c +++ b/libsepol/src/ebitmap.c @@ -72,6 +72,24 @@ int ebitmap_union(ebitmap_t * dst, const ebitmap_t * e1) return 0; } +int ebitmap_subtract(ebitmap_t *dst, const ebitmap_t *e1) +{ + unsigned int i, length; + + if (ebitmap_is_empty(dst) || ebitmap_is_empty(e1)) + return 0; + + length = min(ebitmap_length(dst), ebitmap_length(e1)); + for (i=0; i < length; i++) { + if (ebitmap_get_bit(e1, i)) { + int rc = ebitmap_set_bit(dst, i, 0); + if (rc < 0) + return rc; + } + } + return 0; +} + int ebitmap_and(ebitmap_t *dst, const ebitmap_t *e1, const ebitmap_t *e2) { unsigned int i, length = min(ebitmap_length(e1), ebitmap_length(e2)); From patchwork Wed Nov 24 19:08:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 12637461 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 B12A1C433EF for ; Wed, 24 Nov 2021 19:08:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350907AbhKXTLf (ORCPT ); Wed, 24 Nov 2021 14:11:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242927AbhKXTLe (ORCPT ); Wed, 24 Nov 2021 14:11:34 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07404C06173E for ; Wed, 24 Nov 2021 11:08:24 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id e3so14986083edu.4 for ; Wed, 24 Nov 2021 11:08:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=TauaxXjrhRutN6oPo6eDHF4hG+8baJDPly2T/TRVXWo=; b=qcFt/glqbWESWMb5mYrgdKQMOQxoGsgO62Kl3UoNDJwKCl5RwA2wgQZSpecQsw7UXf 0tx0UF8f0aFwaAp/Jjln0Z9Dh7eyESAlB3F2eOaSZIEmOSlnOv1Gpe3E/4Am0RDlkvJW zsMrnjNYmbCkQ/MfDLk9DjudUPy0XrhzdMFcb1hEVJw20YTXlW+KeepcAS8W/TBVu88Q N/ytjLz+UWpzUrgRnvLXpKp5dH07YFz4xbIEckazdwjdPUpOPoKze/iJv5629wcpwsT8 MIq5rvj8GXA9CV51Wbv9O1cKYdhLI6uBFPzmBarYe8gQ2FfDZgd0YoqybF7030okkkaG CbbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TauaxXjrhRutN6oPo6eDHF4hG+8baJDPly2T/TRVXWo=; b=QJ5xUWTCwrAImI/p/+2eBfR1fiFc50EMdanOsfNRqdkvMXRpU2p1YE2uO0q/QPNhZ7 kij5QMRQcHL+BHUksyomsiqHpSr3lfjFe8DE13g4szu3vkPHjAu4jsUf9iIGy5ID6rJv OhC0ff1eDqFy6l2cwGcjswaTh0XZRIuUNMEkKGCCOEPZ9N83vaUzFCVlTHHVLlWvRwFQ TzPw5Ata5I6ARVgG7p75vsNEm6HWUyFlZSFy/Ft3U7KLL0hrKuEqiZuJwwm6P7m+neRL xjNgfP0GOECsF1l5fkMQBbXmlTCp2UHXNUcBqdxw0Cy70yqNfQ4XxVDaHqzx2HWlR/2U V/dg== X-Gm-Message-State: AOAM530hM4I9h9m3XVmd19KMssEyjI8IJdULkKESXlcHHhuAmo3eZ9Wa 8L1tTicgHwQm4jfW+tb/Noti+CutYTqpZg== X-Google-Smtp-Source: ABdhPJxHdSoGLUMRpiyBlcYef6KOX8Eto9M0w73+Nei3UeaKFaF+e2y2OCsg9mKgiIO9mwHHmyz+JQ== X-Received: by 2002:a50:d8cf:: with SMTP id y15mr28816007edj.66.1637780902513; Wed, 24 Nov 2021 11:08:22 -0800 (PST) Received: from debianHome.localdomain (dynamic-077-008-186-056.77.8.pool.telefonica.de. [77.8.186.56]) by smtp.gmail.com with ESMTPSA id p3sm339256ejy.94.2021.11.24.11.08.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 11:08:22 -0800 (PST) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [RFC PATCH v2 2/4] libsepol: add not-self neverallow support Date: Wed, 24 Nov 2021 20:08:13 +0100 Message-Id: <20211124190815.12757-2-cgzones@googlemail.com> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211124190815.12757-1-cgzones@googlemail.com> References: <20211123190704.14341-1-cgzones@googlemail.com> <20211124190815.12757-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Add support for not-self neverallow rules. These do not trigger on allow rules where the source type is exactly equal to the target type. Signed-off-by: Christian Göttsche --- v2: - do not change the value of RULE_SELF --- libsepol/include/sepol/policydb/policydb.h | 3 +- libsepol/src/assertion.c | 36 ++++++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/libsepol/include/sepol/policydb/policydb.h b/libsepol/include/sepol/policydb/policydb.h index 4bf9f05d..11637fe8 100644 --- a/libsepol/include/sepol/policydb/policydb.h +++ b/libsepol/include/sepol/policydb/policydb.h @@ -285,7 +285,8 @@ typedef struct avrule { #define AVRULE_XPERMS (AVRULE_XPERMS_ALLOWED | AVRULE_XPERMS_AUDITALLOW | \ AVRULE_XPERMS_DONTAUDIT | AVRULE_XPERMS_NEVERALLOW) uint32_t specified; -#define RULE_SELF 1 +#define RULE_SELF (1U << 0) +#define RULE_NOTSELF (1U << 1) uint32_t flags; type_set_t stypes; type_set_t ttypes; diff --git a/libsepol/src/assertion.c b/libsepol/src/assertion.c index dd2749a0..efa136c8 100644 --- a/libsepol/src/assertion.c +++ b/libsepol/src/assertion.c @@ -241,7 +241,7 @@ static int report_assertion_avtab_matches(avtab_key_t *k, avtab_datum_t *d, void if (rc) goto oom; - if (avrule->flags == RULE_SELF) { + if (avrule->flags & RULE_SELF) { rc = ebitmap_and(&matches, &p->attr_type_map[k->source_type - 1], &p->attr_type_map[k->target_type - 1]); if (rc) goto oom; @@ -268,6 +268,8 @@ static int report_assertion_avtab_matches(avtab_key_t *k, avtab_datum_t *d, void ebitmap_for_each_positive_bit(&src_matches, snode, i) { ebitmap_for_each_positive_bit(&tgt_matches, tnode, j) { + if ((avrule->flags & RULE_NOTSELF) && i == j) + continue; if (avrule->specified == AVRULE_XPERMS_NEVERALLOW) { a->errors += report_assertion_extended_permissions(handle,p, avrule, i, j, cp, perms, k, avtab); @@ -402,7 +404,7 @@ static int check_assertion_extended_permissions(avrule_t *avrule, avtab_t *avtab if (rc) goto oom; - if (avrule->flags == RULE_SELF) { + if (avrule->flags & RULE_SELF) { rc = ebitmap_and(&matches, &p->attr_type_map[k->source_type - 1], &p->attr_type_map[k->target_type - 1]); if (rc) @@ -418,6 +420,18 @@ static int check_assertion_extended_permissions(avrule_t *avrule, avtab_t *avtab } } + if (avrule->flags & RULE_NOTSELF) { + rc = ebitmap_and(&matches, &p->attr_type_map[k->source_type - 1], &p->attr_type_map[k->target_type - 1]); + if (rc) + goto oom; + rc = ebitmap_and(&self_matches, &avrule->ttypes.types, &matches); + if (rc) + goto oom; + rc = ebitmap_subtract(&tgt_matches, &self_matches); + if (rc) + goto oom; + } + if (ebitmap_is_empty(&tgt_matches)) goto exit; @@ -463,7 +477,7 @@ static int check_assertion_avtab_match(avtab_key_t *k, avtab_datum_t *d, void *a if (rc == 0) goto exit; - if (avrule->flags == RULE_SELF) { + if (avrule->flags & RULE_SELF) { /* If the neverallow uses SELF, then it is not enough that the * neverallow's source matches the src and tgt of the rule being checked. * It must match the same thing in the src and tgt, so AND the source @@ -479,6 +493,22 @@ static int check_assertion_avtab_match(avtab_key_t *k, avtab_datum_t *d, void *a ebitmap_destroy(&match); } + if (avrule->flags & RULE_NOTSELF) { + ebitmap_t match; + rc = ebitmap_cpy(&match, &p->attr_type_map[k->source_type - 1]); + if (rc) { + ebitmap_destroy(&match); + goto oom; + } + rc = ebitmap_subtract(&match, &p->attr_type_map[k->target_type - 1]); + if (rc) { + ebitmap_destroy(&match); + goto oom; + } + rc2 = ebitmap_match_any(&avrule->ttypes.types, &match); + ebitmap_destroy(&match); + } + /* neverallow may have tgts even if it uses SELF */ rc = ebitmap_match_any(&avrule->ttypes.types, &p->attr_type_map[k->target_type -1]); if (rc == 0 && rc2 == 0) From patchwork Wed Nov 24 19:08:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 12637463 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 45512C433FE for ; Wed, 24 Nov 2021 19:08:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237578AbhKXTLi (ORCPT ); Wed, 24 Nov 2021 14:11:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350906AbhKXTLe (ORCPT ); Wed, 24 Nov 2021 14:11:34 -0500 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A487BC061574 for ; Wed, 24 Nov 2021 11:08:24 -0800 (PST) Received: by mail-ed1-x535.google.com with SMTP id x15so14924540edv.1 for ; Wed, 24 Nov 2021 11:08:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=OSjelv+XERb3ttiEo/h/qavc/aMITk3pWcNy9/KGD+I=; b=pLS+nBk1eel++JAoMJnfeAPYSm90ym/sOKyqwTThGHemlaVJHH/Hwcz995ueDo8o9H 7mReG3e14DsLJeloeUUFk7BNSIhvh9Ws4zbCHlFu+DoIoyGt/+t20lp6CMXspuYt8N4t H9/1EXWfgko51j8sVEMNSSQMvYfaOPwDDuE1sV/TajHnIn9bvfb12q2GsrAmd6UcJiXl KJK8+v/LDaSHfa9zBtDFgXWzvFknnbake0mjjS1otyztqTa5aaNJXgE1q1fdwjAkKV/z 8HDRK3zIp625/mRGridrVFB4cFdYOlu5uJc/t8fz+mUrR3+JCD/xRKlQsiBdHHS53NZM HRQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OSjelv+XERb3ttiEo/h/qavc/aMITk3pWcNy9/KGD+I=; b=5fupBUUOpBFrO+3oDOlvrIQX6Cx7lWuc3Y2Hyv1tr05IiGZ6HzisuzoMQ9CXw2Q/2b Zix0KBVXX2c8CzqEu4WCYKE9Su1w5T0na0KJiA9wgRa2E+w4e7864tAp0+0Tp4qUJ7lo xOD3fsQ7VEZpt5LbOGFb2ue8xUThhAZ8L32DHkCwKH4YycfpltoLYIM5jzTsR42vO060 WZqBRPChnjvsKwPvhUrH9DEHySc3yZRLtFCw0xydCMpEc1c/UJ0Kx7hotK0dTaSviZC4 Yf9lTgE8ATkRmEHbxb13GCOieXjUkmL1h0ROL/QRtFbTc05gB4Hb1dt8MO0wOw5pKNv3 ZX3g== X-Gm-Message-State: AOAM5304Ou23xNJv+n3xVG8BSuss+N+OD3ly+lDrSq07n0CZ0xGbRjuB 3nxbcrWZcKkism+KcwOAZiVPadzgpNh/Wg== X-Google-Smtp-Source: ABdhPJzNA/tAM+zW1Z0kxXRdZOiNbyVLKegX1toqjiqfWTG1wEP207D/s3Xo67icWh0DvayFr89fcw== X-Received: by 2002:a17:907:b17:: with SMTP id h23mr23683177ejl.80.1637780903117; Wed, 24 Nov 2021 11:08:23 -0800 (PST) Received: from debianHome.localdomain (dynamic-077-008-186-056.77.8.pool.telefonica.de. [77.8.186.56]) by smtp.gmail.com with ESMTPSA id p3sm339256ejy.94.2021.11.24.11.08.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 11:08:22 -0800 (PST) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [RFC PATCH v2 3/4] checkpolicy: add not-self neverallow support Date: Wed, 24 Nov 2021 20:08:14 +0100 Message-Id: <20211124190815.12757-3-cgzones@googlemail.com> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211124190815.12757-1-cgzones@googlemail.com> References: <20211123190704.14341-1-cgzones@googlemail.com> <20211124190815.12757-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Add support for using negated or complemented self in the target type of neverallow rules. Some refpolicy examples: neverallow * ~self:{ capability cap_userns capability2 cap2_userns } *; # no violations neverallow domain domain:file ~{ append read_file_perms write }; libsepol.report_failure: neverallow on line 565 of policy/modules/kernel/kernel.te (or line 30300 of policy.conf) violated by allow sysadm_t httpd_bugzilla_script_t:file { create setattr relabelfrom relabelto unlink link rename }; libsepol.report_failure: neverallow on line 565 of policy/modules/kernel/kernel.te (or line 30300 of policy.conf) violated by allow chromium_t chromium_t:file { create }; libsepol.report_failure: neverallow on line 564 of policy/modules/kernel/kernel.te (or line 30299 of policy.conf) violated by allow sysadm_t httpd_bugzilla_script_t:dir { create }; neverallow domain { domain -self }:file ~{ append read_file_perms write }; libsepol.report_failure: neverallow on line 565 of policy/modules/kernel/kernel.te (or line 30300 of policy.conf) violated by allow sysadm_t httpd_bugzilla_script_t:file { create setattr relabelfrom relabelto unlink link rename }; libsepol.report_failure: neverallow on line 564 of policy/modules/kernel/kernel.te (or line 30299 of policy.conf) violated by allow sysadm_t httpd_bugzilla_script_t:dir { create }; Using negated self in a complement `~{ domain -self }` is not supported. Signed-off-by: Christian Göttsche --- v2: - fix neverallowxperm usage --- checkpolicy/policy_define.c | 46 ++++++++++++++++++++++++++++++++----- checkpolicy/test/dismod.c | 6 ++++- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/checkpolicy/policy_define.c b/checkpolicy/policy_define.c index d3eb6111..f27a6f33 100644 --- a/checkpolicy/policy_define.c +++ b/checkpolicy/policy_define.c @@ -2067,12 +2067,17 @@ static int define_te_avtab_xperms_helper(int which, avrule_t ** rule) while ((id = queue_remove(id_queue))) { if (strcmp(id, "self") == 0) { free(id); - if (add == 0) { - yyerror("-self is not supported"); + if (add == 0 && which != AVRULE_XPERMS_NEVERALLOW) { + yyerror("-self is only supported in neverallowxperm rules"); + ret = -1; + goto out; + } + avrule->flags |= (add ? RULE_SELF : RULE_NOTSELF); + if ((avrule->flags & RULE_SELF) && (avrule->flags & RULE_NOTSELF)) { + yyerror("self and -self is not supported"); ret = -1; goto out; } - avrule->flags |= RULE_SELF; continue; } if (set_types @@ -2083,6 +2088,18 @@ static int define_te_avtab_xperms_helper(int which, avrule_t ** rule) } } + if ((avrule->ttypes.flags & TYPE_COMP)) { + if (avrule->flags & RULE_NOTSELF) { + yyerror("-self is not supported in complements"); + ret = -1; + goto out; + } + if (avrule->flags & RULE_SELF) { + avrule->flags &= ~RULE_SELF; + avrule->flags |= RULE_NOTSELF; + } + } + ebitmap_init(&tclasses); ret = read_classes(&tclasses); if (ret) @@ -2528,12 +2545,17 @@ static int define_te_avtab_helper(int which, avrule_t ** rule) while ((id = queue_remove(id_queue))) { if (strcmp(id, "self") == 0) { free(id); - if (add == 0) { - yyerror("-self is not supported"); + if (add == 0 && which != AVRULE_NEVERALLOW) { + yyerror("-self is only supported in neverallow rules"); + ret = -1; + goto out; + } + avrule->flags |= (add ? RULE_SELF : RULE_NOTSELF); + if ((avrule->flags & RULE_SELF) && (avrule->flags & RULE_NOTSELF)) { + yyerror("self and -self is not supported"); ret = -1; goto out; } - avrule->flags |= RULE_SELF; continue; } if (set_types @@ -2544,6 +2566,18 @@ static int define_te_avtab_helper(int which, avrule_t ** rule) } } + if ((avrule->ttypes.flags & TYPE_COMP)) { + if (avrule->flags & RULE_NOTSELF) { + yyerror("-self is not supported in complements"); + ret = -1; + goto out; + } + if (avrule->flags & RULE_SELF) { + avrule->flags &= ~RULE_SELF; + avrule->flags |= RULE_NOTSELF; + } + } + ebitmap_init(&tclasses); ret = read_classes(&tclasses); if (ret) diff --git a/checkpolicy/test/dismod.c b/checkpolicy/test/dismod.c index ec2a3e9a..a2d74d42 100644 --- a/checkpolicy/test/dismod.c +++ b/checkpolicy/test/dismod.c @@ -124,7 +124,7 @@ static int display_type_set(type_set_t * set, uint32_t flags, policydb_t * polic } num_types = 0; - if (flags & RULE_SELF) { + if (flags & (RULE_SELF | RULE_NOTSELF)) { num_types++; } @@ -169,6 +169,10 @@ static int display_type_set(type_set_t * set, uint32_t flags, policydb_t * polic fprintf(fp, " self"); } + if (flags & RULE_NOTSELF) { + fprintf(fp, " -self"); + } + if (num_types > 1) fprintf(fp, " }"); From patchwork Wed Nov 24 19:08:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 12637465 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 B10D7C433F5 for ; Wed, 24 Nov 2021 19:08:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239974AbhKXTLk (ORCPT ); Wed, 24 Nov 2021 14:11:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350910AbhKXTLf (ORCPT ); Wed, 24 Nov 2021 14:11:35 -0500 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BDF1C06173E for ; Wed, 24 Nov 2021 11:08:25 -0800 (PST) Received: by mail-ed1-x534.google.com with SMTP id r11so14900401edd.9 for ; Wed, 24 Nov 2021 11:08:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=DvHzWs666aXqrRw4ZTDs15zTNsMxqXc8bxBiSNAXvkw=; b=cRYKfcXNnbSag55+WbuToBVfuHJ6u8Nk2O+4RiLwnKQ6pjZNkB9tcr6yWYbUoo2rsp Bz2yWanTkBGNZYFZ+yjSuAuXIctCV5noV7UJHD91D1tqf7ZfF0Qjlh6Zb8ZeA0nT17XJ lhyYwfAeq6V9g+VvF3MCNIzq3RiNQoHllbsqy1KSf+/VYQrOwYGQwgtJ2kPCNnw5lqiS L34ZB68mwp9dJgXKS0Ip8g61UyNMLKT5A8PNmWIxOg1GzdMsO1ossTGzO5C1HTTasKE6 f2clOxFuGnFhmWsOg0s89oaulEnnI0a4kHh7fhq3pvqBn0tZoJ/tgUW1cC4uneoRkipJ 5w1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DvHzWs666aXqrRw4ZTDs15zTNsMxqXc8bxBiSNAXvkw=; b=lB1hqds33KPe/WvLUV7u3BGIwVM6rhh3pKp8yg/+XceQa2kOOTD5AHsVkt5BRBbYfU X9DMPxfSpk5MBCVC1dSlxg6SFuNcNOECcXiXe4sIHD6xNgdCej9zjJyudNcs3ktFCTGU Cp53RsAL5V22Kg8oXsqMRV6RdfYEcOAwSMzUw0OvfmcX+mJaeRfBRcX5j+yxOb7IqyJV 6narUjXvnAK6BHeNPL/aSp085Si/Ue/8QKdKajkJCBAiwos9VOxpxj43B/InfZt034Uq RPu8cPwMIRLBpT+HY1VFtSWpI2Cdi+ChJZnjWYPA+cOUm00ENpFulTBGibIk3lfH+m55 oHHA== X-Gm-Message-State: AOAM532LfV2cMk+i4iGvtiIqvMA2xz03vk26YtQh+2CJ5DxTiwEIwgNm o/kN2ekSszzUI9xZCuomMMXgSGnKTRYuUg== X-Google-Smtp-Source: ABdhPJzxgz8RbFV8/S5AggNinhgUHbIZ8OI8UwqGX5klSIcnaVH+ktZ+WhJ6fk+LprfK/ldUCg50AQ== X-Received: by 2002:a05:6402:354e:: with SMTP id f14mr28405367edd.245.1637780903610; Wed, 24 Nov 2021 11:08:23 -0800 (PST) Received: from debianHome.localdomain (dynamic-077-008-186-056.77.8.pool.telefonica.de. [77.8.186.56]) by smtp.gmail.com with ESMTPSA id p3sm339256ejy.94.2021.11.24.11.08.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 11:08:23 -0800 (PST) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [RFC PATCH v2 4/4] libsepol: free ebitmap on end of function Date: Wed, 24 Nov 2021 20:08:15 +0100 Message-Id: <20211124190815.12757-4-cgzones@googlemail.com> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211124190815.12757-1-cgzones@googlemail.com> References: <20211123190704.14341-1-cgzones@googlemail.com> <20211124190815.12757-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Signed-off-by: Christian Göttsche --- libsepol/src/assertion.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libsepol/src/assertion.c b/libsepol/src/assertion.c index efa136c8..429e61f5 100644 --- a/libsepol/src/assertion.c +++ b/libsepol/src/assertion.c @@ -455,6 +455,7 @@ oom: exit: ebitmap_destroy(&src_matches); ebitmap_destroy(&tgt_matches); + ebitmap_destroy(&self_matches); ebitmap_destroy(&matches); return ret; }