License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Implementation of the multi-level security (MLS) policy.
|
|
|
|
*
|
2017-08-18 01:32:36 +08:00
|
|
|
* Author : Stephen Smalley, <sds@tycho.nsa.gov>
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Updated: Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com>
|
|
|
|
*
|
|
|
|
* Support for enhanced MLS infrastructure.
|
|
|
|
*
|
2006-02-25 05:44:05 +08:00
|
|
|
* Copyright (C) 2004-2006 Trusted Computer Solutions, Inc.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2006-08-05 14:17:57 +08:00
|
|
|
/*
|
2011-08-01 19:10:33 +08:00
|
|
|
* Updated: Hewlett-Packard <paul@paul-moore.com>
|
2006-08-05 14:17:57 +08:00
|
|
|
*
|
2006-11-30 02:18:18 +08:00
|
|
|
* Added support to import/export the MLS label from NetLabel
|
2006-08-05 14:17:57 +08:00
|
|
|
*
|
|
|
|
* (c) Copyright Hewlett-Packard Development Company, L.P., 2006
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/errno.h>
|
2006-11-30 02:18:18 +08:00
|
|
|
#include <net/netlabel.h>
|
2005-07-28 16:07:37 +08:00
|
|
|
#include "sidtab.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "mls.h"
|
|
|
|
#include "policydb.h"
|
|
|
|
#include "services.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the length in bytes for the MLS fields of the
|
|
|
|
* security context string representation of `context'.
|
|
|
|
*/
|
2018-03-02 07:48:02 +08:00
|
|
|
int mls_compute_context_len(struct policydb *p, struct context *context)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-29 01:20:55 +08:00
|
|
|
int i, l, len, head, prev;
|
|
|
|
char *nm;
|
|
|
|
struct ebitmap *e;
|
2005-09-04 06:55:16 +08:00
|
|
|
struct ebitmap_node *node;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-03-02 07:48:02 +08:00
|
|
|
if (!p->mls_enabled)
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
len = 1; /* for the beginning ":" */
|
|
|
|
for (l = 0; l < 2; l++) {
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-29 01:20:55 +08:00
|
|
|
int index_sens = context->range.level[l].sens;
|
2018-03-02 07:48:02 +08:00
|
|
|
len += strlen(sym_name(p, SYM_LEVELS, index_sens - 1));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-29 01:20:55 +08:00
|
|
|
/* categories */
|
|
|
|
head = -2;
|
|
|
|
prev = -2;
|
|
|
|
e = &context->range.level[l].cat;
|
|
|
|
ebitmap_for_each_positive_bit(e, node, i) {
|
|
|
|
if (i - prev > 1) {
|
|
|
|
/* one or more negative bits are skipped */
|
|
|
|
if (head != prev) {
|
2018-03-02 07:48:02 +08:00
|
|
|
nm = sym_name(p, SYM_CATS, prev);
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-29 01:20:55 +08:00
|
|
|
len += strlen(nm) + 1;
|
|
|
|
}
|
2018-03-02 07:48:02 +08:00
|
|
|
nm = sym_name(p, SYM_CATS, i);
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-29 01:20:55 +08:00
|
|
|
len += strlen(nm) + 1;
|
|
|
|
head = i;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-29 01:20:55 +08:00
|
|
|
prev = i;
|
|
|
|
}
|
|
|
|
if (prev != head) {
|
2018-03-02 07:48:02 +08:00
|
|
|
nm = sym_name(p, SYM_CATS, prev);
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-29 01:20:55 +08:00
|
|
|
len += strlen(nm) + 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
if (l == 0) {
|
|
|
|
if (mls_level_eq(&context->range.level[0],
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-29 01:20:55 +08:00
|
|
|
&context->range.level[1]))
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
else
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the security context string representation of
|
|
|
|
* the MLS fields of `context' into the string `*scontext'.
|
|
|
|
* Update `*scontext' to point to the end of the MLS fields.
|
|
|
|
*/
|
2018-03-02 07:48:02 +08:00
|
|
|
void mls_sid_to_context(struct policydb *p,
|
|
|
|
struct context *context,
|
2008-04-19 05:38:32 +08:00
|
|
|
char **scontext)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-29 01:20:55 +08:00
|
|
|
char *scontextp, *nm;
|
|
|
|
int i, l, head, prev;
|
|
|
|
struct ebitmap *e;
|
2005-09-04 06:55:16 +08:00
|
|
|
struct ebitmap_node *node;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-03-02 07:48:02 +08:00
|
|
|
if (!p->mls_enabled)
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
scontextp = *scontext;
|
|
|
|
|
|
|
|
*scontextp = ':';
|
|
|
|
scontextp++;
|
|
|
|
|
|
|
|
for (l = 0; l < 2; l++) {
|
2018-03-02 07:48:02 +08:00
|
|
|
strcpy(scontextp, sym_name(p, SYM_LEVELS,
|
2010-11-30 04:47:09 +08:00
|
|
|
context->range.level[l].sens - 1));
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-29 01:20:55 +08:00
|
|
|
scontextp += strlen(scontextp);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* categories */
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-29 01:20:55 +08:00
|
|
|
head = -2;
|
|
|
|
prev = -2;
|
|
|
|
e = &context->range.level[l].cat;
|
|
|
|
ebitmap_for_each_positive_bit(e, node, i) {
|
|
|
|
if (i - prev > 1) {
|
|
|
|
/* one or more negative bits are skipped */
|
|
|
|
if (prev != head) {
|
|
|
|
if (prev - head > 1)
|
2005-04-17 06:20:36 +08:00
|
|
|
*scontextp++ = '.';
|
|
|
|
else
|
|
|
|
*scontextp++ = ',';
|
2018-03-02 07:48:02 +08:00
|
|
|
nm = sym_name(p, SYM_CATS, prev);
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-29 01:20:55 +08:00
|
|
|
strcpy(scontextp, nm);
|
|
|
|
scontextp += strlen(nm);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-29 01:20:55 +08:00
|
|
|
if (prev < 0)
|
|
|
|
*scontextp++ = ':';
|
|
|
|
else
|
|
|
|
*scontextp++ = ',';
|
2018-03-02 07:48:02 +08:00
|
|
|
nm = sym_name(p, SYM_CATS, i);
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-29 01:20:55 +08:00
|
|
|
strcpy(scontextp, nm);
|
|
|
|
scontextp += strlen(nm);
|
|
|
|
head = i;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-29 01:20:55 +08:00
|
|
|
prev = i;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-29 01:20:55 +08:00
|
|
|
if (prev != head) {
|
|
|
|
if (prev - head > 1)
|
2005-04-17 06:20:36 +08:00
|
|
|
*scontextp++ = '.';
|
|
|
|
else
|
|
|
|
*scontextp++ = ',';
|
2018-03-02 07:48:02 +08:00
|
|
|
nm = sym_name(p, SYM_CATS, prev);
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-29 01:20:55 +08:00
|
|
|
strcpy(scontextp, nm);
|
|
|
|
scontextp += strlen(nm);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (l == 0) {
|
|
|
|
if (mls_level_eq(&context->range.level[0],
|
2008-04-19 05:38:32 +08:00
|
|
|
&context->range.level[1]))
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-29 01:20:55 +08:00
|
|
|
else
|
|
|
|
*scontextp++ = '-';
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*scontext = scontextp;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-11-07 23:08:00 +08:00
|
|
|
int mls_level_isvalid(struct policydb *p, struct mls_level *l)
|
|
|
|
{
|
|
|
|
struct level_datum *levdatum;
|
|
|
|
|
|
|
|
if (!l->sens || l->sens > p->p_levels.nprim)
|
|
|
|
return 0;
|
2020-04-28 20:55:12 +08:00
|
|
|
levdatum = hashtab_search(&p->p_levels.table,
|
2010-11-30 04:47:09 +08:00
|
|
|
sym_name(p, SYM_LEVELS, l->sens - 1));
|
2007-11-07 23:08:00 +08:00
|
|
|
if (!levdatum)
|
|
|
|
return 0;
|
|
|
|
|
2013-07-24 05:38:41 +08:00
|
|
|
/*
|
|
|
|
* Return 1 iff all the bits set in l->cat are also be set in
|
|
|
|
* levdatum->level->cat and no bit in l->cat is larger than
|
|
|
|
* p->p_cats.nprim.
|
|
|
|
*/
|
|
|
|
return ebitmap_contains(&levdatum->level->cat, &l->cat,
|
|
|
|
p->p_cats.nprim);
|
2007-11-07 23:08:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int mls_range_isvalid(struct policydb *p, struct mls_range *r)
|
|
|
|
{
|
|
|
|
return (mls_level_isvalid(p, &r->level[0]) &&
|
|
|
|
mls_level_isvalid(p, &r->level[1]) &&
|
|
|
|
mls_level_dom(&r->level[1], &r->level[0]));
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Return 1 if the MLS fields in the security context
|
|
|
|
* structure `c' are valid. Return 0 otherwise.
|
|
|
|
*/
|
|
|
|
int mls_context_isvalid(struct policydb *p, struct context *c)
|
|
|
|
{
|
|
|
|
struct user_datum *usrdatum;
|
|
|
|
|
2010-02-03 23:40:20 +08:00
|
|
|
if (!p->mls_enabled)
|
2005-04-17 06:20:36 +08:00
|
|
|
return 1;
|
|
|
|
|
2007-11-07 23:08:00 +08:00
|
|
|
if (!mls_range_isvalid(p, &c->range))
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (c->role == OBJECT_R_VAL)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* User must be authorized for the MLS range.
|
|
|
|
*/
|
|
|
|
if (!c->user || c->user > p->p_users.nprim)
|
|
|
|
return 0;
|
|
|
|
usrdatum = p->user_val_to_struct[c->user - 1];
|
|
|
|
if (!mls_range_contains(usrdatum->range, c->range))
|
|
|
|
return 0; /* user may not be associated with range */
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the MLS fields in the security context structure
|
|
|
|
* `context' based on the string representation in
|
2018-08-07 05:19:32 +08:00
|
|
|
* the string `scontext'.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* This function modifies the string in place, inserting
|
|
|
|
* NULL characters to terminate the MLS fields.
|
2005-07-28 16:07:37 +08:00
|
|
|
*
|
|
|
|
* If a def_sid is provided and no MLS field is present,
|
|
|
|
* copy the MLS field of the associated default context.
|
|
|
|
* Used for upgraded to MLS systems where objects may lack
|
|
|
|
* MLS fields.
|
|
|
|
*
|
|
|
|
* Policy read-lock must be held for sidtab lookup.
|
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2008-05-08 01:03:20 +08:00
|
|
|
int mls_context_to_sid(struct policydb *pol,
|
|
|
|
char oldc,
|
2018-08-07 05:19:32 +08:00
|
|
|
char *scontext,
|
2005-07-28 16:07:37 +08:00
|
|
|
struct context *context,
|
|
|
|
struct sidtab *s,
|
|
|
|
u32 def_sid)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-08-07 05:19:32 +08:00
|
|
|
char *sensitivity, *cur_cat, *next_cat, *rngptr;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct level_datum *levdatum;
|
|
|
|
struct cat_datum *catdatum, *rngdatum;
|
2018-08-07 05:19:32 +08:00
|
|
|
int l, rc, i;
|
|
|
|
char *rangep[2];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-03 23:40:20 +08:00
|
|
|
if (!pol->mls_enabled) {
|
2018-11-14 10:44:33 +08:00
|
|
|
/*
|
|
|
|
* With no MLS, only return -EINVAL if there is a MLS field
|
|
|
|
* and it did not come from an xattr.
|
|
|
|
*/
|
|
|
|
if (oldc && def_sid == SECSID_NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
return 0;
|
2005-11-09 13:34:32 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-07-28 16:07:37 +08:00
|
|
|
/*
|
|
|
|
* No MLS component to the security context, try and map to
|
|
|
|
* default if provided.
|
|
|
|
*/
|
|
|
|
if (!oldc) {
|
|
|
|
struct context *defcon;
|
|
|
|
|
|
|
|
if (def_sid == SECSID_NULL)
|
2018-08-07 05:19:32 +08:00
|
|
|
return -EINVAL;
|
2005-07-28 16:07:37 +08:00
|
|
|
|
|
|
|
defcon = sidtab_search(s, def_sid);
|
|
|
|
if (!defcon)
|
2018-08-07 05:19:32 +08:00
|
|
|
return -EINVAL;
|
2005-07-28 16:07:37 +08:00
|
|
|
|
2018-08-07 05:19:32 +08:00
|
|
|
return mls_context_cpy(context, defcon);
|
2005-07-28 16:07:37 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-08-07 05:19:32 +08:00
|
|
|
/*
|
|
|
|
* If we're dealing with a range, figure out where the two parts
|
|
|
|
* of the range begin.
|
|
|
|
*/
|
|
|
|
rangep[0] = scontext;
|
|
|
|
rangep[1] = strchr(scontext, '-');
|
|
|
|
if (rangep[1]) {
|
|
|
|
rangep[1][0] = '\0';
|
|
|
|
rangep[1]++;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-08-07 05:19:32 +08:00
|
|
|
/* For each part of the range: */
|
2005-04-17 06:20:36 +08:00
|
|
|
for (l = 0; l < 2; l++) {
|
2018-08-07 05:19:32 +08:00
|
|
|
/* Split sensitivity and category set. */
|
|
|
|
sensitivity = rangep[l];
|
|
|
|
if (sensitivity == NULL)
|
|
|
|
break;
|
|
|
|
next_cat = strchr(sensitivity, ':');
|
|
|
|
if (next_cat)
|
|
|
|
*(next_cat++) = '\0';
|
|
|
|
|
|
|
|
/* Parse sensitivity. */
|
2020-04-28 20:55:12 +08:00
|
|
|
levdatum = hashtab_search(&pol->p_levels.table, sensitivity);
|
2018-08-07 05:19:32 +08:00
|
|
|
if (!levdatum)
|
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
context->range.level[l].sens = levdatum->level->sens;
|
|
|
|
|
2018-08-07 05:19:32 +08:00
|
|
|
/* Extract category set. */
|
|
|
|
while (next_cat != NULL) {
|
|
|
|
cur_cat = next_cat;
|
|
|
|
next_cat = strchr(next_cat, ',');
|
|
|
|
if (next_cat != NULL)
|
|
|
|
*(next_cat++) = '\0';
|
|
|
|
|
|
|
|
/* Separate into range if exists */
|
|
|
|
rngptr = strchr(cur_cat, '.');
|
|
|
|
if (rngptr != NULL) {
|
|
|
|
/* Remove '.' */
|
|
|
|
*rngptr++ = '\0';
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2020-04-28 20:55:12 +08:00
|
|
|
catdatum = hashtab_search(&pol->p_cats.table, cur_cat);
|
2018-08-07 05:19:32 +08:00
|
|
|
if (!catdatum)
|
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-08-07 05:19:32 +08:00
|
|
|
rc = ebitmap_set_bit(&context->range.level[l].cat,
|
|
|
|
catdatum->value - 1, 1);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
/* If range, set all categories in range */
|
|
|
|
if (rngptr == NULL)
|
|
|
|
continue;
|
|
|
|
|
2020-04-28 20:55:12 +08:00
|
|
|
rngdatum = hashtab_search(&pol->p_cats.table, rngptr);
|
2018-08-07 05:19:32 +08:00
|
|
|
if (!rngdatum)
|
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-08-07 05:19:32 +08:00
|
|
|
if (catdatum->value >= rngdatum->value)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
for (i = catdatum->value; i < rngdatum->value; i++) {
|
|
|
|
rc = ebitmap_set_bit(&context->range.level[l].cat, i, 1);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 05:19:32 +08:00
|
|
|
/* If we didn't see a '-', the range start is also the range end. */
|
|
|
|
if (rangep[1] == NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
context->range.level[1].sens = context->range.level[0].sens;
|
|
|
|
rc = ebitmap_cpy(&context->range.level[1].cat,
|
|
|
|
&context->range.level[0].cat);
|
|
|
|
if (rc)
|
2018-08-07 05:19:32 +08:00
|
|
|
return rc;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2018-08-07 05:19:32 +08:00
|
|
|
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-02-25 05:44:05 +08:00
|
|
|
/*
|
|
|
|
* Set the MLS fields in the security context structure
|
|
|
|
* `context' based on the string representation in
|
|
|
|
* the string `str'. This function will allocate temporary memory with the
|
|
|
|
* given constraints of gfp_mask.
|
|
|
|
*/
|
2018-03-02 07:48:02 +08:00
|
|
|
int mls_from_string(struct policydb *p, char *str, struct context *context,
|
|
|
|
gfp_t gfp_mask)
|
2006-02-25 05:44:05 +08:00
|
|
|
{
|
2018-08-07 05:19:32 +08:00
|
|
|
char *tmpstr;
|
2006-02-25 05:44:05 +08:00
|
|
|
int rc;
|
|
|
|
|
2018-03-02 07:48:02 +08:00
|
|
|
if (!p->mls_enabled)
|
2006-02-25 05:44:05 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2018-08-07 05:19:32 +08:00
|
|
|
tmpstr = kstrdup(str, gfp_mask);
|
2006-02-25 05:44:05 +08:00
|
|
|
if (!tmpstr) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
} else {
|
2018-08-07 05:19:32 +08:00
|
|
|
rc = mls_context_to_sid(p, ':', tmpstr, context,
|
2008-04-19 05:38:32 +08:00
|
|
|
NULL, SECSID_NULL);
|
2018-08-07 05:19:32 +08:00
|
|
|
kfree(tmpstr);
|
2006-02-25 05:44:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Copies the MLS range `range' into `context'.
|
|
|
|
*/
|
2010-02-03 23:40:20 +08:00
|
|
|
int mls_range_set(struct context *context,
|
2008-04-19 05:38:32 +08:00
|
|
|
struct mls_range *range)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int l, rc = 0;
|
|
|
|
|
|
|
|
/* Copy the MLS range into the context */
|
|
|
|
for (l = 0; l < 2; l++) {
|
|
|
|
context->range.level[l].sens = range->level[l].sens;
|
|
|
|
rc = ebitmap_cpy(&context->range.level[l].cat,
|
|
|
|
&range->level[l].cat);
|
|
|
|
if (rc)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-03-02 07:48:02 +08:00
|
|
|
int mls_setup_user_range(struct policydb *p,
|
|
|
|
struct context *fromcon, struct user_datum *user,
|
2008-04-19 05:38:32 +08:00
|
|
|
struct context *usercon)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-03-02 07:48:02 +08:00
|
|
|
if (p->mls_enabled) {
|
2005-04-17 06:20:36 +08:00
|
|
|
struct mls_level *fromcon_sen = &(fromcon->range.level[0]);
|
|
|
|
struct mls_level *fromcon_clr = &(fromcon->range.level[1]);
|
|
|
|
struct mls_level *user_low = &(user->range.level[0]);
|
|
|
|
struct mls_level *user_clr = &(user->range.level[1]);
|
|
|
|
struct mls_level *user_def = &(user->dfltlevel);
|
|
|
|
struct mls_level *usercon_sen = &(usercon->range.level[0]);
|
|
|
|
struct mls_level *usercon_clr = &(usercon->range.level[1]);
|
|
|
|
|
|
|
|
/* Honor the user's default level if we can */
|
2008-05-14 23:27:45 +08:00
|
|
|
if (mls_level_between(user_def, fromcon_sen, fromcon_clr))
|
2005-04-17 06:20:36 +08:00
|
|
|
*usercon_sen = *user_def;
|
2008-05-14 23:27:45 +08:00
|
|
|
else if (mls_level_between(fromcon_sen, user_def, user_clr))
|
2005-04-17 06:20:36 +08:00
|
|
|
*usercon_sen = *fromcon_sen;
|
2008-05-14 23:27:45 +08:00
|
|
|
else if (mls_level_between(fromcon_clr, user_low, user_def))
|
2005-04-17 06:20:36 +08:00
|
|
|
*usercon_sen = *user_low;
|
2008-05-14 23:27:45 +08:00
|
|
|
else
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Lower the clearance of available contexts
|
|
|
|
if the clearance of "fromcon" is lower than
|
|
|
|
that of the user's default clearance (but
|
|
|
|
only if the "fromcon" clearance dominates
|
|
|
|
the user's computed sensitivity level) */
|
2008-04-19 05:38:32 +08:00
|
|
|
if (mls_level_dom(user_clr, fromcon_clr))
|
2005-04-17 06:20:36 +08:00
|
|
|
*usercon_clr = *fromcon_clr;
|
2008-04-19 05:38:32 +08:00
|
|
|
else if (mls_level_dom(fromcon_clr, user_clr))
|
2005-04-17 06:20:36 +08:00
|
|
|
*usercon_clr = *user_clr;
|
2008-04-19 05:38:32 +08:00
|
|
|
else
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert the MLS fields in the security context
|
selinux: overhaul sidtab to fix bug and improve performance
Before this patch, during a policy reload the sidtab would become frozen
and trying to map a new context to SID would be unable to add a new
entry to sidtab and fail with -ENOMEM.
Such failures are usually propagated into userspace, which has no way of
distignuishing them from actual allocation failures and thus doesn't
handle them gracefully. Such situation can be triggered e.g. by the
following reproducer:
while true; do load_policy; echo -n .; sleep 0.1; done &
for (( i = 0; i < 1024; i++ )); do
runcon -l s0:c$i echo -n x || break
# or:
# chcon -l s0:c$i <some_file> || break
done
This patch overhauls the sidtab so it doesn't need to be frozen during
policy reload, thus solving the above problem.
The new SID table leverages the fact that SIDs are allocated
sequentially and are never invalidated and stores them in linear buckets
indexed by a tree structure. This brings several advantages:
1. Fast SID -> context lookup - this lookup can now be done in
logarithmic time complexity (usually in less than 4 array lookups)
and can still be done safely without locking.
2. No need to re-search the whole table on reverse lookup miss - after
acquiring the spinlock only the newly added entries need to be
searched, which means that reverse lookups that end up inserting a
new entry are now about twice as fast.
3. No need to freeze sidtab during policy reload - it is now possible
to handle insertion of new entries even during sidtab conversion.
The tree structure of the new sidtab is able to grow automatically to up
to about 2^31 entries (at which point it should not have more than about
4 tree levels). The old sidtab had a theoretical capacity of almost 2^32
entries, but half of that is still more than enough since by that point
the reverse table lookups would become unusably slow anyway...
The number of entries per tree node is selected automatically so that
each node fits into a single page, which should be the easiest size for
kmalloc() to handle.
Note that the cache for reverse lookup is preserved with equivalent
logic. The only difference is that instead of storing pointers to the
hash table nodes it stores just the indices of the cached entries.
The new cache ensures that the indices are loaded/stored atomically, but
it still has the drawback that concurrent cache updates may mess up the
contents of the cache. Such situation however only reduces its
effectivity, not the correctness of lookups.
Tested by selinux-testsuite and thoroughly tortured by this simple
stress test:
```
function rand_cat() {
echo $(( $RANDOM % 1024 ))
}
function do_work() {
while true; do
echo -n "system_u:system_r:kernel_t:s0:c$(rand_cat),c$(rand_cat)" \
>/sys/fs/selinux/context 2>/dev/null || true
done
}
do_work >/dev/null &
do_work >/dev/null &
do_work >/dev/null &
while load_policy; do echo -n .; sleep 0.1; done
kill %1
kill %2
kill %3
```
Link: https://github.com/SELinuxProject/selinux-kernel/issues/38
Reported-by: Orion Poplawski <orion@nwra.com>
Reported-by: Li Kun <hw.likun@huawei.com>
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Reviewed-by: Stephen Smalley <sds@tycho.nsa.gov>
[PM: most of sidtab.c merged by hand due to conflicts]
[PM: checkpatch fixes in mls.c, services.c, sidtab.c]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2018-11-30 23:24:08 +08:00
|
|
|
* structure `oldc' from the values specified in the
|
|
|
|
* policy `oldp' to the values specified in the policy `newp',
|
|
|
|
* storing the resulting context in `newc'.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
int mls_convert_context(struct policydb *oldp,
|
|
|
|
struct policydb *newp,
|
selinux: overhaul sidtab to fix bug and improve performance
Before this patch, during a policy reload the sidtab would become frozen
and trying to map a new context to SID would be unable to add a new
entry to sidtab and fail with -ENOMEM.
Such failures are usually propagated into userspace, which has no way of
distignuishing them from actual allocation failures and thus doesn't
handle them gracefully. Such situation can be triggered e.g. by the
following reproducer:
while true; do load_policy; echo -n .; sleep 0.1; done &
for (( i = 0; i < 1024; i++ )); do
runcon -l s0:c$i echo -n x || break
# or:
# chcon -l s0:c$i <some_file> || break
done
This patch overhauls the sidtab so it doesn't need to be frozen during
policy reload, thus solving the above problem.
The new SID table leverages the fact that SIDs are allocated
sequentially and are never invalidated and stores them in linear buckets
indexed by a tree structure. This brings several advantages:
1. Fast SID -> context lookup - this lookup can now be done in
logarithmic time complexity (usually in less than 4 array lookups)
and can still be done safely without locking.
2. No need to re-search the whole table on reverse lookup miss - after
acquiring the spinlock only the newly added entries need to be
searched, which means that reverse lookups that end up inserting a
new entry are now about twice as fast.
3. No need to freeze sidtab during policy reload - it is now possible
to handle insertion of new entries even during sidtab conversion.
The tree structure of the new sidtab is able to grow automatically to up
to about 2^31 entries (at which point it should not have more than about
4 tree levels). The old sidtab had a theoretical capacity of almost 2^32
entries, but half of that is still more than enough since by that point
the reverse table lookups would become unusably slow anyway...
The number of entries per tree node is selected automatically so that
each node fits into a single page, which should be the easiest size for
kmalloc() to handle.
Note that the cache for reverse lookup is preserved with equivalent
logic. The only difference is that instead of storing pointers to the
hash table nodes it stores just the indices of the cached entries.
The new cache ensures that the indices are loaded/stored atomically, but
it still has the drawback that concurrent cache updates may mess up the
contents of the cache. Such situation however only reduces its
effectivity, not the correctness of lookups.
Tested by selinux-testsuite and thoroughly tortured by this simple
stress test:
```
function rand_cat() {
echo $(( $RANDOM % 1024 ))
}
function do_work() {
while true; do
echo -n "system_u:system_r:kernel_t:s0:c$(rand_cat),c$(rand_cat)" \
>/sys/fs/selinux/context 2>/dev/null || true
done
}
do_work >/dev/null &
do_work >/dev/null &
do_work >/dev/null &
while load_policy; do echo -n .; sleep 0.1; done
kill %1
kill %2
kill %3
```
Link: https://github.com/SELinuxProject/selinux-kernel/issues/38
Reported-by: Orion Poplawski <orion@nwra.com>
Reported-by: Li Kun <hw.likun@huawei.com>
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Reviewed-by: Stephen Smalley <sds@tycho.nsa.gov>
[PM: most of sidtab.c merged by hand due to conflicts]
[PM: checkpatch fixes in mls.c, services.c, sidtab.c]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2018-11-30 23:24:08 +08:00
|
|
|
struct context *oldc,
|
|
|
|
struct context *newc)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct level_datum *levdatum;
|
|
|
|
struct cat_datum *catdatum;
|
2005-09-04 06:55:16 +08:00
|
|
|
struct ebitmap_node *node;
|
2005-04-17 06:20:36 +08:00
|
|
|
int l, i;
|
|
|
|
|
2018-03-02 07:48:02 +08:00
|
|
|
if (!oldp->mls_enabled || !newp->mls_enabled)
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (l = 0; l < 2; l++) {
|
2020-04-28 20:55:12 +08:00
|
|
|
levdatum = hashtab_search(&newp->p_levels.table,
|
2010-11-30 04:47:09 +08:00
|
|
|
sym_name(oldp, SYM_LEVELS,
|
selinux: overhaul sidtab to fix bug and improve performance
Before this patch, during a policy reload the sidtab would become frozen
and trying to map a new context to SID would be unable to add a new
entry to sidtab and fail with -ENOMEM.
Such failures are usually propagated into userspace, which has no way of
distignuishing them from actual allocation failures and thus doesn't
handle them gracefully. Such situation can be triggered e.g. by the
following reproducer:
while true; do load_policy; echo -n .; sleep 0.1; done &
for (( i = 0; i < 1024; i++ )); do
runcon -l s0:c$i echo -n x || break
# or:
# chcon -l s0:c$i <some_file> || break
done
This patch overhauls the sidtab so it doesn't need to be frozen during
policy reload, thus solving the above problem.
The new SID table leverages the fact that SIDs are allocated
sequentially and are never invalidated and stores them in linear buckets
indexed by a tree structure. This brings several advantages:
1. Fast SID -> context lookup - this lookup can now be done in
logarithmic time complexity (usually in less than 4 array lookups)
and can still be done safely without locking.
2. No need to re-search the whole table on reverse lookup miss - after
acquiring the spinlock only the newly added entries need to be
searched, which means that reverse lookups that end up inserting a
new entry are now about twice as fast.
3. No need to freeze sidtab during policy reload - it is now possible
to handle insertion of new entries even during sidtab conversion.
The tree structure of the new sidtab is able to grow automatically to up
to about 2^31 entries (at which point it should not have more than about
4 tree levels). The old sidtab had a theoretical capacity of almost 2^32
entries, but half of that is still more than enough since by that point
the reverse table lookups would become unusably slow anyway...
The number of entries per tree node is selected automatically so that
each node fits into a single page, which should be the easiest size for
kmalloc() to handle.
Note that the cache for reverse lookup is preserved with equivalent
logic. The only difference is that instead of storing pointers to the
hash table nodes it stores just the indices of the cached entries.
The new cache ensures that the indices are loaded/stored atomically, but
it still has the drawback that concurrent cache updates may mess up the
contents of the cache. Such situation however only reduces its
effectivity, not the correctness of lookups.
Tested by selinux-testsuite and thoroughly tortured by this simple
stress test:
```
function rand_cat() {
echo $(( $RANDOM % 1024 ))
}
function do_work() {
while true; do
echo -n "system_u:system_r:kernel_t:s0:c$(rand_cat),c$(rand_cat)" \
>/sys/fs/selinux/context 2>/dev/null || true
done
}
do_work >/dev/null &
do_work >/dev/null &
do_work >/dev/null &
while load_policy; do echo -n .; sleep 0.1; done
kill %1
kill %2
kill %3
```
Link: https://github.com/SELinuxProject/selinux-kernel/issues/38
Reported-by: Orion Poplawski <orion@nwra.com>
Reported-by: Li Kun <hw.likun@huawei.com>
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Reviewed-by: Stephen Smalley <sds@tycho.nsa.gov>
[PM: most of sidtab.c merged by hand due to conflicts]
[PM: checkpatch fixes in mls.c, services.c, sidtab.c]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2018-11-30 23:24:08 +08:00
|
|
|
oldc->range.level[l].sens - 1));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!levdatum)
|
|
|
|
return -EINVAL;
|
selinux: overhaul sidtab to fix bug and improve performance
Before this patch, during a policy reload the sidtab would become frozen
and trying to map a new context to SID would be unable to add a new
entry to sidtab and fail with -ENOMEM.
Such failures are usually propagated into userspace, which has no way of
distignuishing them from actual allocation failures and thus doesn't
handle them gracefully. Such situation can be triggered e.g. by the
following reproducer:
while true; do load_policy; echo -n .; sleep 0.1; done &
for (( i = 0; i < 1024; i++ )); do
runcon -l s0:c$i echo -n x || break
# or:
# chcon -l s0:c$i <some_file> || break
done
This patch overhauls the sidtab so it doesn't need to be frozen during
policy reload, thus solving the above problem.
The new SID table leverages the fact that SIDs are allocated
sequentially and are never invalidated and stores them in linear buckets
indexed by a tree structure. This brings several advantages:
1. Fast SID -> context lookup - this lookup can now be done in
logarithmic time complexity (usually in less than 4 array lookups)
and can still be done safely without locking.
2. No need to re-search the whole table on reverse lookup miss - after
acquiring the spinlock only the newly added entries need to be
searched, which means that reverse lookups that end up inserting a
new entry are now about twice as fast.
3. No need to freeze sidtab during policy reload - it is now possible
to handle insertion of new entries even during sidtab conversion.
The tree structure of the new sidtab is able to grow automatically to up
to about 2^31 entries (at which point it should not have more than about
4 tree levels). The old sidtab had a theoretical capacity of almost 2^32
entries, but half of that is still more than enough since by that point
the reverse table lookups would become unusably slow anyway...
The number of entries per tree node is selected automatically so that
each node fits into a single page, which should be the easiest size for
kmalloc() to handle.
Note that the cache for reverse lookup is preserved with equivalent
logic. The only difference is that instead of storing pointers to the
hash table nodes it stores just the indices of the cached entries.
The new cache ensures that the indices are loaded/stored atomically, but
it still has the drawback that concurrent cache updates may mess up the
contents of the cache. Such situation however only reduces its
effectivity, not the correctness of lookups.
Tested by selinux-testsuite and thoroughly tortured by this simple
stress test:
```
function rand_cat() {
echo $(( $RANDOM % 1024 ))
}
function do_work() {
while true; do
echo -n "system_u:system_r:kernel_t:s0:c$(rand_cat),c$(rand_cat)" \
>/sys/fs/selinux/context 2>/dev/null || true
done
}
do_work >/dev/null &
do_work >/dev/null &
do_work >/dev/null &
while load_policy; do echo -n .; sleep 0.1; done
kill %1
kill %2
kill %3
```
Link: https://github.com/SELinuxProject/selinux-kernel/issues/38
Reported-by: Orion Poplawski <orion@nwra.com>
Reported-by: Li Kun <hw.likun@huawei.com>
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Reviewed-by: Stephen Smalley <sds@tycho.nsa.gov>
[PM: most of sidtab.c merged by hand due to conflicts]
[PM: checkpatch fixes in mls.c, services.c, sidtab.c]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2018-11-30 23:24:08 +08:00
|
|
|
newc->range.level[l].sens = levdatum->level->sens;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
selinux: overhaul sidtab to fix bug and improve performance
Before this patch, during a policy reload the sidtab would become frozen
and trying to map a new context to SID would be unable to add a new
entry to sidtab and fail with -ENOMEM.
Such failures are usually propagated into userspace, which has no way of
distignuishing them from actual allocation failures and thus doesn't
handle them gracefully. Such situation can be triggered e.g. by the
following reproducer:
while true; do load_policy; echo -n .; sleep 0.1; done &
for (( i = 0; i < 1024; i++ )); do
runcon -l s0:c$i echo -n x || break
# or:
# chcon -l s0:c$i <some_file> || break
done
This patch overhauls the sidtab so it doesn't need to be frozen during
policy reload, thus solving the above problem.
The new SID table leverages the fact that SIDs are allocated
sequentially and are never invalidated and stores them in linear buckets
indexed by a tree structure. This brings several advantages:
1. Fast SID -> context lookup - this lookup can now be done in
logarithmic time complexity (usually in less than 4 array lookups)
and can still be done safely without locking.
2. No need to re-search the whole table on reverse lookup miss - after
acquiring the spinlock only the newly added entries need to be
searched, which means that reverse lookups that end up inserting a
new entry are now about twice as fast.
3. No need to freeze sidtab during policy reload - it is now possible
to handle insertion of new entries even during sidtab conversion.
The tree structure of the new sidtab is able to grow automatically to up
to about 2^31 entries (at which point it should not have more than about
4 tree levels). The old sidtab had a theoretical capacity of almost 2^32
entries, but half of that is still more than enough since by that point
the reverse table lookups would become unusably slow anyway...
The number of entries per tree node is selected automatically so that
each node fits into a single page, which should be the easiest size for
kmalloc() to handle.
Note that the cache for reverse lookup is preserved with equivalent
logic. The only difference is that instead of storing pointers to the
hash table nodes it stores just the indices of the cached entries.
The new cache ensures that the indices are loaded/stored atomically, but
it still has the drawback that concurrent cache updates may mess up the
contents of the cache. Such situation however only reduces its
effectivity, not the correctness of lookups.
Tested by selinux-testsuite and thoroughly tortured by this simple
stress test:
```
function rand_cat() {
echo $(( $RANDOM % 1024 ))
}
function do_work() {
while true; do
echo -n "system_u:system_r:kernel_t:s0:c$(rand_cat),c$(rand_cat)" \
>/sys/fs/selinux/context 2>/dev/null || true
done
}
do_work >/dev/null &
do_work >/dev/null &
do_work >/dev/null &
while load_policy; do echo -n .; sleep 0.1; done
kill %1
kill %2
kill %3
```
Link: https://github.com/SELinuxProject/selinux-kernel/issues/38
Reported-by: Orion Poplawski <orion@nwra.com>
Reported-by: Li Kun <hw.likun@huawei.com>
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Reviewed-by: Stephen Smalley <sds@tycho.nsa.gov>
[PM: most of sidtab.c merged by hand due to conflicts]
[PM: checkpatch fixes in mls.c, services.c, sidtab.c]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2018-11-30 23:24:08 +08:00
|
|
|
ebitmap_for_each_positive_bit(&oldc->range.level[l].cat,
|
|
|
|
node, i) {
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-29 01:20:55 +08:00
|
|
|
int rc;
|
|
|
|
|
2020-04-28 20:55:12 +08:00
|
|
|
catdatum = hashtab_search(&newp->p_cats.table,
|
2010-11-30 04:47:09 +08:00
|
|
|
sym_name(oldp, SYM_CATS, i));
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-29 01:20:55 +08:00
|
|
|
if (!catdatum)
|
|
|
|
return -EINVAL;
|
selinux: overhaul sidtab to fix bug and improve performance
Before this patch, during a policy reload the sidtab would become frozen
and trying to map a new context to SID would be unable to add a new
entry to sidtab and fail with -ENOMEM.
Such failures are usually propagated into userspace, which has no way of
distignuishing them from actual allocation failures and thus doesn't
handle them gracefully. Such situation can be triggered e.g. by the
following reproducer:
while true; do load_policy; echo -n .; sleep 0.1; done &
for (( i = 0; i < 1024; i++ )); do
runcon -l s0:c$i echo -n x || break
# or:
# chcon -l s0:c$i <some_file> || break
done
This patch overhauls the sidtab so it doesn't need to be frozen during
policy reload, thus solving the above problem.
The new SID table leverages the fact that SIDs are allocated
sequentially and are never invalidated and stores them in linear buckets
indexed by a tree structure. This brings several advantages:
1. Fast SID -> context lookup - this lookup can now be done in
logarithmic time complexity (usually in less than 4 array lookups)
and can still be done safely without locking.
2. No need to re-search the whole table on reverse lookup miss - after
acquiring the spinlock only the newly added entries need to be
searched, which means that reverse lookups that end up inserting a
new entry are now about twice as fast.
3. No need to freeze sidtab during policy reload - it is now possible
to handle insertion of new entries even during sidtab conversion.
The tree structure of the new sidtab is able to grow automatically to up
to about 2^31 entries (at which point it should not have more than about
4 tree levels). The old sidtab had a theoretical capacity of almost 2^32
entries, but half of that is still more than enough since by that point
the reverse table lookups would become unusably slow anyway...
The number of entries per tree node is selected automatically so that
each node fits into a single page, which should be the easiest size for
kmalloc() to handle.
Note that the cache for reverse lookup is preserved with equivalent
logic. The only difference is that instead of storing pointers to the
hash table nodes it stores just the indices of the cached entries.
The new cache ensures that the indices are loaded/stored atomically, but
it still has the drawback that concurrent cache updates may mess up the
contents of the cache. Such situation however only reduces its
effectivity, not the correctness of lookups.
Tested by selinux-testsuite and thoroughly tortured by this simple
stress test:
```
function rand_cat() {
echo $(( $RANDOM % 1024 ))
}
function do_work() {
while true; do
echo -n "system_u:system_r:kernel_t:s0:c$(rand_cat),c$(rand_cat)" \
>/sys/fs/selinux/context 2>/dev/null || true
done
}
do_work >/dev/null &
do_work >/dev/null &
do_work >/dev/null &
while load_policy; do echo -n .; sleep 0.1; done
kill %1
kill %2
kill %3
```
Link: https://github.com/SELinuxProject/selinux-kernel/issues/38
Reported-by: Orion Poplawski <orion@nwra.com>
Reported-by: Li Kun <hw.likun@huawei.com>
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Reviewed-by: Stephen Smalley <sds@tycho.nsa.gov>
[PM: most of sidtab.c merged by hand due to conflicts]
[PM: checkpatch fixes in mls.c, services.c, sidtab.c]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2018-11-30 23:24:08 +08:00
|
|
|
rc = ebitmap_set_bit(&newc->range.level[l].cat,
|
|
|
|
catdatum->value - 1, 1);
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-29 01:20:55 +08:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-02 07:48:02 +08:00
|
|
|
int mls_compute_sid(struct policydb *p,
|
|
|
|
struct context *scontext,
|
2005-04-17 06:20:36 +08:00
|
|
|
struct context *tcontext,
|
|
|
|
u16 tclass,
|
|
|
|
u32 specified,
|
2011-03-02 13:32:33 +08:00
|
|
|
struct context *newcontext,
|
|
|
|
bool sock)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-01-08 04:55:16 +08:00
|
|
|
struct range_trans rtr;
|
|
|
|
struct mls_range *r;
|
2012-03-21 02:35:12 +08:00
|
|
|
struct class_datum *cladatum;
|
|
|
|
int default_range = 0;
|
2006-09-26 14:31:59 +08:00
|
|
|
|
2018-03-02 07:48:02 +08:00
|
|
|
if (!p->mls_enabled)
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (specified) {
|
|
|
|
case AVTAB_TRANSITION:
|
2006-09-26 14:31:59 +08:00
|
|
|
/* Look for a range transition rule. */
|
2010-01-08 04:55:16 +08:00
|
|
|
rtr.source_type = scontext->type;
|
|
|
|
rtr.target_type = tcontext->type;
|
|
|
|
rtr.target_class = tclass;
|
2020-04-28 20:55:12 +08:00
|
|
|
r = hashtab_search(&p->range_tr, &rtr);
|
2010-01-08 04:55:16 +08:00
|
|
|
if (r)
|
|
|
|
return mls_range_set(newcontext, r);
|
2012-03-21 02:35:12 +08:00
|
|
|
|
2018-03-02 07:48:02 +08:00
|
|
|
if (tclass && tclass <= p->p_classes.nprim) {
|
|
|
|
cladatum = p->class_val_to_struct[tclass - 1];
|
2012-03-21 02:35:12 +08:00
|
|
|
if (cladatum)
|
|
|
|
default_range = cladatum->default_range;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (default_range) {
|
|
|
|
case DEFAULT_SOURCE_LOW:
|
|
|
|
return mls_context_cpy_low(newcontext, scontext);
|
|
|
|
case DEFAULT_SOURCE_HIGH:
|
|
|
|
return mls_context_cpy_high(newcontext, scontext);
|
|
|
|
case DEFAULT_SOURCE_LOW_HIGH:
|
|
|
|
return mls_context_cpy(newcontext, scontext);
|
|
|
|
case DEFAULT_TARGET_LOW:
|
|
|
|
return mls_context_cpy_low(newcontext, tcontext);
|
|
|
|
case DEFAULT_TARGET_HIGH:
|
|
|
|
return mls_context_cpy_high(newcontext, tcontext);
|
|
|
|
case DEFAULT_TARGET_LOW_HIGH:
|
|
|
|
return mls_context_cpy(newcontext, tcontext);
|
2019-09-05 05:03:23 +08:00
|
|
|
case DEFAULT_GLBLUB:
|
|
|
|
return mls_context_glblub(newcontext,
|
|
|
|
scontext, tcontext);
|
2012-03-21 02:35:12 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Fallthrough */
|
|
|
|
case AVTAB_CHANGE:
|
2020-04-14 16:18:07 +08:00
|
|
|
if ((tclass == p->process_class) || sock)
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Use the process MLS attributes. */
|
2006-12-13 03:02:41 +08:00
|
|
|
return mls_context_cpy(newcontext, scontext);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
|
|
|
/* Use the process effective MLS attributes. */
|
2006-12-13 03:02:41 +08:00
|
|
|
return mls_context_cpy_low(newcontext, scontext);
|
2005-04-17 06:20:36 +08:00
|
|
|
case AVTAB_MEMBER:
|
2008-01-25 04:30:52 +08:00
|
|
|
/* Use the process effective MLS attributes. */
|
|
|
|
return mls_context_cpy_low(newcontext, scontext);
|
2009-12-03 16:48:28 +08:00
|
|
|
|
|
|
|
/* fall through */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2006-11-30 02:18:18 +08:00
|
|
|
#ifdef CONFIG_NETLABEL
|
2006-08-05 14:17:57 +08:00
|
|
|
/**
|
2006-11-30 02:18:18 +08:00
|
|
|
* mls_export_netlbl_lvl - Export the MLS sensitivity levels to NetLabel
|
2006-08-05 14:17:57 +08:00
|
|
|
* @context: the security context
|
2006-11-30 02:18:18 +08:00
|
|
|
* @secattr: the NetLabel security attributes
|
2006-08-05 14:17:57 +08:00
|
|
|
*
|
|
|
|
* Description:
|
2006-11-30 02:18:18 +08:00
|
|
|
* Given the security context copy the low MLS sensitivity level into the
|
|
|
|
* NetLabel MLS sensitivity level field.
|
2006-08-05 14:17:57 +08:00
|
|
|
*
|
|
|
|
*/
|
2018-03-02 07:48:02 +08:00
|
|
|
void mls_export_netlbl_lvl(struct policydb *p,
|
|
|
|
struct context *context,
|
2006-11-30 02:18:18 +08:00
|
|
|
struct netlbl_lsm_secattr *secattr)
|
2006-08-05 14:17:57 +08:00
|
|
|
{
|
2018-03-02 07:48:02 +08:00
|
|
|
if (!p->mls_enabled)
|
2006-08-05 14:17:57 +08:00
|
|
|
return;
|
|
|
|
|
2008-01-29 21:37:59 +08:00
|
|
|
secattr->attr.mls.lvl = context->range.level[0].sens - 1;
|
2006-11-30 02:18:18 +08:00
|
|
|
secattr->flags |= NETLBL_SECATTR_MLS_LVL;
|
2006-08-05 14:17:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-11-30 02:18:18 +08:00
|
|
|
* mls_import_netlbl_lvl - Import the NetLabel MLS sensitivity levels
|
2006-08-05 14:17:57 +08:00
|
|
|
* @context: the security context
|
2006-11-30 02:18:18 +08:00
|
|
|
* @secattr: the NetLabel security attributes
|
2006-08-05 14:17:57 +08:00
|
|
|
*
|
|
|
|
* Description:
|
2006-11-30 02:18:18 +08:00
|
|
|
* Given the security context and the NetLabel security attributes, copy the
|
|
|
|
* NetLabel MLS sensitivity level into the context.
|
2006-08-05 14:17:57 +08:00
|
|
|
*
|
|
|
|
*/
|
2018-03-02 07:48:02 +08:00
|
|
|
void mls_import_netlbl_lvl(struct policydb *p,
|
|
|
|
struct context *context,
|
2006-11-30 02:18:18 +08:00
|
|
|
struct netlbl_lsm_secattr *secattr)
|
2006-08-05 14:17:57 +08:00
|
|
|
{
|
2018-03-02 07:48:02 +08:00
|
|
|
if (!p->mls_enabled)
|
2006-08-05 14:17:57 +08:00
|
|
|
return;
|
|
|
|
|
2008-01-29 21:37:59 +08:00
|
|
|
context->range.level[0].sens = secattr->attr.mls.lvl + 1;
|
2006-11-30 02:18:18 +08:00
|
|
|
context->range.level[1].sens = context->range.level[0].sens;
|
2006-08-05 14:17:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-11-30 02:18:18 +08:00
|
|
|
* mls_export_netlbl_cat - Export the MLS categories to NetLabel
|
2006-08-05 14:17:57 +08:00
|
|
|
* @context: the security context
|
2006-11-30 02:18:18 +08:00
|
|
|
* @secattr: the NetLabel security attributes
|
2006-08-05 14:17:57 +08:00
|
|
|
*
|
|
|
|
* Description:
|
2006-11-30 02:18:18 +08:00
|
|
|
* Given the security context copy the low MLS categories into the NetLabel
|
|
|
|
* MLS category field. Returns zero on success, negative values on failure.
|
2006-08-05 14:17:57 +08:00
|
|
|
*
|
|
|
|
*/
|
2018-03-02 07:48:02 +08:00
|
|
|
int mls_export_netlbl_cat(struct policydb *p,
|
|
|
|
struct context *context,
|
2006-11-30 02:18:18 +08:00
|
|
|
struct netlbl_lsm_secattr *secattr)
|
2006-08-05 14:17:57 +08:00
|
|
|
{
|
2006-11-30 02:18:18 +08:00
|
|
|
int rc;
|
2006-08-05 14:17:57 +08:00
|
|
|
|
2018-03-02 07:48:02 +08:00
|
|
|
if (!p->mls_enabled)
|
2006-08-05 14:17:57 +08:00
|
|
|
return 0;
|
|
|
|
|
2006-11-30 02:18:18 +08:00
|
|
|
rc = ebitmap_netlbl_export(&context->range.level[0].cat,
|
2008-01-29 21:37:59 +08:00
|
|
|
&secattr->attr.mls.cat);
|
|
|
|
if (rc == 0 && secattr->attr.mls.cat != NULL)
|
2006-11-30 02:18:18 +08:00
|
|
|
secattr->flags |= NETLBL_SECATTR_MLS_CAT;
|
2006-08-05 14:17:57 +08:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-11-30 02:18:18 +08:00
|
|
|
* mls_import_netlbl_cat - Import the MLS categories from NetLabel
|
2006-08-05 14:17:57 +08:00
|
|
|
* @context: the security context
|
2006-11-30 02:18:18 +08:00
|
|
|
* @secattr: the NetLabel security attributes
|
2006-08-05 14:17:57 +08:00
|
|
|
*
|
|
|
|
* Description:
|
2006-11-30 02:18:18 +08:00
|
|
|
* Copy the NetLabel security attributes into the SELinux context; since the
|
|
|
|
* NetLabel security attribute only contains a single MLS category use it for
|
|
|
|
* both the low and high categories of the context. Returns zero on success,
|
|
|
|
* negative values on failure.
|
2006-08-05 14:17:57 +08:00
|
|
|
*
|
|
|
|
*/
|
2018-03-02 07:48:02 +08:00
|
|
|
int mls_import_netlbl_cat(struct policydb *p,
|
|
|
|
struct context *context,
|
2006-11-30 02:18:18 +08:00
|
|
|
struct netlbl_lsm_secattr *secattr)
|
2006-08-05 14:17:57 +08:00
|
|
|
{
|
2006-11-30 02:18:18 +08:00
|
|
|
int rc;
|
2006-08-05 14:17:57 +08:00
|
|
|
|
2018-03-02 07:48:02 +08:00
|
|
|
if (!p->mls_enabled)
|
2006-08-05 14:17:57 +08:00
|
|
|
return 0;
|
|
|
|
|
2006-11-30 02:18:18 +08:00
|
|
|
rc = ebitmap_netlbl_import(&context->range.level[0].cat,
|
2008-01-29 21:37:59 +08:00
|
|
|
secattr->attr.mls.cat);
|
2015-02-18 04:30:23 +08:00
|
|
|
if (rc)
|
2006-11-30 02:18:18 +08:00
|
|
|
goto import_netlbl_cat_failure;
|
2015-02-18 04:30:23 +08:00
|
|
|
memcpy(&context->range.level[1].cat, &context->range.level[0].cat,
|
|
|
|
sizeof(context->range.level[0].cat));
|
2006-08-05 14:17:57 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2006-11-30 02:18:18 +08:00
|
|
|
import_netlbl_cat_failure:
|
2006-08-05 14:17:57 +08:00
|
|
|
ebitmap_destroy(&context->range.level[0].cat);
|
|
|
|
return rc;
|
|
|
|
}
|
2006-11-30 02:18:18 +08:00
|
|
|
#endif /* CONFIG_NETLABEL */
|