Skip to content

Commit 7f313ff

Browse files
committed
Merge tag 'integrity-v5.18' of git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity
Pull integrity subsystem updates from Mimi Zohar: "Except for extending the 'encrypted' key type to support user provided data, the rest is code cleanup, __setup() usage bug fix, and a trivial change" * tag 'integrity-v5.18' of git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity: MAINTAINERS: add missing security/integrity/platform_certs EVM: fix the evm= __setup handler return value KEYS: encrypted: Instantiate key with user-provided decrypted data ima: define ima_max_digest_data struct without a flexible array variable ima: rename IMA_ACTION_FLAGS to IMA_NONACTION_FLAGS ima: Return error code obtained from securityfs functions MAINTAINERS: add missing "security/integrity" directory ima: Fix trivial typos in the comments
2 parents 2c5a535 + 4a48b4c commit 7f313ff

12 files changed

Lines changed: 146 additions & 64 deletions

File tree

Documentation/security/keys/trusted-encrypted.rst

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,13 @@ Encrypted Keys
107107
--------------
108108

109109
Encrypted keys do not depend on a trust source, and are faster, as they use AES
110-
for encryption/decryption. New keys are created from kernel-generated random
111-
numbers, and are encrypted/decrypted using a specified ‘master’ key. The
112-
‘master’ key can either be a trusted-key or user-key type. The main disadvantage
113-
of encrypted keys is that if they are not rooted in a trusted key, they are only
114-
as secure as the user key encrypting them. The master user key should therefore
115-
be loaded in as secure a way as possible, preferably early in boot.
110+
for encryption/decryption. New keys are created either from kernel-generated
111+
random numbers or user-provided decrypted data, and are encrypted/decrypted
112+
using a specified ‘master’ key. The ‘master’ key can either be a trusted-key or
113+
user-key type. The main disadvantage of encrypted keys is that if they are not
114+
rooted in a trusted key, they are only as secure as the user key encrypting
115+
them. The master user key should therefore be loaded in as secure a way as
116+
possible, preferably early in boot.
116117

117118

118119
Usage
@@ -199,6 +200,8 @@ Usage::
199200

200201
keyctl add encrypted name "new [format] key-type:master-key-name keylen"
201202
ring
203+
keyctl add encrypted name "new [format] key-type:master-key-name keylen
204+
decrypted-data" ring
202205
keyctl add encrypted name "load hex_blob" ring
203206
keyctl update keyid "update key-type:master-key-name"
204207

@@ -303,6 +306,16 @@ Load an encrypted key "evm" from saved blob::
303306
82dbbc55be2a44616e4959430436dc4f2a7a9659aa60bb4652aeb2120f149ed197c564e0
304307
24717c64 5972dcb82ab2dde83376d82b2e3c09ffc
305308

309+
Instantiate an encrypted key "evm" using user-provided decrypted data::
310+
311+
$ keyctl add encrypted evm "new default user:kmk 32 `cat evm_decrypted_data.blob`" @u
312+
794890253
313+
314+
$ keyctl print 794890253
315+
default user:kmk 32 2375725ad57798846a9bbd240de8906f006e66c03af53b1b382d
316+
bbc55be2a44616e4959430436dc4f2a7a9659aa60bb4652aeb2120f149ed197c564e0247
317+
17c64 5972dcb82ab2dde83376d82b2e3c09ffc
318+
306319
Other uses for trusted and encrypted keys, such as for disk and file encryption
307320
are anticipated. In particular the new format 'ecryptfs' has been defined
308321
in order to use encrypted keys to mount an eCryptfs filesystem. More details

MAINTAINERS

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7280,7 +7280,9 @@ Extended Verification Module (EVM)
72807280
M: Mimi Zohar <zohar@linux.ibm.com>
72817281
L: linux-integrity@vger.kernel.org
72827282
S: Supported
7283+
T: git git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git
72837284
F: security/integrity/evm/
7285+
F: security/integrity/
72847286

