Skip to content

Commit 78dc53c

Browse files
committed
Merge branch 'for-linus2' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security
Pull security subsystem updates from James Morris: "In this patchset, we finally get an SELinux update, with Paul Moore taking over as maintainer of that code. Also a significant update for the Keys subsystem, as well as maintenance updates to Smack, IMA, TPM, and Apparmor" and since I wanted to know more about the updates to key handling, here's the explanation from David Howells on that: "Okay. There are a number of separate bits. I'll go over the big bits and the odd important other bit, most of the smaller bits are just fixes and cleanups. If you want the small bits accounting for, I can do that too. (1) Keyring capacity expansion. KEYS: Consolidate the concept of an 'index key' for key access KEYS: Introduce a search context structure KEYS: Search for auth-key by name rather than target key ID Add a generic associative array implementation. KEYS: Expand the capacity of a keyring Several of the patches are providing an expansion of the capacity of a keyring. Currently, the maximum size of a keyring payload is one page. Subtract a small header and then divide up into pointers, that only gives you ~500 pointers on an x86_64 box. However, since the NFS idmapper uses a keyring to store ID mapping data, that has proven to be insufficient to the cause. Whatever data structure I use to handle the keyring payload, it can only store pointers to keys, not the keys themselves because several keyrings may point to a single key. This precludes inserting, say, and rb_node struct into the key struct for this purpose. I could make an rbtree of records such that each record has an rb_node and a key pointer, but that would use four words of space per key stored in the keyring. It would, however, be able to use much existing code. I selected instead a non-rebalancing radix-tree type approach as that could have a better space-used/key-pointer ratio. I could have used the radix tree implementation that we already have and insert keys into it by their serial numbers, but that means any sort of search must iterate over the whole radix tree. Further, its nodes are a bit on the capacious side for what I want - especially given that key serial numbers are randomly allocated, thus leaving a lot of empty space in the tree. So what I have is an associative array that internally is a radix-tree with 16 pointers per node where the index key is constructed from the key type pointer and the key description. This means that an exact lookup by type+description is very fast as this tells us how to navigate directly to the target key. I made the data structure general in lib/assoc_array.c as far as it is concerned, its index key is just a sequence of bits that leads to a pointer. It's possible that someone else will be able to make use of it also. FS-Cache might, for example. (2) Mark keys as 'trusted' and keyrings as 'trusted only'. KEYS: verify a certificate is signed by a 'trusted' key KEYS: Make the system 'trusted' keyring viewable by userspace KEYS: Add a 'trusted' flag and a 'trusted only' flag KEYS: Separate the kernel signature checking keyring from module signing These patches allow keys carrying asymmetric public keys to be marked as being 'trusted' and allow keyrings to be marked as only permitting the addition or linkage of trusted keys. Keys loaded from hardware during kernel boot or compiled into the kernel during build are marked as being trusted automatically. New keys can be loaded at runtime with add_key(). They are checked against the system keyring contents and if their signatures can be validated with keys that are already marked trusted, then they are marked trusted also and can thus be added into the master keyring. Patches from Mimi Zohar make this usable with the IMA keyrings also. (3) Remove the date checks on the key used to validate a module signature. X.509: Remove certificate date checks It's not reasonable to reject a signature just because the key that it was generated with is no longer valid datewise - especially if the kernel hasn't yet managed to set the system clock when the first module is loaded - so just remove those checks. (4) Make it simpler to deal with additional X.509 being loaded into the kernel. KEYS: Load *.x509 files into kernel keyring KEYS: Have make canonicalise the paths of the X.509 certs better to deduplicate The builder of the kernel now just places files with the extension ".x509" into the kernel source or build trees and they're concatenated by the kernel build and stuffed into the appropriate section. (5) Add support for userspace kerberos to use keyrings. KEYS: Add per-user_namespace registers for persistent per-UID kerberos caches KEYS: Implement a big key type that can save to tmpfs Fedora went to, by default, storing kerberos tickets and tokens in tmpfs. We looked at storing it in keyrings instead as that confers certain advantages such as tickets being automatically deleted after a certain amount of time and the ability for the kernel to get at these tokens more easily. To make this work, two things were needed: (a) A way for the tickets to persist beyond the lifetime of all a user's sessions so that cron-driven processes can still use them. The problem is that a user's session keyrings are deleted when the session that spawned them logs out and the user's user keyring is deleted when the UID is deleted (typically when the last log out happens), so neither of these places is suitable. I've added a system keyring into which a 'persistent' keyring is created for each UID on request. Each time a user requests their persistent keyring, the expiry time on it is set anew. If the user doesn't ask for it for, say, three days, the keyring is automatically expired and garbage collected using the existing gc. All the kerberos tokens it held are then also gc'd. (b) A key type that can hold really big tickets (up to 1MB in size). The problem is that Active Directory can return huge tickets with lots of auxiliary data attached. We don't, however, want to eat up huge tracts of unswappable kernel space for this, so if the ticket is greater than a certain size, we create a swappable shmem file and dump the contents in there and just live with the fact we then have an inode and a dentry overhead. If the ticket is smaller than that, we slap it in a kmalloc()'d buffer" * 'for-linus2' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (121 commits) KEYS: Fix keyring content gc scanner KEYS: Fix error handling in big_key instantiation KEYS: Fix UID check in keyctl_get_persistent() KEYS: The RSA public key algorithm needs to select MPILIB ima: define '_ima' as a builtin 'trusted' keyring ima: extend the measurement list to include the file signature kernel/system_certificate.S: use real contents instead of macro GLOBAL() KEYS: fix error return code in big_key_instantiate() KEYS: Fix keyring quota misaccounting on key replacement and unlink KEYS: Fix a race between negating a key and reading the error set KEYS: Make BIG_KEYS boolean apparmor: remove the "task" arg from may_change_ptraced_domain() apparmor: remove parent task info from audit logging apparmor: remove tsk field from the apparmor_audit_struct apparmor: fix capability to not use the current task, during reporting Smack: Ptrace access check mode ima: provide hash algo info in the xattr ima: enable support for larger default filedata hash algorithms ima: define kernel parameter 'ima_template=' to change configured default ima: add Kconfig default measurement list template ...
2 parents 3eaded8 + 62fe318 commit 78dc53c

