From patchwork Thu Jul 6 13:23:34 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: 116726 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp2575499vqx; Thu, 6 Jul 2023 06:52:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlEl9r7hKQVZ5QZJL4P6BooXk8CJym3XdCoX3FhXPzgrsICMScKNJi81Q95y23xY6HmZeMli X-Received: by 2002:a17:90a:eb08:b0:263:856:fcdf with SMTP id j8-20020a17090aeb0800b002630856fcdfmr1439137pjz.12.1688651529232; Thu, 06 Jul 2023 06:52:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688651529; cv=none; d=google.com; s=arc-20160816; b=axaphehPF3mRFIpUil0YgavkJoS7vvzFQfILnJ/NQswLcjMpzOW91lCVBU2Tu0lB88 ZZcZuloEQwS3qJ0PAx4ufLaUyNuh2bm1zZCETIvOY4apqWLG7/zZ28DYJTgUwkBzK8ZJ ShZwrO4dkvAkbiIVT+NLBj2tGWidKJKcjWth25uHjaWdLh9BwFBPOUG2g3w+qJbD9oZ/ My4KurAd9AgO4KeQycdZCNMgMqpbifdRYjv0nFZXOn2+4nCCHDXLtqqvoLBYkUGvrwrC vu00YF9vd2yiY7ae8KWK4GnQGe3PBj/H2V7plntIrhA+AbhiV9TUGLXPvWM/8TJnJRyp h2dA== 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=nn4pFvZABfTjKU9YrTeBoguU9feOF4gfW94L1p7i5hU=; fh=MhpIefJbjj5uiYoGxdoCmbUnLbTqzWkmo44G3Q/36Z4=; b=U4fipT06LaAvMbrrYK757U5g/2s/4UAZRqXlCLtPmlNxFTUbXcXKY6s+c/4eDOUzCj RjXOEAlMkWmk4qNuPOHzrMUqO2Bi7sBk6zTs1jPEmkzePWEQ7fcOr0hQqoHnxxzx+ZjT KHqdEUCo/xTNWYCresKtCYLeWT1BybEgyreX9kKxDlcWODB+dWsMb4OM4V+s/LnGhQ6L kHatgWr+zTwfDr4YSgRQjBzZ8b1TJ5eXaPifG1pXUAV9isr34jrd+oQK56bmwnTa1vaN jS0oPNApQj/X5Cp4qqOH/7JOK4CAZlm0C5G/W6TIus2F0zY34FlAKH6uKUh0YySNCZym d3kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@googlemail.com header.s=20221208 header.b=gUiIINml; 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 oc4-20020a17090b1c0400b00262fba8f808si1732846pjb.108.2023.07.06.06.51.56; Thu, 06 Jul 2023 06:52:09 -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=gUiIINml; 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 S231508AbjGFNYz (ORCPT + 99 others); Thu, 6 Jul 2023 09:24:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232369AbjGFNY1 (ORCPT ); Thu, 6 Jul 2023 09:24:27 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1F3E1FF5; Thu, 6 Jul 2023 06:24:05 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2b5c231c23aso10477831fa.0; Thu, 06 Jul 2023 06:24:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20221208; t=1688649844; x=1691241844; 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=nn4pFvZABfTjKU9YrTeBoguU9feOF4gfW94L1p7i5hU=; b=gUiIINmlSl//9me/XihypS9ph/uurS7b+gobd0svEUr+LMeWisf6Xoxe805QzCKoMm H5inKyTFnh6rEOLylIuyLTm5bgW0tmAMjrVHfvxrX3S/oKyvewXnZfnhWXgbCMFohjbM rILBvZIgaNNGvv9ZqY8GM3gpSnhPLCG5LegeNH86S+or2cOJmNpl0dHUFwSOWr2LLxaq aMTIW4XzZpfD6U0pwnOVqU5HFw8BWfE4zyoq/60ARR1OPLmz9XpdxBljTdxGDPngMEsB KRJVP33Y9Arh0i4QM7LkD9O8BPMtTsst1RfWxUMLWkLIyVvpbuKSmoFxmGKLR+lzX0e2 2dMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688649844; x=1691241844; 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=nn4pFvZABfTjKU9YrTeBoguU9feOF4gfW94L1p7i5hU=; b=VWMox+U45fTpK62uqUGEsgfNo8ciU3oVYT7ogVFQkuT/Vglngqak38x9FdeUSxI9MK a52hCccaL7xSJ+X24l+XGld0g+BcJyiRWCxkaMinZtpU8gvj1PvExGok/+Cuyt/eeOUi 4mvBagJlQawkcLWwV1VX3+S4Cgw+knHB+4BHeWJxvtoR/K4HFx/7m0sZh13lxlkn+YWv GSlXhDiiTj+/KA7+i2wpuED6j7ZW7h0f+o34ezzYxqeT1Nj1t+xxc5GQkIVzx8K0OiSA JcJEYlF6ybDgaYc5JTTpP+P0UtYxarS8uUoB+5gTRaHizEtiCpYX7ufWLlF47sHcGfkW 4mfw== X-Gm-Message-State: ABy/qLaxcAjLLKfOMEt39tv3O1j0+cnCX5CM2qMi9x9HS0WWIG6JQsKm 2eqweVEh8+LSgFh40/voDlJvqD429aPkWcV+ X-Received: by 2002:a2e:8210:0:b0:2b6:ece0:a3c1 with SMTP id w16-20020a2e8210000000b002b6ece0a3c1mr1365397ljg.35.1688649843757; Thu, 06 Jul 2023 06:24:03 -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.24.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 06:24:03 -0700 (PDT) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Cc: Paul Moore , Stephen Smalley , Eric Paris , Ondrej Mosnacek , Xiu Jianfeng , linux-kernel@vger.kernel.org Subject: [RFC PATCH 19/20] selinux: status: avoid implicit conversions regarding enforcing status Date: Thu, 6 Jul 2023 15:23:34 +0200 Message-Id: <20230706132337.15924-19-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?1770679465748606518?= X-GMAIL-MSGID: =?utf-8?q?1770679465748606518?= Use the type bool as parameter type in selinux_status_update_setenforce(). The related function enforcing_enabled() returns the type bool, while the struct selinux_kernel_status member enforcing uses an u32. Signed-off-by: Christian Göttsche --- security/selinux/include/security.h | 2 +- security/selinux/selinuxfs.c | 7 ++++--- security/selinux/status.c | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/security/selinux/include/security.h b/security/selinux/include/security.h index a16c52d553e1..d0837efde62b 100644 --- a/security/selinux/include/security.h +++ b/security/selinux/include/security.h @@ -375,7 +375,7 @@ struct selinux_kernel_status { */ } __packed; -extern void selinux_status_update_setenforce(int enforcing); +extern void selinux_status_update_setenforce(bool enforcing); extern void selinux_status_update_policyload(u32 seqno); extern void selinux_complete_init(void); extern struct path selinux_null; diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c index c3ac0468f698..88d856f5c6bc 100644 --- a/security/selinux/selinuxfs.c +++ b/security/selinux/selinuxfs.c @@ -137,7 +137,8 @@ static ssize_t sel_write_enforce(struct file *file, const char __user *buf, { char *page = NULL; ssize_t length; - int old_value, new_value; + int scan_value; + bool old_value, new_value; if (count >= PAGE_SIZE) return -ENOMEM; @@ -151,10 +152,10 @@ static ssize_t sel_write_enforce(struct file *file, const char __user *buf, return PTR_ERR(page); length = -EINVAL; - if (sscanf(page, "%d", &new_value) != 1) + if (sscanf(page, "%d", &scan_value) != 1) goto out; - new_value = !!new_value; + new_value = !!scan_value; old_value = enforcing_enabled(); if (new_value != old_value) { diff --git a/security/selinux/status.c b/security/selinux/status.c index e436e4975adc..dffca22ce6f7 100644 --- a/security/selinux/status.c +++ b/security/selinux/status.c @@ -76,7 +76,7 @@ struct page *selinux_kernel_status_page(void) * * It updates status of the current enforcing/permissive mode. */ -void selinux_status_update_setenforce(int enforcing) +void selinux_status_update_setenforce(bool enforcing) { struct selinux_kernel_status *status; @@ -87,7 +87,7 @@ void selinux_status_update_setenforce(int enforcing) status->sequence++; smp_wmb(); - status->enforcing = enforcing; + status->enforcing = enforcing ? 1 : 0; smp_wmb(); status->sequence++;