From patchwork Thu Jul 6 13:23:35 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: 116715 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp2562471vqx; Thu, 6 Jul 2023 06:30:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlGs0PoaQdTHxq4eojv1eZw8Ik2brF3MCOovlTvcNDbNDywZUpcwP1eP2neAcrSi0Qs7Dc3t X-Received: by 2002:a05:6870:a707:b0:1a3:365:a8c9 with SMTP id g7-20020a056870a70700b001a30365a8c9mr2062846oam.44.1688650248194; Thu, 06 Jul 2023 06:30:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688650248; cv=none; d=google.com; s=arc-20160816; b=YAPvv2fgooQ1gyY1qFw3kCvtNfS+M3j+yGD2AdpxnPLlapDT+x0Evyq1emPhfzAxfu o3F45ZBDhBi1HPrKHjFducySnaLfgC6QodDPTFMIDSLBtAIslgp0Df4TacGbxooJRrd0 jTfVkqGdv2tNRhPt9ObX3FtEPaYXbfylF6rEk0IE55RauYGnRq5xqWLMlkXbXHaBvmK2 /G1ZzbAWkq1lh/9eQYKmUvrjqYbf6RIWtVV49mOk8/EigUrY2GeGKvIEfbtQ1lnf2p3q 8wefXXtI0fNmHKGocpV7Qjqe8+NCTdx2XACcXPrztKuPJajmGAEkwoWqcpKfQhMGmLRj AO7A== 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=PKZMCCQ7wVVZeBi4fnxNrrCgfWKmBY0QQttlYN04RUs=; fh=QKur2PFwoLuCt27JzfZM4LabS9ldoGoSAJNPH9t/KWI=; b=sVtd262y1ktkVFq2is/kj5gqS8UikUQIpU1jfgA/r59Lq1fp5wddwhY+RySuHO3LLJ CNWAilteZcYY5r9wRLLuRj/jVs74lk5sUOGLk1tnE58oJLrL/Yi9G/5kiZpCKn4rH7bY CkwcA7EOXZHSBn05fNYbyJdNF/nA+mY0qC2kwMLN1ToP2WlqEdjVAj7Hdkov3CQQf0ug KgdIz8XucALlovBDQxJ+Ng45Q3H5BzjT3u0MYcRvv9HxmMj44O0iz+t191lP9bOonolc 2blTciDjvWFpKigy11QiwLlrmXQ2xnbX3QIV4xVI95p7U8oRqXr8EMdGDbG5Y3t0C/W7 fEaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@googlemail.com header.s=20221208 header.b=muMEGpAz; 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 pc2-20020a17090b3b8200b0025e9a3124c7si4381672pjb.143.2023.07.06.06.30.32; Thu, 06 Jul 2023 06:30:48 -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=muMEGpAz; 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 S232369AbjGFNY7 (ORCPT + 99 others); Thu, 6 Jul 2023 09:24:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232477AbjGFNY1 (ORCPT ); Thu, 6 Jul 2023 09:24:27 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4816D1FFA; Thu, 6 Jul 2023 06:24:06 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-9741caaf9d4so80309866b.0; Thu, 06 Jul 2023 06:24:06 -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=PKZMCCQ7wVVZeBi4fnxNrrCgfWKmBY0QQttlYN04RUs=; b=muMEGpAzBHoY1MUttdjulommg6urYMBgqAf79lMnKAkKiLzwVe8gSTZQ9T/xHy04ZV 9hg+R5svbXxS3mCWeU+qFOrB+knC7NugjL8h5lNJv3ApRtujq9SNzam0CiOmapqlJj5H cPSDQOn1VanGnQEwDtu3z92yA30uD+fryYr7sMce4KVF2KK4te5NqVXCs5qoYitIJKXR lXCOAVmr/sMlosDCDntFJEDuJUJHRDDvs6qVEiRBBuiMfhJml818V4oJSbvQcuLznkz8 m8qkeKKbBfFAj2/71tqIwx9ABUTOWLOX191nLz1wsyyRT3jQFsy0+s05QFFA5KoI6BCm HerA== 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=PKZMCCQ7wVVZeBi4fnxNrrCgfWKmBY0QQttlYN04RUs=; b=emcbEmzGA4LGmi+S1u0GXOqjaW42ThHa05udoUT0n7PGEco/uu1B3u2oifcDKVUElR 98l6H19QIV2qHI23YykiGOgHzJBpZn96QI2it8jfEB1zsvK7koURcvc6IVjASpBNeXih znussI0X3VZsO/CO4cpkqZCBw+fWo40XO1PMbeGqrfW8o/P2GyR+KX6f3PtELuVtT7Sf 6kSjJcpl56AbClFiOmMzCG4eDDawTalxLRFJWN43HJiAjx/DtKl9mqAMYVsmHNFk/yFk KdsqpbpMTOYIDcO6dha8SY5QYVUEjmdiqK6s1lqOG51bZlrBuwE3lpbGUyVfqiSbO58V PXuw== X-Gm-Message-State: ABy/qLYsfXiRGJszNVBhUeXXFBSBYMO5b5kUsH4lFBK8HxOZBVpweklr bxZsEvlwrAvKUCYmlSUuhgGzhwK3gLjXTfBZ X-Received: by 2002:a17:906:7e11:b0:988:699d:64d0 with SMTP id e17-20020a1709067e1100b00988699d64d0mr1759883ejr.32.1688649844399; Thu, 06 Jul 2023 06:24:04 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 06:24:04 -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 20/20] selinux: selinuxfs: avoid implicit conversions Date: Thu, 6 Jul 2023 15:23:35 +0200 Message-Id: <20230706132337.15924-20-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?1770677804925393678?= X-GMAIL-MSGID: =?utf-8?q?1770678122269424992?= Use unsigned loop counters where the upper bound is of unsigned type. Signed-off-by: Christian Göttsche --- security/selinux/selinuxfs.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c index 88d856f5c6bc..a2dc415779ae 100644 --- a/security/selinux/selinuxfs.c +++ b/security/selinux/selinuxfs.c @@ -1074,7 +1074,7 @@ static ssize_t sel_write_user(struct file *file, char *buf, size_t size) u32 sid, *sids = NULL; ssize_t length; char *newcon; - int i, rc; + int rc; u32 len, nsids; length = avc_has_perm(current_sid(), SECINITSID_SECURITY, @@ -1107,7 +1107,7 @@ static ssize_t sel_write_user(struct file *file, char *buf, size_t size) length = sprintf(buf, "%u", nsids) + 1; ptr = buf + length; - for (i = 0; i < nsids; i++) { + for (u32 i = 0; i < nsids; i++) { rc = security_sid_to_context(sids[i], &newcon, &len); if (rc) { length = rc; @@ -1612,7 +1612,6 @@ static int sel_make_avc_files(struct dentry *dir) { struct super_block *sb = dir->d_sb; struct selinux_fs_info *fsi = sb->s_fs_info; - int i; static const struct tree_descr files[] = { { "cache_threshold", &sel_avc_cache_threshold_ops, S_IRUGO|S_IWUSR }, @@ -1622,7 +1621,7 @@ static int sel_make_avc_files(struct dentry *dir) #endif }; - for (i = 0; i < ARRAY_SIZE(files); i++) { + for (u32 i = 0; i < ARRAY_SIZE(files); i++) { struct inode *inode; struct dentry *dentry; @@ -1648,12 +1647,11 @@ static int sel_make_ss_files(struct dentry *dir) { struct super_block *sb = dir->d_sb; struct selinux_fs_info *fsi = sb->s_fs_info; - int i; static const struct tree_descr files[] = { { "sidtab_hash_stats", &sel_sidtab_hash_stats_ops, S_IRUGO }, }; - for (i = 0; i < ARRAY_SIZE(files); i++) { + for (u32 i = 0; i < ARRAY_SIZE(files); i++) { struct inode *inode; struct dentry *dentry; @@ -1699,9 +1697,7 @@ static const struct file_operations sel_initcon_ops = { static int sel_make_initcon_files(struct dentry *dir) { - int i; - - for (i = 1; i <= SECINITSID_NUM; i++) { + for (u32 i = 1; i <= SECINITSID_NUM; i++) { struct inode *inode; struct dentry *dentry; const char *s = security_get_initial_sid_context(i);