125 files changed

Lines changed: 7712 additions & 2058 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/assoc_array.txt‎

Lines changed: 574 additions & 0 deletions
Large diffs are not rendered by default.

‎Documentation/devicetree/bindings/i2c/trivial-devices.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ adi,adt7461 +/-1C TDM Extended Temp Range I.C
1515
adt7461 +/-1C TDM Extended Temp Range I.C
1616
at,24c08 i2c serial eeprom (24cxx)
1717
atmel,24c02 i2c serial eeprom (24cxx)
18+
atmel,at97sc3204t i2c trusted platform module (TPM)
1819
catalyst,24c32 i2c serial eeprom
1920
dallas,ds1307 64 x 8, Serial, I2C Real-Time Clock
2021
dallas,ds1338 I2C RTC with 56-Byte NV RAM
@@ -44,6 +45,7 @@ mc,rv3029c2 Real Time Clock Module with I2C-Bus
4445
national,lm75 I2C TEMP SENSOR
4546
national,lm80 Serial Interface ACPI-Compatible Microprocessor System Hardware Monitor
4647
national,lm92 ±0.33°C Accurate, 12-Bit + Sign Temperature Sensor and Thermal Window Comparator with Two-Wire Interface
48+
nuvoton,npct501 i2c trusted platform module (TPM)
4749
nxp,pca9556 Octal SMBus and I2C registered interface
4850
nxp,pca9557 8-bit I2C-bus and SMBus I/O port with reset
4951
nxp,pcf8563 Real-time clock/calendar
@@ -61,3 +63,4 @@ taos,tsl2550 Ambient Light Sensor with SMBUS/Two Wire Serial Interface
6163
ti,tsc2003 I2C Touch-Screen Controller
6264
ti,tmp102 Low Power Digital Temperature Sensor with SMBUS/Two Wire Serial Interface
6365
ti,tmp275 Digital Temperature Sensor
66+
winbond,wpct301 i2c trusted platform module (TPM)

‎Documentation/kernel-parameters.txt‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,15 +1190,24 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
11901190
owned by uid=0.
11911191

11921192
ima_hash= [IMA]
1193-
Format: { "sha1" | "md5" }
1193+
Format: { md5 | sha1 | rmd160 | sha256 | sha384
1194+
| sha512 | ... }
11941195
default: "sha1"
11951196

1197+
The list of supported hash algorithms is defined
1198+
in crypto/hash_info.h.
1199+
11961200
ima_tcb [IMA]
11971201
Load a policy which meets the needs of the Trusted
11981202
Computing Base. This means IMA will measure all
11991203
programs exec'd, files mmap'd for exec, and all files
12001204
opened for read by uid=0.
12011205

1206+
ima_template= [IMA]
1207+
Select one of defined IMA measurements template formats.
1208+
Formats: { "ima" | "ima-ng" }
1209+
Default: "ima-ng"
1210+
12021211
init= [KNL]
12031212
Format: <full_path>
12041213
Run specified binary instead of /sbin/init as init

