1

selinux: fix style issues in security/selinux/ss/mls.c

As part of on ongoing effort to perform more automated testing and
provide more tools for individual developers to validate their
patches before submitting, we are trying to make our code
"clang-format clean".  My hope is that once we have fixed all of our
style "quirks", developers will be able to run clang-format on their
patches to help avoid silly formatting problems and ensure their
changes fit in well with the rest of the SELinux kernel code.

Signed-off-by: Paul Moore <paul@paul-moore.com>
This commit is contained in:
Paul Moore 2024-02-22 18:52:31 -05:00
parent 470948bc2d
commit 4afec3607b

View File

@ -4,19 +4,15 @@
* *
* Author : Stephen Smalley, <stephen.smalley.work@gmail.com> * Author : Stephen Smalley, <stephen.smalley.work@gmail.com>
*/ */
/* /*
* Updated: Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com> * Updated: Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com>
* Support for enhanced MLS infrastructure.
* Copyright (C) 2004-2006 Trusted Computer Solutions, Inc.
* *
* Support for enhanced MLS infrastructure.
*
* Copyright (C) 2004-2006 Trusted Computer Solutions, Inc.
*/
/*
* Updated: Hewlett-Packard <paul@paul-moore.com> * Updated: Hewlett-Packard <paul@paul-moore.com>
* * Added support to import/export the MLS label from NetLabel
* Added support to import/export the MLS label from NetLabel * Copyright (C) Hewlett-Packard Development Company, L.P., 2006
*
* (c) Copyright Hewlett-Packard Development Company, L.P., 2006
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>
@ -52,7 +48,8 @@ int mls_compute_context_len(struct policydb *p, struct context *context)
head = -2; head = -2;
prev = -2; prev = -2;
e = &context->range.level[l].cat; e = &context->range.level[l].cat;
ebitmap_for_each_positive_bit(e, node, i) { ebitmap_for_each_positive_bit(e, node, i)
{
if (i - prev > 1) { if (i - prev > 1) {
/* one or more negative bits are skipped */ /* one or more negative bits are skipped */
if (head != prev) { if (head != prev) {
@ -86,8 +83,7 @@ int mls_compute_context_len(struct policydb *p, struct context *context)
* the MLS fields of `context' into the string `*scontext'. * the MLS fields of `context' into the string `*scontext'.
* Update `*scontext' to point to the end of the MLS fields. * Update `*scontext' to point to the end of the MLS fields.
*/ */
void mls_sid_to_context(struct policydb *p, void mls_sid_to_context(struct policydb *p, struct context *context,
struct context *context,
char **scontext) char **scontext)
{ {
char *scontextp, *nm; char *scontextp, *nm;
@ -112,7 +108,8 @@ void mls_sid_to_context(struct policydb *p,
head = -2; head = -2;
prev = -2; prev = -2;
e = &context->range.level[l].cat; e = &context->range.level[l].cat;
ebitmap_for_each_positive_bit(e, node, i) { ebitmap_for_each_positive_bit(e, node, i)
{
if (i - prev > 1) { if (i - prev > 1) {
/* one or more negative bits are skipped */ /* one or more negative bits are skipped */
if (prev != head) { if (prev != head) {
@ -230,12 +227,8 @@ int mls_context_isvalid(struct policydb *p, struct context *c)
* Policy read-lock must be held for sidtab lookup. * Policy read-lock must be held for sidtab lookup.
* *
*/ */
int mls_context_to_sid(struct policydb *pol, int mls_context_to_sid(struct policydb *pol, char oldc, char *scontext,
char oldc, struct context *context, struct sidtab *s, u32 def_sid)
char *scontext,
struct context *context,
struct sidtab *s,
u32 def_sid)
{ {
char *sensitivity, *cur_cat, *next_cat, *rngptr; char *sensitivity, *cur_cat, *next_cat, *rngptr;
struct level_datum *levdatum; struct level_datum *levdatum;
@ -333,7 +326,8 @@ int mls_context_to_sid(struct policydb *pol,
return -EINVAL; return -EINVAL;
for (i = catdatum->value; i < rngdatum->value; i++) { for (i = catdatum->value; i < rngdatum->value; i++) {
rc = ebitmap_set_bit(&context->range.level[l].cat, i, 1); rc = ebitmap_set_bit(
&context->range.level[l].cat, i, 1);
if (rc) if (rc)
return rc; return rc;
} }
@ -371,8 +365,8 @@ int mls_from_string(struct policydb *p, char *str, struct context *context,
if (!tmpstr) { if (!tmpstr) {
rc = -ENOMEM; rc = -ENOMEM;
} else { } else {
rc = mls_context_to_sid(p, ':', tmpstr, context, rc = mls_context_to_sid(p, ':', tmpstr, context, NULL,
NULL, SECSID_NULL); SECSID_NULL);
kfree(tmpstr); kfree(tmpstr);
} }
@ -382,8 +376,7 @@ int mls_from_string(struct policydb *p, char *str, struct context *context,
/* /*
* Copies the MLS range `range' into `context'. * Copies the MLS range `range' into `context'.
*/ */
int mls_range_set(struct context *context, int mls_range_set(struct context *context, struct mls_range *range)
struct mls_range *range)
{ {
int l, rc = 0; int l, rc = 0;
@ -399,9 +392,8 @@ int mls_range_set(struct context *context,
return rc; return rc;
} }
int mls_setup_user_range(struct policydb *p, int mls_setup_user_range(struct policydb *p, struct context *fromcon,
struct context *fromcon, struct user_datum *user, struct user_datum *user, struct context *usercon)
struct context *usercon)
{ {
if (p->mls_enabled) { if (p->mls_enabled) {
struct mls_level *fromcon_sen = &(fromcon->range.level[0]); struct mls_level *fromcon_sen = &(fromcon->range.level[0]);
@ -444,10 +436,8 @@ int mls_setup_user_range(struct policydb *p,
* policy `oldp' to the values specified in the policy `newp', * policy `oldp' to the values specified in the policy `newp',
* storing the resulting context in `newc'. * storing the resulting context in `newc'.
*/ */
int mls_convert_context(struct policydb *oldp, int mls_convert_context(struct policydb *oldp, struct policydb *newp,
struct policydb *newp, struct context *oldc, struct context *newc)
struct context *oldc,
struct context *newc)
{ {
struct level_datum *levdatum; struct level_datum *levdatum;
struct cat_datum *catdatum; struct cat_datum *catdatum;
@ -468,8 +458,9 @@ int mls_convert_context(struct policydb *oldp,
return -EINVAL; return -EINVAL;
newc->range.level[l].sens = levdatum->level->sens; newc->range.level[l].sens = levdatum->level->sens;
ebitmap_for_each_positive_bit(&oldc->range.level[l].cat, ebitmap_for_each_positive_bit(&oldc->range.level[l].cat, node,
node, i) { i)
{
int rc; int rc;
catdatum = symtab_search(&newp->p_cats, catdatum = symtab_search(&newp->p_cats,
@ -486,13 +477,9 @@ int mls_convert_context(struct policydb *oldp,
return 0; return 0;
} }
int mls_compute_sid(struct policydb *p, int mls_compute_sid(struct policydb *p, struct context *scontext,
struct context *scontext, struct context *tcontext, u16 tclass, u32 specified,
struct context *tcontext, struct context *newcontext, bool sock)
u16 tclass,
u32 specified,
struct context *newcontext,
bool sock)
{ {
struct range_trans rtr; struct range_trans rtr;
struct mls_range *r; struct mls_range *r;
@ -532,8 +519,8 @@ int mls_compute_sid(struct policydb *p,
case DEFAULT_TARGET_LOW_HIGH: case DEFAULT_TARGET_LOW_HIGH:
return mls_context_cpy(newcontext, tcontext); return mls_context_cpy(newcontext, tcontext);
case DEFAULT_GLBLUB: case DEFAULT_GLBLUB:
return mls_context_glblub(newcontext, return mls_context_glblub(newcontext, scontext,
scontext, tcontext); tcontext);
} }
fallthrough; fallthrough;
@ -563,8 +550,7 @@ int mls_compute_sid(struct policydb *p,
* NetLabel MLS sensitivity level field. * NetLabel MLS sensitivity level field.
* *
*/ */
void mls_export_netlbl_lvl(struct policydb *p, void mls_export_netlbl_lvl(struct policydb *p, struct context *context,
struct context *context,
struct netlbl_lsm_secattr *secattr) struct netlbl_lsm_secattr *secattr)
{ {
if (!p->mls_enabled) if (!p->mls_enabled)
@ -585,8 +571,7 @@ void mls_export_netlbl_lvl(struct policydb *p,
* NetLabel MLS sensitivity level into the context. * NetLabel MLS sensitivity level into the context.
* *
*/ */
void mls_import_netlbl_lvl(struct policydb *p, void mls_import_netlbl_lvl(struct policydb *p, struct context *context,
struct context *context,
struct netlbl_lsm_secattr *secattr) struct netlbl_lsm_secattr *secattr)
{ {
if (!p->mls_enabled) if (!p->mls_enabled)
@ -607,8 +592,7 @@ void mls_import_netlbl_lvl(struct policydb *p,
* MLS category field. Returns zero on success, negative values on failure. * MLS category field. Returns zero on success, negative values on failure.
* *
*/ */
int mls_export_netlbl_cat(struct policydb *p, int mls_export_netlbl_cat(struct policydb *p, struct context *context,
struct context *context,
struct netlbl_lsm_secattr *secattr) struct netlbl_lsm_secattr *secattr)
{ {
int rc; int rc;
@ -637,8 +621,7 @@ int mls_export_netlbl_cat(struct policydb *p,
* negative values on failure. * negative values on failure.
* *
*/ */
int mls_import_netlbl_cat(struct policydb *p, int mls_import_netlbl_cat(struct policydb *p, struct context *context,
struct context *context,
struct netlbl_lsm_secattr *secattr) struct netlbl_lsm_secattr *secattr)
{ {
int rc; int rc;