From patchwork Wed Jul 13 13:43:41 2022 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: 12916752 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 D98E2C433EF for ; Wed, 13 Jul 2022 13:43:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230064AbiGMNnz (ORCPT ); Wed, 13 Jul 2022 09:43:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235157AbiGMNnx (ORCPT ); Wed, 13 Jul 2022 09:43:53 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B413221242 for ; Wed, 13 Jul 2022 06:43:51 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id w12so13424784edd.13 for ; Wed, 13 Jul 2022 06:43:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=wVCQjuE4rq4BsATRPowf3jYYOLjF1n8SI07aqJ9Dpns=; b=ltIPfdzfyIaUlTJ27guHwQuEbuq9a4O17tVRYYDVO2bIADpkqv4Z6DUnARfcvoQJ6x UKRpNEO99VNLldPYDLkV0l2fQvJyKfNexoupfDa5a8U515hx+XpZ+pGtvAAen7ZAuMG1 osAFPTWBzfmsABs33B9IxcuHH6AZ05vqCxLHnaRJv9ZgWgKsBatld1z8k2LpiQuhCP4X aEcHnWirZw59L8QBlREIVwuoi7oNEgDWq0P9uzmOKqAXfQlZgl8DXPsOR1/Xv55Wmwk9 cE7v6pJh8P15J61FQiSOyZ72iegTWukf5vuv0fuGo2QNX0PzBy0x9akMppG42pHLJ/xh sc4Q== 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:mime-version :content-transfer-encoding; bh=wVCQjuE4rq4BsATRPowf3jYYOLjF1n8SI07aqJ9Dpns=; b=5BRwQaRNJNFAP8lXlUhyI+1IkTO16yIYx3wdxRWZ3X5r41nMYy9/z7Mqkb58RBdocq mw9dJE7wn8x9VS7psFo6GqfWijd+wiFSkLj0ZwPEFOhDkFaVyU3Y28BNN2hNdMq/WJpg 6sMORb/IDjbuKktmxHPA1s54wa/jPvGNecPmU0meFVgn55bqPc5O0/qfr9tbr2iSerRm 5JSdYLY75M96WGQFPNHUJFWlKZA8CU6+5TOvq5MhfRaN9Hyq6i+4pP6m4U9POlcyNw+g oNwX3qcLx2NUWMyhMKNwUPzc7lQaAXosAMOdQw9TEp4ZlZ/SiY8qmynjuvRNa1fKLrAM FuDw== X-Gm-Message-State: AJIora8mO6zY1xAgrmD/NYfZwqx8PLJUgZOltJ+m5K9lYhKdcFsR86gK oilFM22WNevFuNvgAZkWUVKJEMj0tX4t2A== X-Google-Smtp-Source: AGRyM1v/tBkS0DDJQcHAPotRMcl+r26TiPmzcm533lTQCYhkgdumugIBdYIhPCLgSSqqDpk/yUMnow== X-Received: by 2002:a05:6402:40ce:b0:43a:918d:a73f with SMTP id z14-20020a05640240ce00b0043a918da73fmr5074647edb.387.1657719829587; Wed, 13 Jul 2022 06:43:49 -0700 (PDT) Received: from debianHome.localdomain (dynamic-095-116-083-213.95.116.pool.telefonica.de. [95.116.83.213]) by smtp.gmail.com with ESMTPSA id g18-20020a170906539200b00722fc0779e3sm4973763ejo.85.2022.07.13.06.43.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 06:43:49 -0700 (PDT) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [PATCH 1/3] libsepol: break circular include Date: Wed, 13 Jul 2022 15:43:41 +0200 Message-Id: <20220713134343.19811-1-cgzones@googlemail.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Since `struct type_set` is forward declared including policydb/policydb.h is not necessary and creates a circular include. Also drop the unnecessary forward declaration of `struct policydb`. Signed-off-by: Christian Göttsche Acked-by: James Carter --- libsepol/include/sepol/policydb/constraint.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/libsepol/include/sepol/policydb/constraint.h b/libsepol/include/sepol/policydb/constraint.h index b91fc4e9..82335e21 100644 --- a/libsepol/include/sepol/policydb/constraint.h +++ b/libsepol/include/sepol/policydb/constraint.h @@ -18,7 +18,6 @@ #ifndef _SEPOL_POLICYDB_CONSTRAINT_H_ #define _SEPOL_POLICYDB_CONSTRAINT_H_ -#include #include #include @@ -70,8 +69,6 @@ typedef struct constraint_node { struct constraint_node *next; /* next constraint */ } constraint_node_t; -struct policydb; - extern int constraint_expr_init(constraint_expr_t * expr); extern void constraint_expr_destroy(constraint_expr_t * expr); From patchwork Wed Jul 13 13:43:42 2022 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: 12916751 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 42181C43334 for ; Wed, 13 Jul 2022 13:43:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229918AbiGMNny (ORCPT ); Wed, 13 Jul 2022 09:43:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232797AbiGMNnx (ORCPT ); Wed, 13 Jul 2022 09:43:53 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3FC020BE9 for ; Wed, 13 Jul 2022 06:43:51 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id r18so14140234edb.9 for ; Wed, 13 Jul 2022 06:43:51 -0700 (PDT) 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=R+C7f1K0/GyPwWwNwIoeMTgBASKEbixLaqwNLscmI9A=; b=oJjnanyrioVGwFmlXIyogpZsxvGew0IbIBvKATVWtgzhU7RlHGwl27WdvEd+yflyvb oN4SVcTp7/t104xeWQNbjJl5Yx0R0shOKr9SdjSI0vpisSvwxJF/I1e1F8HUAezhtcqC wGWbWYzjqEMicSB1YeV5wcFW78CVoC+ajc54LgSy7lNrX5FZkdR0r9xwCBM/UHmD6oLg rVFg3dC9uapwb3xvZKLsYBnIv9gmFTyBM8SLwZRgxBW6fpu/gBLLJxmPDo04rSodVFwQ jQs338WEqsPuJRV/sOz6RK/mqUIbugBa6WBMN3ehMjR63KlxW28vBBkA/NW9pq80JjA6 x7zw== 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=R+C7f1K0/GyPwWwNwIoeMTgBASKEbixLaqwNLscmI9A=; b=BwFYREhIMciBndiSeO4ead9eBOLHpleEa6qDlPM5elNRr5vcl/SS02d86EoxttCkPA UdiniQk/86K+R/EhgDr/bgwKDbBLKE+PMino3dbKS8FYRJXKy+VoY7Ubu9J6KdeGmZeX c6/AV5RY0XyKdZCsihtHT+Np5SbPv5TtZp2zULfF4WfhayjWMZGhaMvx/dVMI3FscQE8 xA9QVNiWT8NEW/F5pz0e04Y7t8WBCU+hxn6ZT2OQhl+qWNNpSLu5mO5iO5WAYI9Ymycd 7ewd+b+iAEP078EY6py7JKGSKA7jHOCetlxrPHpCCYf2waEhPMUQSLrG13ocuBbcYi9B cdsw== X-Gm-Message-State: AJIora9cAe0XUO47+4KBxng8GNPK0gXXMQrlOpx4fat127UVQDbJkKBs hE0bNxtIjSIoQcpKos7tE2TLjnUXFCykhw== X-Google-Smtp-Source: AGRyM1sGWg4AJQGVR1hH+mYfWBvuaYiH7ZGTI04mHRv6YhDj0rIatPXHW9y/cKIPucBLvw8tFyak9Q== X-Received: by 2002:a05:6402:5008:b0:437:7f01:82a with SMTP id p8-20020a056402500800b004377f01082amr5165710eda.220.1657719830147; Wed, 13 Jul 2022 06:43:50 -0700 (PDT) Received: from debianHome.localdomain (dynamic-095-116-083-213.95.116.pool.telefonica.de. [95.116.83.213]) by smtp.gmail.com with ESMTPSA id g18-20020a170906539200b00722fc0779e3sm4973763ejo.85.2022.07.13.06.43.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 06:43:49 -0700 (PDT) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [PATCH 2/3] libsepol: include necessary headers in headers Date: Wed, 13 Jul 2022 15:43:42 +0200 Message-Id: <20220713134343.19811-2-cgzones@googlemail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220713134343.19811-1-cgzones@googlemail.com> References: <20220713134343.19811-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Include policydb header file required for typedef policydb_t. This is for example helpful when working with an IDE, which needs to resolve those symbols. Signed-off-by: Christian Göttsche --- libsepol/include/sepol/policydb/util.h | 2 ++ libsepol/src/mls.h | 1 + 2 files changed, 3 insertions(+) diff --git a/libsepol/include/sepol/policydb/util.h b/libsepol/include/sepol/policydb/util.h index ee236a25..db8da213 100644 --- a/libsepol/include/sepol/policydb/util.h +++ b/libsepol/include/sepol/policydb/util.h @@ -23,6 +23,8 @@ #ifndef __SEPOL_UTIL_H__ #define __SEPOL_UTIL_H__ +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/libsepol/src/mls.h b/libsepol/src/mls.h index eb4a1cb8..befd12c5 100644 --- a/libsepol/src/mls.h +++ b/libsepol/src/mls.h @@ -25,6 +25,7 @@ #include "policydb_internal.h" #include +#include #include "handle.h" extern int mls_from_string(sepol_handle_t * handle, From patchwork Wed Jul 13 13:43:43 2022 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: 12916753 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 4E957CCA479 for ; Wed, 13 Jul 2022 13:43:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231236AbiGMNnz (ORCPT ); Wed, 13 Jul 2022 09:43:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235389AbiGMNnx (ORCPT ); Wed, 13 Jul 2022 09:43:53 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55D502AE8 for ; Wed, 13 Jul 2022 06:43:52 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id dn9so19923694ejc.7 for ; Wed, 13 Jul 2022 06:43:52 -0700 (PDT) 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=EzrcWy+LyF0DX7ugCyKzRHZJLseYVkcBn7I3jA9Fxa8=; b=PEyq+Gtncgnf3X9GPAEV9/1YQibMa+y91o+963oFGctCY3PPqTzIXoSsCxYeVqNpFP h8kNHbulaHYL5ZzihwO5V0iQ2iAYpXw2aePSo30HmxBneLVWnsqXD0Neq3OErumRdIoG iTkI9sxdPLVd8LSw1Es9oiCNrb0eq7Y5mEX/LNiKtwXWMiKnqhZqkNU7SjTImaZ/bUW4 Y+YV18s1zTM4JH2w0q1x4xBl1TgZOeokEIhCvefWhKMTiuPaVBv1di1Y84rcEdhaHQsb 6dzQ4eGbXBiVTOBjkQFiSyrAMNx/BOFiMqX711OuGhXg7OBE+6Iw4pwarxKvjZkL1GZF A3fg== 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=EzrcWy+LyF0DX7ugCyKzRHZJLseYVkcBn7I3jA9Fxa8=; b=0tvUIAc69kZCRmkjJPSuxG66WSoWKJvmUu9OSGpVWI0y6FxgEDT3QugQb2DReWkvWf eWmhVSAMGCRgYTztO2H8ZNGyOaEpPtVoexMHdgiq0m5oceNrIRQbX7rkoqsbZuVIRFS7 RQRHyNbk+SmHdAyijdVeAII0kSsw6nvNfnICNAc8Vpg7nyRJaaTzeAaUX+0C/UWXzG6e i2TTUoUw1bOZjnNS+mQNTqkRgsKOo6ygvKDO+ZUCRYAgC0xkWpQlvzplllP3gX+kHmm8 aAtplxui/ITeHnfGCe0zYFXUcm1LHjCn9SBGQn7N7QApVGMXvIAmUdtv2fpQ5toLAS6Q gIgw== X-Gm-Message-State: AJIora/LdKNtKo9rXrROo6rpzOVJ63cQj76aX0H/y5a9CmmbHcQgArQm Daz4o1ZeOov2l7bLV0b4LGu5cFZhdACu/w== X-Google-Smtp-Source: AGRyM1vCNAyYSF/dkvpRJBS5blL+jlXIsqKgba1m/E4f7TdiFORoiXzAuomCLpybdaSRhdjU4nFyUg== X-Received: by 2002:a17:907:2ce9:b0:72b:30e5:f1bc with SMTP id hz9-20020a1709072ce900b0072b30e5f1bcmr3616076ejc.127.1657719830842; Wed, 13 Jul 2022 06:43:50 -0700 (PDT) Received: from debianHome.localdomain (dynamic-095-116-083-213.95.116.pool.telefonica.de. [95.116.83.213]) by smtp.gmail.com with ESMTPSA id g18-20020a170906539200b00722fc0779e3sm4973763ejo.85.2022.07.13.06.43.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 06:43:50 -0700 (PDT) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [PATCH 3/3] libsepol: enclose macro parameters and replacement lists in parentheses Date: Wed, 13 Jul 2022 15:43:43 +0200 Message-Id: <20220713134343.19811-3-cgzones@googlemail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220713134343.19811-1-cgzones@googlemail.com> References: <20220713134343.19811-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/include/sepol/errcodes.h | 13 ++++++------- libsepol/include/sepol/policydb/policydb.h | 10 +++++----- libsepol/src/kernel_to_cil.c | 2 +- libsepol/src/module_to_cil.c | 2 +- libsepol/src/util.c | 2 +- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/libsepol/include/sepol/errcodes.h b/libsepol/include/sepol/errcodes.h index 6e9ff316..e5fe71e3 100644 --- a/libsepol/include/sepol/errcodes.h +++ b/libsepol/include/sepol/errcodes.h @@ -16,15 +16,14 @@ extern "C" { * codes that don't map to system error codes should be defined * outside of the range of system error codes. */ -#define SEPOL_ERR -1 -#define SEPOL_ENOTSUP -2 /* feature not supported in module language */ -#define SEPOL_EREQ -3 /* requirements not met */ +#define SEPOL_ERR (-1) +#define SEPOL_ENOTSUP (-2) /* feature not supported in module language */ +#define SEPOL_EREQ (-3) /* requirements not met */ /* Error codes that map to system error codes */ -#define SEPOL_ENOMEM -ENOMEM -#define SEPOL_ERANGE -ERANGE -#define SEPOL_EEXIST -EEXIST -#define SEPOL_ENOENT -ENOENT +#define SEPOL_ENOMEM (-ENOMEM) +#define SEPOL_EEXIST (-EEXIST) +#define SEPOL_ENOENT (-ENOENT) #ifdef __cplusplus } diff --git a/libsepol/include/sepol/policydb/policydb.h b/libsepol/include/sepol/policydb/policydb.h index de0068a6..ef1a014a 100644 --- a/libsepol/include/sepol/policydb/policydb.h +++ b/libsepol/include/sepol/policydb/policydb.h @@ -251,9 +251,9 @@ typedef struct class_perm_node { struct class_perm_node *next; } class_perm_node_t; -#define xperm_test(x, p) (UINT32_C(1) & (p[x >> 5] >> (x & 0x1f))) -#define xperm_set(x, p) (p[x >> 5] |= (UINT32_C(1) << (x & 0x1f))) -#define xperm_clear(x, p) (p[x >> 5] &= ~(UINT32_C(1) << (x & 0x1f))) +#define xperm_test(x, p) (UINT32_C(1) & ((p)[(x) >> 5] >> ((x) & 0x1f))) +#define xperm_set(x, p) ((p)[(x) >> 5] |= (UINT32_C(1) << ((x) & 0x1f))) +#define xperm_clear(x, p) ((p)[(x) >> 5] &= ~(UINT32_C(1) << ((x) & 0x1f))) #define EXTENDED_PERMS_LEN 8 typedef struct av_extended_perms { @@ -795,9 +795,9 @@ extern int policydb_set_target_platform(policydb_t *p, int platform); #define policydb_has_boundary_feature(p) \ (((p)->policy_type == POLICY_KERN \ - && p->policyvers >= POLICYDB_VERSION_BOUNDARY) || \ + && (p)->policyvers >= POLICYDB_VERSION_BOUNDARY) || \ ((p)->policy_type != POLICY_KERN \ - && p->policyvers >= MOD_POLICYDB_VERSION_BOUNDARY)) + && (p)->policyvers >= MOD_POLICYDB_VERSION_BOUNDARY)) /* the config flags related to unknown classes/perms are bits 2 and 3 */ #define DENY_UNKNOWN SEPOL_DENY_UNKNOWN diff --git a/libsepol/src/kernel_to_cil.c b/libsepol/src/kernel_to_cil.c index 9128ac55..5a1336a3 100644 --- a/libsepol/src/kernel_to_cil.c +++ b/libsepol/src/kernel_to_cil.c @@ -1626,7 +1626,7 @@ exit: return rc; } -#define next_bit_in_range(i, p) ((i + 1 < sizeof(p)*8) && xperm_test((i + 1), p)) +#define next_bit_in_range(i, p) (((i) + 1 < sizeof(p)*8) && xperm_test(((i) + 1), p)) static char *xperms_to_str(avtab_extended_perms_t *xperms) { diff --git a/libsepol/src/module_to_cil.c b/libsepol/src/module_to_cil.c index b35bf055..b900290a 100644 --- a/libsepol/src/module_to_cil.c +++ b/libsepol/src/module_to_cil.c @@ -624,7 +624,7 @@ exit: return rc; } -#define next_bit_in_range(i, p) ((i + 1 < sizeof(p)*8) && xperm_test((i + 1), p)) +#define next_bit_in_range(i, p) (((i) + 1 < sizeof(p)*8) && xperm_test(((i) + 1), p)) static int xperms_to_cil(const av_extended_perms_t *xperms) { diff --git a/libsepol/src/util.c b/libsepol/src/util.c index 1cd1308d..0a2edc85 100644 --- a/libsepol/src/util.c +++ b/libsepol/src/util.c @@ -124,7 +124,7 @@ char *sepol_av_to_string(policydb_t * policydbp, uint32_t tclass, return avbuf; } -#define next_bit_in_range(i, p) ((i + 1 < sizeof(p)*8) && xperm_test((i + 1), p)) +#define next_bit_in_range(i, p) (((i) + 1 < sizeof(p)*8) && xperm_test(((i) + 1), p)) char *sepol_extended_perms_to_string(avtab_extended_perms_t *xperms) {