‎Documentation/security/00-INDEX‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ keys.txt
2222
- description of the kernel key retention service.
2323
tomoyo.txt
2424
- documentation on the TOMOYO Linux Security Module.
25+
IMA-templates.txt
26+
- documentation on the template management mechanism for IMA.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
IMA Template Management Mechanism
2+
3+
4+
==== INTRODUCTION ====
5+
6+
The original 'ima' template is fixed length, containing the filedata hash
7+
and pathname. The filedata hash is limited to 20 bytes (md5/sha1).
8+
The pathname is a null terminated string, limited to 255 characters.
9+
To overcome these limitations and to add additional file metadata, it is
10+
necessary to extend the current version of IMA by defining additional
11+
templates. For example, information that could be possibly reported are
12+
the inode UID/GID or the LSM labels either of the inode and of the process
13+
that is accessing it.
14+
15+
However, the main problem to introduce this feature is that, each time
16+
a new template is defined, the functions that generate and display
17+
the measurements list would include the code for handling a new format
18+
and, thus, would significantly grow over the time.
19+
20+
The proposed solution solves this problem by separating the template
21+
management from the remaining IMA code. The core of this solution is the
22+
definition of two new data structures: a template descriptor, to determine
23+
which information should be included in the measurement list; a template
24+
field, to generate and display data of a given type.
25+
26+
Managing templates with these structures is very simple. To support
27+
a new data type, developers define the field identifier and implement
28+
two functions, init() and show(), respectively to generate and display
29+
measurement entries. Defining a new template descriptor requires
30+
specifying the template format, a string of field identifiers separated
31+
by the '|' character. While in the current implementation it is possible
32+
to define new template descriptors only by adding their definition in the
33+
template specific code (ima_template.c), in a future version it will be
34+
possible to register a new template on a running kernel by supplying to IMA
35+
the desired format string. In this version, IMA initializes at boot time
36+
all defined template descriptors by translating the format into an array
37+
of template fields structures taken from the set of the supported ones.
38+
39+
After the initialization step, IMA will call ima_alloc_init_template()
40+
(new function defined within the patches for the new template management
41+
mechanism) to generate a new measurement entry by using the template
42+
descriptor chosen through the kernel configuration or through the newly
43+
introduced 'ima_template=' kernel command line parameter. It is during this
44+
phase that the advantages of the new architecture are clearly shown:
45+
the latter function will not contain specific code to handle a given template
46+
but, instead, it simply calls the init() method of the template fields
47+
associated to the chosen template descriptor and store the result (pointer
48+
to allocated data and data length) in the measurement entry structure.
49+
50+
The same mechanism is employed to display measurements entries.
51+
The functions ima[_ascii]_measurements_show() retrieve, for each entry,
52+
the template descriptor used to produce that entry and call the show()
53+
method for each item of the array of template fields structures.
54+
55+
56+
57+
==== SUPPORTED TEMPLATE FIELDS AND DESCRIPTORS ====
58+
59+
In the following, there is the list of supported template fields
60+
('<identifier>': description), that can be used to define new template
61+
descriptors by adding their identifier to the format string
62+
(support for more data types will be added later):
63+
64+
- 'd': the digest of the event (i.e. the digest of a measured file),
65+
calculated with the SHA1 or MD5 hash algorithm;
66+
- 'n': the name of the event (i.e. the file name), with size up to 255 bytes;
67+
- 'd-ng': the digest of the event, calculated with an arbitrary hash
68+
algorithm (field format: [<hash algo>:]digest, where the digest
69+
prefix is shown only if the hash algorithm is not SHA1 or MD5);
70+
- 'n-ng': the name of the event, without size limitations.
71+
72+
73+
Below, there is the list of defined template descriptors:
74+
- "ima": its format is 'd|n';
75+
- "ima-ng" (default): its format is 'd-ng|n-ng'.
76+
77+
78+
79+
==== USE ====
80+
81+
To specify the template descriptor to be used to generate measurement entries,
82+
currently the following methods are supported:
83+
84+
- select a template descriptor among those supported in the kernel
85+
configuration ('ima-ng' is the default choice);
86+
- specify a template descriptor name from the kernel command line through
87+
the 'ima_template=' parameter.

‎Documentation/security/keys.txt‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -865,15 +865,14 @@ encountered:
865865
calling processes has a searchable link to the key from one of its
866866
keyrings. There are three functions for dealing with these:
867867

868-
key_ref_t make_key_ref(const struct key *key,
869-
unsigned long possession);
868+
key_ref_t make_key_ref(const struct key *key, bool possession);
870869