72857287
EXTENSIBLE FIRMWARE INTERFACE (EFI)
72867288
M: Ard Biesheuvel <ardb@kernel.org>
@@ -9537,6 +9539,7 @@ L: linux-integrity@vger.kernel.org
95379539
S: Supported
95389540
T: git git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git
95399541
F: security/integrity/ima/
9542+
F: security/integrity/
95409543

95419544
INTEL 810/815 FRAMEBUFFER DRIVER
95429545
M: Antonino Daplas <adaplas@gmail.com>
@@ -10675,6 +10678,14 @@ F: include/linux/keyctl.h
1067510678
F: include/uapi/linux/keyctl.h
1067610679
F: security/keys/
1067710680

10681+
KEYS/KEYRINGS_INTEGRITY
10682+
M: Jarkko Sakkinen <jarkko@kernel.org>
10683+
M: Mimi Zohar <zohar@linux.ibm.com>
10684+
L: linux-integrity@vger.kernel.org
10685+
L: keyrings@vger.kernel.org
10686+
S: Supported
10687+
F: security/integrity/platform_certs
10688+
1067810689
KFENCE
1067910690
M: Alexander Potapenko <glider@google.com>
1068010691
M: Marco Elver <elver@google.com>

security/integrity/evm/evm_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static int __init evm_set_fixmode(char *str)
8686
else
8787
pr_err("invalid \"%s\" mode", str);
8888

89-
return 0;
89+
return 1;
9090
}
9191
__setup("evm=", evm_set_fixmode);
9292

