From patchwork Mon Aug 7 17:11:37 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: 132296 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1606243vqr; Mon, 7 Aug 2023 10:38:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFpRJdKNO56m1bwqmTxGzTy/nqkgvw6eD8okESinUsPrFyqbfbmaY+N0Pp0o/BahUC0U+9A X-Received: by 2002:a17:902:ecc5:b0:1b0:307c:e6fe with SMTP id a5-20020a170902ecc500b001b0307ce6femr9773425plh.10.1691429936366; Mon, 07 Aug 2023 10:38:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691429936; cv=none; d=google.com; s=arc-20160816; b=AcrVFT9WI/4NdfCcvYgXt6eFUti3bL8UFbUhJclDQ58NqZHZER/sOgLYjQ8UswPF5D x94fewe5meTo0gq+5KdtJHkLObW1L8QqtxNOKTQooKK9RvNe4ZTtkvF9nmDOr7ufwvfr wzMNxVS/gBIiN1i30g4O4nDMC3fNuZi+GLgd4VNJJi7X5UKfIP5/jGT3PRfwDpjQq+/U 6YrDxB5Ys/7IKJ4kH7Rp6jWbw4FTI+4h3lrjfc0Rk9ZtJjo9J28ygELe2bzwtFtGaX02 Qk4jLCkU8RbLIbmQgxc65PQXIBdjKWKGu7Z3/qe5RBjq1d479jCpHpCW4axGBQq5g5v0 CKcw== 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=DciKbSFWjq2a4hr5WGLiRBew39Nly0oMydCVVcPx1pg=; fh=fBY5D/IDrKFsN9mMQMRE3IlhWmhEeMbp24YlZR3fWbQ=; b=TO3wpSfgcDBbXOJNZwukCgiQcyadRqI5zfq6VOX/joxjyZvknW0bvErhcdufQ+95fu AtlAynF1oNAKXAd7YaPFxX7dOOLlEN/SVPpvPuH/rcVfMchV9ExYXVbbO8KTaV3jcz/m JGjuEtOOzG86nqqDd6079KmO/lq9gmKH8fkUzLbyvNpqkStpeUwGqfRPrVQGzglOjCZ9 2J0gOc4n7MRZGz3y97KSlfLM//9cw8WoCBFTYdWUxyZ3bFfPpbsmPthmA4iZyVK/p7fL R7HQLzx8TYPmZsyFhYTCFwdUGNgGJkCWDC9OSP/UiCS6I3XfBKwoV9hfssJWU1Bn++QX Iu0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@googlemail.com header.s=20221208 header.b=niNzslaP; 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 ky16-20020a170902f99000b001bbd2599ac7si5901097plb.53.2023.08.07.10.38.41; Mon, 07 Aug 2023 10:38:56 -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=niNzslaP; 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 S231199AbjHGRL6 (ORCPT + 99 others); Mon, 7 Aug 2023 13:11:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230267AbjHGRL5 (ORCPT ); Mon, 7 Aug 2023 13:11:57 -0400 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 B134AB1; Mon, 7 Aug 2023 10:11:54 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-523108efb36so5373265a12.1; Mon, 07 Aug 2023 10:11:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20221208; t=1691428313; x=1692033113; 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=DciKbSFWjq2a4hr5WGLiRBew39Nly0oMydCVVcPx1pg=; b=niNzslaPuqd7b5KcbIfKjJtnuLsnsuv8tUmWZXErPSYM+0cghYrb6PsPGWaXsoTZfa HvRLqZYfWeo+6mPmYKRm/BUGjcxWYp/SMd6RQwFr/K5Lq5Zo3wUOFRwIuJ+z+JYoWmG9 OUyj22fJqir6AXH+A0uAj581d59d+XKDPXa1SLBhV5e1f/tmCAeQ7RDb13QBfiF6poCQ 9KuR3QziNequ0LHYYUJQzF3p2cyP6JoUpPbPtYDig+eCMNFTm62HLnrxzXwAq3Qeje4Q ULkZpnaQoVAeL2sGiMK7E8VpUrPX7GE5hFgJ0npTUtYzTooVzBNTCxUlcNrT8eCEYRLA pmpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691428313; x=1692033113; 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=DciKbSFWjq2a4hr5WGLiRBew39Nly0oMydCVVcPx1pg=; b=TU+eXmr5eEwPoSwuYP01Ou7o/a67b5xCi7crLakIinR9qzuSxhXwB11mndkZHzw8lF EYsMYRDoiSurWZRDVwotmO9dVvS2qIgFEYctl4D94HKBKgKxjDDKGl8BJVoj2zTMdjwQ E5b5otzradPqUg4iPe2UHSpG+pZnIt3K9DM6TPMbfO8jyx3mIffMliYBGAU8rZ+Wsk6q /Txnx5DgXaGZywM+gI9Iedp1ElhkODyhYwhli4oxdvNGWzS5YF/qMRCcHELLsBrVDTX8 JbPZwqiAoxFvWyg7jteSfBS5gDioo8ukfyi5WGsiMmqK5mC1HHJZYljH6EHYgNEeGFmC eBzw== X-Gm-Message-State: AOJu0YxBL5meCtRVq7r2/sEYOAqsfEygR6ywbQuY3+UfeRy8DDRgD6OC ih7zTldA75eJSRl014FJnZBpqFBG3gOxbg== X-Received: by 2002:a05:6402:1059:b0:522:2782:532 with SMTP id e25-20020a056402105900b0052227820532mr7892346edu.30.1691428313067; Mon, 07 Aug 2023 10:11:53 -0700 (PDT) Received: from debian_development.DebianHome (dynamic-095-112-033-028.95.112.pool.telefonica.de. [95.112.33.28]) by smtp.gmail.com with ESMTPSA id e10-20020a056402148a00b005224d960e66sm5420814edv.96.2023.08.07.10.11.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 10:11:52 -0700 (PDT) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Cc: Paul Moore , Stephen Smalley , Eric Paris , Ondrej Mosnacek , "GONG, Ruiqi" , linux-kernel@vger.kernel.org Subject: [PATCH v3 3/7] selinux: update type for number of class permissions in services code Date: Mon, 7 Aug 2023 19:11:37 +0200 Message-Id: <20230807171143.208481-2-cgzones@googlemail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230807171143.208481-1-cgzones@googlemail.com> References: <20230807171143.208481-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_BLOCKED,SPF_HELO_NONE,SPF_PASS 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: INBOX X-GMAIL-THRID: 1773592837143781950 X-GMAIL-MSGID: 1773592837143781950 Security classes have only up to 32 permissions, hence using an u16 is sufficient (while improving padding in struct selinux_mapping). Signed-off-by: Christian Göttsche --- v3: - drop type change of arithmetic variable; it might effect performance as suggested by David. - split bogus and corrected cast into separate patch v2: update commit description: - mention struct selinux_mapping in the padding argument (currently between the first and second member there are 2 bytes padding) - mention overflow in the cast argument and the result of setting no bits due to it --- security/selinux/ss/services.c | 2 +- security/selinux/ss/services.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c index 3ec0bb39c234..dacec2ebdcd7 100644 --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c @@ -97,7 +97,6 @@ static int selinux_set_mapping(struct policydb *pol, struct selinux_map *out_map) { u16 i, j; - unsigned k; bool print_unknown_handle = false; /* Find number of classes in the input mapping */ @@ -117,6 +116,7 @@ static int selinux_set_mapping(struct policydb *pol, while (map[j].name) { const struct security_class_mapping *p_in = map + (j++); struct selinux_mapping *p_out = out_map->mapping + j; + u16 k; /* An empty class string skips ahead */ if (!strcmp(p_in->name, "")) { diff --git a/security/selinux/ss/services.h b/security/selinux/ss/services.h index ed2ee6600467..d24b0a3d198e 100644 --- a/security/selinux/ss/services.h +++ b/security/selinux/ss/services.h @@ -12,7 +12,7 @@ /* Mapping for a single class */ struct selinux_mapping { u16 value; /* policy value for class */ - unsigned int num_perms; /* number of permissions in class */ + u16 num_perms; /* number of permissions in class */ u32 perms[sizeof(u32) * 8]; /* policy values for permissions */ };