871870
struct key *key_ref_to_ptr(const key_ref_t key_ref);
872871

873-
unsigned long is_key_possessed(const key_ref_t key_ref);
872+
bool is_key_possessed(const key_ref_t key_ref);
874873

875874
The first function constructs a key reference from a key pointer and
876-
possession information (which must be 0 or 1 and not any other value).
875+
possession information (which must be true or false).
877876

878877
The second function retrieves the key pointer from a reference and the
879878
third retrieves the possession flag.
@@ -961,14 +960,17 @@ payload contents" for more information.
961960
the argument will not be parsed.
962961

963962

964-
(*) Extra references can be made to a key by calling the following function:
963+
(*) Extra references can be made to a key by calling one of the following
964+
functions:
965965

966+
struct key *__key_get(struct key *key);
966967
struct key *key_get(struct key *key);
967968

968-
These need to be disposed of by calling key_put() when they've been
969-
finished with. The key pointer passed in will be returned. If the pointer
970-
is NULL or CONFIG_KEYS is not set then the key will not be dereferenced and
971-
no increment will take place.
969+
Keys so references will need to be disposed of by calling key_put() when
970+
they've been finished with. The key pointer passed in will be returned.
971+
972+
In the case of key_get(), if the pointer is NULL or CONFIG_KEYS is not set
973+
then the key will not be dereferenced and no increment will take place.
972974

973975

974976
(*) A key's serial number can be obtained by calling:

‎MAINTAINERS‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7515,9 +7515,10 @@ SELINUX SECURITY MODULE
75157515
M: Stephen Smalley <sds@tycho.nsa.gov>
75167516
M: James Morris <james.l.morris@oracle.com>
75177517
M: Eric Paris <eparis@parisplace.org>
7518+
M: Paul Moore <paul@paul-moore.com>
75187519
L: selinux@tycho.nsa.gov (subscribers-only, general discussion)
75197520
W: http://selinuxproject.org
7520-
T: git git://git.infradead.org/users/eparis/selinux.git
7521+
T: git git://git.infradead.org/users/pcmoore/selinux
75217522
S: Supported
75227523
F: include/linux/selinux*
75237524
F: security/selinux/
@@ -8664,6 +8665,7 @@ F: drivers/media/usb/tm6000/
86648665
TPM DEVICE DRIVER
86658666
M: Leonidas Da Silva Barbosa <leosilva@linux.vnet.ibm.com>
86668667
M: Ashley Lai <ashley@ashleylai.com>
8668+
M: Peter Huewe <peterhuewe@gmx.de>
86678669
M: Rajiv Andrade <mail@srajiv.net>
86688670
W: http://tpmdd.sourceforge.net
86698671
M: Marcel Selhorst <tpmdd@selhorst.net>

‎crypto/Kconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,9 @@ config CRYPTO_USER_API_SKCIPHER
14021402
This option enables the user-spaces interface for symmetric
14031403
key cipher algorithms.
14041404

1405+
config CRYPTO_HASH_INFO
1406+
bool
1407+
14051408
source "drivers/crypto/Kconfig"
14061409
source crypto/asymmetric_keys/Kconfig
14071410

‎crypto/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,4 @@ obj-$(CONFIG_CRYPTO_USER_API_SKCIPHER) += algif_skcipher.o
104104
obj-$(CONFIG_XOR_BLOCKS) += xor.o
105105
obj-$(CONFIG_ASYNC_CORE) += async_tx/
106106
obj-$(CONFIG_ASYMMETRIC_KEY_TYPE) += asymmetric_keys/
107+
obj-$(CONFIG_CRYPTO_HASH_INFO) += hash_info.o

‎crypto/asymmetric_keys/Kconfig‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ if ASYMMETRIC_KEY_TYPE
1212
config ASYMMETRIC_PUBLIC_KEY_SUBTYPE
1313
tristate "Asymmetric public-key crypto algorithm subtype"
1414
select MPILIB
15+
select PUBLIC_KEY_ALGO_RSA
16+
select CRYPTO_HASH_INFO
1517
help
1618
This option provides support for asymmetric public key type handling.
1719
If signature generation and/or verification are to be used,
@@ -20,8 +22,8 @@ config ASYMMETRIC_PUBLIC_KEY_SUBTYPE
2022

2123
config PUBLIC_KEY_ALGO_RSA
2224
tristate "RSA public-key algorithm"
23-
depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE
2425
select MPILIB_EXTRA
26+
select MPILIB
2527
help
2628
This option enables support for the RSA algorithm (PKCS#1, RFC3447).
2729

0 commit comments

Comments
 (0)