security/integrity/ima/ima_api.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,11 @@ int ima_collect_measurement(struct integrity_iint_cache *iint,
217217
const char *audit_cause = "failed";
218218
struct inode *inode = file_inode(file);
219219
const char *filename = file->f_path.dentry->d_name.name;
220+
struct ima_max_digest_data hash;
220221
int result = 0;
221222
int length;
222223
void *tmpbuf;
223224
u64 i_version;
224-
struct {
225-
struct ima_digest_data hdr;
226-
char digest[IMA_MAX_DIGEST_SIZE];
227-
} hash;
228225

229226
/*
230227
* Always collect the modsig, because IMA might have already collected
@@ -238,9 +235,10 @@ int ima_collect_measurement(struct integrity_iint_cache *iint,
238235
goto out;
239236

240237
/*
241-
* Dectecting file change is based on i_version. On filesystems
242-
* which do not support i_version, support is limited to an initial
243-
* measurement/appraisal/audit.
238+
* Detecting file change is based on i_version. On filesystems
239+
* which do not support i_version, support was originally limited
240+
* to an initial measurement/appraisal/audit, but was modified to
241+
* assume the file changed.
244242
*/
245243
i_version = inode_query_iversion(inode);
246244
hash.hdr.algo = algo;

security/integrity/ima/ima_fs.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -452,47 +452,61 @@ static const struct file_operations ima_measure_policy_ops = {
452452

453453
int __init ima_fs_init(void)
454454
{
455+
int ret;
456+
455457
ima_dir = securityfs_create_dir("ima", integrity_dir);
456458
if (IS_ERR(ima_dir))
457-
return -1;
459+
return PTR_ERR(ima_dir);
458460

459461
ima_symlink = securityfs_create_symlink("ima", NULL, "integrity/ima",
460462
NULL);
461-
if (IS_ERR(ima_symlink))
463+
if (IS_ERR(ima_symlink)) {
464+
ret = PTR_ERR(ima_symlink);
462465
goto out;
466+
}
463467

464468
binary_runtime_measurements =
465469
securityfs_create_file("binary_runtime_measurements",
466470
S_IRUSR | S_IRGRP, ima_dir, NULL,
467471
&ima_measurements_ops);
468-
if (IS_ERR(binary_runtime_measurements))
472+
if (IS_ERR(binary_runtime_measurements)) {
473+
ret = PTR_ERR(binary_runtime_measurements);
469474
goto out;
475+
}
470476

471477
ascii_runtime_measurements =
472478
securityfs_create_file("ascii_runtime_measurements",
473479
S_IRUSR | S_IRGRP, ima_dir, NULL,
474480
&ima_ascii_measurements_ops);
475-
if (IS_ERR(ascii_runtime_measurements))
481+
if (IS_ERR(ascii_runtime_measurements)) {
482+
ret = PTR_ERR(ascii_runtime_measurements);
476483
goto out;
484+
}
477485

478486
runtime_measurements_count =
479487
securityfs_create_file("runtime_measurements_count",
480488
S_IRUSR | S_IRGRP, ima_dir, NULL,
481489
&ima_measurements_count_ops);
482-
if (IS_ERR(runtime_measurements_count))
490+
if (IS_ERR(runtime_measurements_count)) {
491+
ret = PTR_ERR(runtime_measurements_count);
483492
goto out;
493+
}
484494

485495
violations =
486496
securityfs_create_file("violations", S_IRUSR | S_IRGRP,
487497
ima_dir, NULL, &ima_htable_violations_ops);
488-
if (IS_ERR(violations))
498+
if (IS_ERR(violations)) {
499+
ret = PTR_ERR(violations);
489500
goto out;
501+
}
490502

491503
ima_policy = securityfs_create_file("policy", POLICY_FILE_FLAGS,
492504
ima_dir, NULL,
493505
&ima_measure_policy_ops);
494-
if (IS_ERR(ima_policy))
506+
if (IS_ERR(ima_policy)) {
507+
ret = PTR_ERR(ima_policy);
495508
goto out;
509+
}
496510

497511
return 0;
498512
out:
@@ -503,5 +517,6 @@ int __init ima_fs_init(void)
503517
securityfs_remove(binary_runtime_measurements);
504518
securityfs_remove(ima_symlink);
505519
securityfs_remove(ima_dir);
506-
return -1;
520+
521+
return ret;
507522
}

security/integrity/ima/ima_init.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,9 @@ static int __init ima_add_boot_aggregate(void)
4747
struct integrity_iint_cache tmp_iint, *iint = &tmp_iint;
4848
struct ima_event_data event_data = { .iint = iint,
4949
.filename = boot_aggregate_name };
50+
struct ima_max_digest_data hash;
5051
int result = -ENOMEM;
5152
int violation = 0;
52-
struct {
53-
struct ima_digest_data hdr;
54-
char digest[TPM_MAX_DIGEST_SIZE];
55-
} hash;
5653

5754
memset(iint, 0, sizeof(*iint));
5855
memset(&hash, 0, sizeof(hash));

security/integrity/ima/ima_main.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ static int process_measurement(struct file *file, const struct cred *cred,
263263
/* reset appraisal flags if ima_inode_post_setattr was called */
264264
iint->flags &= ~(IMA_APPRAISE | IMA_APPRAISED |
265265
IMA_APPRAISE_SUBMASK | IMA_APPRAISED_SUBMASK |
266-
IMA_ACTION_FLAGS);
266+
IMA_NONACTION_FLAGS);
267267

268268
/*
269269
* Re-evaulate the file if either the xattr has changed or the
@@ -764,7 +764,7 @@ int ima_post_read_file(struct file *file, void *buf, loff_t size,
764764
* call to ima_post_load_data().
765765
*
766766
* Callers of this LSM hook can not measure, appraise, or audit the
767-
* data provided by userspace. Enforce policy rules requring a file
767+
* data provided by userspace. Enforce policy rules requiring a file
768768
* signature (eg. kexec'ed kernel image).
769769
*
770770
* For permission return 0, otherwise return -EACCES.
@@ -874,10 +874,7 @@ int process_buffer_measurement(struct user_namespace *mnt_userns,
874874
.buf = buf,
875875
.buf_len = size};
876876
struct ima_template_desc *template;
877-
struct {
878-
struct ima_digest_data hdr;
879-
char digest[IMA_MAX_DIGEST_SIZE];
880-
} hash = {};
877+
struct ima_max_digest_data hash;
881878
char digest_hash[IMA_MAX_DIGEST_SIZE];
882879
int digest_hash_len = hash_digest_size[ima_hash_algo];
883880
int violation = 0;

security/integrity/ima/ima_policy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ static int ima_lsm_update_rule(struct ima_rule_entry *entry)
428428
/*
429429
* ima_lsm_copy_rule() shallow copied all references, except for the
430430
* LSM references, from entry to nentry so we only want to free the LSM
431-
* references and the entry itself. All other memory refrences will now
431+
* references and the entry itself. All other memory references will now
432432
* be owned by nentry.
433433
*/
434434
ima_lsm_free_rule(entry);
@@ -711,7 +711,7 @@ int ima_match_policy(struct user_namespace *mnt_userns, struct inode *inode,
711711
func, mask, func_data))
712712
continue;
713713

714-
action |= entry->flags & IMA_ACTION_FLAGS;
714+
action |= entry->flags & IMA_NONACTION_FLAGS;
715715

716716
action |= entry->action & IMA_DO_MASK;
717717
if (entry->action & IMA_APPRAISE) {

security/integrity/ima/ima_template_lib.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ static int ima_eventdigest_init_common(const u8 *digest, u32 digestsize,
272272
* digest formats:
273273
* - DATA_FMT_DIGEST: digest
274274
* - DATA_FMT_DIGEST_WITH_ALGO: [<hash algo>] + ':' + '\0' + digest,
275-
* where <hash algo> is provided if the hash algoritm is not
275+
* where <hash algo> is provided if the hash algorithm is not
276276
* SHA1 or MD5
277277
*/
278278
u8 buffer[CRYPTO_MAX_ALG_NAME + 2 + IMA_MAX_DIGEST_SIZE] = { 0 };
@@ -307,10 +307,7 @@ static int ima_eventdigest_init_common(const u8 *digest, u32 digestsize,
307307
int ima_eventdigest_init(struct ima_event_data *event_data,
308308
struct ima_field_data *field_data)
309309
{
310-
struct {
311-
struct ima_digest_data hdr;
312-
char digest[IMA_MAX_DIGEST_SIZE];
313-
} hash;
310+
struct ima_max_digest_data hash;
314311
u8 *cur_digest = NULL;
315312
u32 cur_digestsize = 0;
316313
struct inode *inode;

security/integrity/integrity.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/types.h>
1616
#include <linux/integrity.h>
1717
#include <crypto/sha1.h>
18+
#include <crypto/hash.h>
1819
#include <linux/key.h>
1920
#include <linux/audit.h>
2021

@@ -30,8 +31,8 @@
3031
#define IMA_HASH 0x00000100
3132
#define IMA_HASHED 0x00000200
3233

33-
/* iint cache flags */
34-
#define IMA_ACTION_FLAGS 0xff000000
34+
/* iint policy rule cache flags */
35+
#define IMA_NONACTION_FLAGS 0xff000000
3536
#define IMA_DIGSIG_REQUIRED 0x01000000
3637
#define IMA_PERMIT_DIRECTIO 0x02000000
3738
#define IMA_NEW_FILE 0x04000000
@@ -110,6 +111,15 @@ struct ima_digest_data {
110111
u8 digest[];
111112
} __packed;
112113

114+
/*
115+
* Instead of wrapping the ima_digest_data struct inside a local structure
116+
* with the maximum hash size, define ima_max_digest_data struct.
117+
*/
118+
struct ima_max_digest_data {
119+
struct ima_digest_data hdr;
120+
u8 digest[HASH_MAX_DIGESTSIZE];
121+
} __packed;
122+
113123
/*
114124
* signature format v2 - for using with asymmetric keys
115125
*/

0 commit comments

Comments
 (0)