From patchwork Thu Jul 6 13:23:21 2023 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: 116704 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp2559122vqx; Thu, 6 Jul 2023 06:25:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlFz2E0Gq2W7SXHDxLE5F43hyzEJzB6IrA2Mpxb1hBECKj9Z7biBcWL84sj1Mpg0LTxm53lD X-Received: by 2002:a17:90a:bd0d:b0:263:ff36:3aa0 with SMTP id y13-20020a17090abd0d00b00263ff363aa0mr1541259pjr.41.1688649929574; Thu, 06 Jul 2023 06:25:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688649929; cv=none; d=google.com; s=arc-20160816; b=pMRm/6FtLL8S5PI4adBe1ZM51Bj95vRmReEJIoDMU5wQXlOYuf9RpQ7e8YApggVlrZ 7rRrqxv5uHxCGT9RLQwoK4CIE8ON+Hhv84EQTtzMOfSyJNOIPqGJU0vFiK6VuCxVFH2e X6Rv7M3JguSoxHkhW4HdKgP21tWROV2c6xC/NycD6jlJBi1tcC+uZA1l/q2AV+B+lgP/ 8+B/FaGHRO51CNfv0xy4QBqP40SJW84V3slgw79kTqIjFRxZLypgbzH9R4b4sg+6CoH5 i+oT4egt7uRbytG+Rb7Ei+eVV3gGHoPkXuGu+aotOTqPGfDt0QN9LZdPZW4lHmSg9ow4 2fbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fjeU+oFwnLoTGw/GiFQxSoA+QryPefibnYvK0tDSOi0=; fh=QKur2PFwoLuCt27JzfZM4LabS9ldoGoSAJNPH9t/KWI=; b=DdepcyI/5i4SAg+kMwLiaaOWmitQnShNmwkceyDWAegNolagNHP6tbp2ry2q4g4otT U0kcFoIcTwvshiorPmAR7mKQqLebv1cHEa7pV/XPrzqpDDQTtEN1+cQysCqaCqzysK2M HIuCJqcgsVMMAJP9FJF1csysJ8M1cAwVajGHH+/D/WgPgsdEhQ8EO9UIjpBTDMAGiQY3 w/btqmgb83llxTjp3pQCLthmPIgDQiIEG5dxNVitHo/ahDvq09Vupb2CPO94Pc9O3/xV hAu0YJ7pA0Cdm6w9bjlwvtXSBM1FZYM/sPaNOabSRSUpw7TKRPn6JEQtoa2Yp0IQRLve 8k7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@googlemail.com header.s=20221208 header.b=MqKQaLP1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gd14-20020a17090b0fce00b00263aff4ccf0si1603117pjb.3.2023.07.06.06.25.14; Thu, 06 Jul 2023 06:25:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@googlemail.com header.s=20221208 header.b=MqKQaLP1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232364AbjGFNYE (ORCPT + 99 others); Thu, 6 Jul 2023 09:24:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232077AbjGFNXv (ORCPT ); Thu, 6 Jul 2023 09:23:51 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A28B31BC9; Thu, 6 Jul 2023 06:23:50 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-992f6d7c7fbso88722066b.3; Thu, 06 Jul 2023 06:23:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20221208; t=1688649829; x=1691241829; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fjeU+oFwnLoTGw/GiFQxSoA+QryPefibnYvK0tDSOi0=; b=MqKQaLP19EQnZquTr15z2LYEMWk0lbI5ahUOyiCTMkO8YK8LPDbmlgOI1nxf7s91Je iGlcY/sOWLM8xRhikuBOXXIghPJCylRJDoZMIu32VvAgTY86pJgwqEQk3p8fxOObj/7f LvypWTZxm7AJtBNKRR2383uF0sqquAmpMfEfz1wZYdiJuoOTKU+3EzQMgFHD8pX6x4fX /kT1jVDeH85FVHRdN43fwgGmiPS5csGgjmrY6Ji6MlU4CZvjJyDbq3YhD3LWeNVM5MQ5 A6RnA9ztb1WrIgir9cG5fIFtq/o3yHGYCMyRQviIhzKNmMHQ3Q1efnXp1SczW5VkF0Zd 0L2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688649829; x=1691241829; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fjeU+oFwnLoTGw/GiFQxSoA+QryPefibnYvK0tDSOi0=; b=C7tSbsO7jcL70oTkoLLTnxktjQstGKsHbpFOzvpZHDKf+zysijiHXIo4iVXJgGVX0v 0+xUkc1jHajIQVdoKXdhpn1jQUqrB2n40hNl6MdkI+SwtQHCEOZi/XsMPEO7KJGcazZ2 HC1ZoKosY9dMNOS6suaQjx7kLResGJ4n7x41mJvUIC/N5IN9ng9a+bOTFUxfedJwbEDE hS4XeGjLAAeWIvnGTO4XBO9T8e+LecB3u+x4+Z2KlMdbpmm54eOUAwv3eJLM4bx12NB9 nFKywrslIdb2UqZMAZ+Dpw3POPgBVYNbT1VnhuhSY9tGl/xR+23K1aaox/wlsi+3LmOH LUzw== X-Gm-Message-State: ABy/qLaQe8JgYTXc4kLSdtvjbstSFhVmYEZQmMSAGIlkRkOVJRFDWwyb pbOUmepoDz+11mduULLm4FNukVt87iIZDECs X-Received: by 2002:a17:906:6492:b0:992:d013:1130 with SMTP id e18-20020a170906649200b00992d0131130mr1581300ejm.6.1688649829104; Thu, 06 Jul 2023 06:23:49 -0700 (PDT) Received: from debian_development.DebianHome (dynamic-077-008-088-179.77.8.pool.telefonica.de. [77.8.88.179]) by smtp.gmail.com with ESMTPSA id r2-20020a170906364200b00988dbbd1f7esm808024ejb.213.2023.07.06.06.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 06:23:48 -0700 (PDT) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Cc: Paul Moore , Stephen Smalley , Eric Paris , linux-kernel@vger.kernel.org Subject: [RFC PATCH 06/20] selinux: mls: avoid implicit conversions Date: Thu, 6 Jul 2023 15:23:21 +0200 Message-Id: <20230706132337.15924-6-cgzones@googlemail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230706132337.15924-1-cgzones@googlemail.com> References: <20230706132337.15924-1-cgzones@googlemail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770677788583451108?= X-GMAIL-MSGID: =?utf-8?q?1770677788583451108?= Use u32 for ebitmap bits. Use char for the default range of a class. Signed-off-by: Christian Göttsche --- security/selinux/ss/mls.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/security/selinux/ss/mls.c b/security/selinux/ss/mls.c index 99571b19d4a9..1976f6b857e9 100644 --- a/security/selinux/ss/mls.c +++ b/security/selinux/ss/mls.c @@ -45,7 +45,7 @@ int mls_compute_context_len(struct policydb *p, struct context *context) len = 1; /* for the beginning ":" */ for (l = 0; l < 2; l++) { - int index_sens = context->range.level[l].sens; + u32 index_sens = context->range.level[l].sens; len += strlen(sym_name(p, SYM_LEVELS, index_sens - 1)); /* categories */ @@ -240,7 +240,7 @@ int mls_context_to_sid(struct policydb *pol, char *sensitivity, *cur_cat, *next_cat, *rngptr; struct level_datum *levdatum; struct cat_datum *catdatum, *rngdatum; - int l, rc, i; + int l, rc; char *rangep[2]; if (!pol->mls_enabled) { @@ -331,7 +331,7 @@ int mls_context_to_sid(struct policydb *pol, if (catdatum->value >= rngdatum->value) return -EINVAL; - for (i = catdatum->value; i < rngdatum->value; i++) { + for (u32 i = catdatum->value; i < rngdatum->value; i++) { rc = ebitmap_set_bit(&context->range.level[l].cat, i, 1); if (rc) return rc; @@ -451,7 +451,8 @@ int mls_convert_context(struct policydb *oldp, struct level_datum *levdatum; struct cat_datum *catdatum; struct ebitmap_node *node; - int l, i; + u32 i; + int l; if (!oldp->mls_enabled || !newp->mls_enabled) return 0; @@ -495,7 +496,7 @@ int mls_compute_sid(struct policydb *p, struct range_trans rtr; struct mls_range *r; struct class_datum *cladatum; - int default_range = 0; + char default_range = 0; if (!p->mls_enabled) return 0;