Skip to content

Commit 5807fca

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security
Pull security subsystem updates from James Morris: - EVM gains support for loading an x509 cert from the kernel (EVM_LOAD_X509), into the EVM trusted kernel keyring. - Smack implements 'file receive' process-based permission checking for sockets, rather than just depending on inode checks. - Misc enhancments for TPM & TPM2. - Cleanups and bugfixes for SELinux, Keys, and IMA. * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (41 commits) selinux: Inode label revalidation performance fix KEYS: refcount bug fix ima: ima_write_policy() limit locking IMA: policy can be updated zero times selinux: rate-limit netlink message warnings in selinux_nlmsg_perm() selinux: export validatetrans decisions gfs2: Invalid security labels of inodes when they go invalid selinux: Revalidate invalid inode security labels security: Add hook to invalidate inode security labels selinux: Add accessor functions for inode->i_security security: Make inode argument of inode_getsecid non-const security: Make inode argument of inode_getsecurity non-const selinux: Remove unused variable in selinux_inode_init_security keys, trusted: seal with a TPM2 authorization policy keys, trusted: select hash algorithm for TPM2 chips keys, trusted: fix: *do not* allow duplicate key options tpm_ibmvtpm: properly handle interrupted packet receptions tpm_tis: Tighten IRQ auto-probing tpm_tis: Refactor the interrupt setup tpm_tis: Get rid of the duplicate IRQ probing code ...
2 parents 2d663b5 + acb2cfd commit 5807fca

Some content is hidden

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

53 files changed

+1281
-374
lines changed

Documentation/security/keys-trusted-encrypted.txt

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,26 @@ Usage:
2727
keyctl print keyid
2828

2929
options:
30-
keyhandle= ascii hex value of sealing key default 0x40000000 (SRK)
31-
keyauth= ascii hex auth for sealing key default 0x00...i
32-
(40 ascii zeros)
33-
blobauth= ascii hex auth for sealed data default 0x00...
34-
(40 ascii zeros)
35-
blobauth= ascii hex auth for sealed data default 0x00...
36-
(40 ascii zeros)
37-
pcrinfo= ascii hex of PCR_INFO or PCR_INFO_LONG (no default)
38-
pcrlock= pcr number to be extended to "lock" blob
39-
migratable= 0|1 indicating permission to reseal to new PCR values,
40-
default 1 (resealing allowed)
30+
keyhandle= ascii hex value of sealing key default 0x40000000 (SRK)
31+
keyauth= ascii hex auth for sealing key default 0x00...i
32+
(40 ascii zeros)
33+
blobauth= ascii hex auth for sealed data default 0x00...
34+
(40 ascii zeros)
35+
blobauth= ascii hex auth for sealed data default 0x00...
36+
(40 ascii zeros)
37+
pcrinfo= ascii hex of PCR_INFO or PCR_INFO_LONG (no default)
38+
pcrlock= pcr number to be extended to "lock" blob
39+
migratable= 0|1 indicating permission to reseal to new PCR values,
40+
default 1 (resealing allowed)
41+
hash= hash algorithm name as a string. For TPM 1.x the only
42+
allowed value is sha1. For TPM 2.x the allowed values
43+
are sha1, sha256, sha384, sha512 and sm3-256.
44+
policydigest= digest for the authorization policy. must be calculated
45+
with the same hash algorithm as specified by the 'hash='
46+
option.
47+
policyhandle= handle to an authorization policy session that defines the
48+
same policy and with the same hash algorithm as was used to
49+
seal the key.
4150

4251
"keyctl print" returns an ascii hex copy of the sealed key, which is in standard
4352
TPM_STORED_DATA format. The key length for new keys are always in bytes.

crypto/asymmetric_keys/x509_public_key.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ static int x509_key_preparse(struct key_preparsed_payload *prep)
321321
goto error_free_cert;
322322
} else if (!prep->trusted) {
323323
ret = x509_validate_trust(cert, get_system_trusted_keyring());
324+
if (ret)
325+
ret = x509_validate_trust(cert, get_ima_mok_keyring());
324326
if (!ret)
325327
prep->trusted = 1;
326328
}

crypto/hash_info.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const char *const hash_algo_name[HASH_ALGO__LAST] = {
3131
[HASH_ALGO_TGR_128] = "tgr128",
3232
[HASH_ALGO_TGR_160] = "tgr160",
3333
[HASH_ALGO_TGR_192] = "tgr192",
34+
[HASH_ALGO_SM3_256] = "sm3-256",
3435
};
3536
EXPORT_SYMBOL_GPL(hash_algo_name);
3637

@@ -52,5 +53,6 @@ const int hash_digest_size[HASH_ALGO__LAST] = {
5253
[HASH_ALGO_TGR_128] = TGR128_DIGEST_SIZE,
5354
[HASH_ALGO_TGR_160] = TGR160_DIGEST_SIZE,
5455
[HASH_ALGO_TGR_192] = TGR192_DIGEST_SIZE,
56+
[HASH_ALGO_SM3_256] = SM3256_DIGEST_SIZE,
5557
};
5658
EXPORT_SYMBOL_GPL(hash_digest_size);

drivers/char/tpm/tpm-interface.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,12 @@ unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip,
310310
{
311311
int duration_idx = TPM_UNDEFINED;
312312
int duration = 0;
313-
u8 category = (ordinal >> 24) & 0xFF;
314313

315-
if ((category == TPM_PROTECTED_COMMAND && ordinal < TPM_MAX_ORDINAL) ||
316-
(category == TPM_CONNECTION_COMMAND && ordinal < TSC_MAX_ORDINAL))
314+
/*
315+
* We only have a duration table for protected commands, where the upper
316+
* 16 bits are 0. For the few other ordinals the fallback will be used.
317+
*/
318+
if (ordinal < TPM_MAX_ORDINAL)
317319
duration_idx = tpm_ordinal_duration[ordinal];
318320

319321
if (duration_idx != TPM_UNDEFINED)
@@ -501,6 +503,21 @@ int tpm_get_timeouts(struct tpm_chip *chip)
501503
struct duration_t *duration_cap;
502504
ssize_t rc;
503505

506+
if (chip->flags & TPM_CHIP_FLAG_TPM2) {
507+
/* Fixed timeouts for TPM2 */
508+
chip->vendor.timeout_a = msecs_to_jiffies(TPM2_TIMEOUT_A);
509+
chip->vendor.timeout_b = msecs_to_jiffies(TPM2_TIMEOUT_B);
510+
chip->vendor.timeout_c = msecs_to_jiffies(TPM2_TIMEOUT_C);
511+
chip->vendor.timeout_d = msecs_to_jiffies(TPM2_TIMEOUT_D);
512+
chip->vendor.duration[TPM_SHORT] =
513+
msecs_to_jiffies(TPM2_DURATION_SHORT);
514+
chip->vendor.duration[TPM_MEDIUM] =
515+
msecs_to_jiffies(TPM2_DURATION_MEDIUM);
516+
chip->vendor.duration[TPM_LONG] =
517+
msecs_to_jiffies(TPM2_DURATION_LONG);
518+
return 0;
519+
}
520+
504521
tpm_cmd.header.in = tpm_getcap_header;
505522
tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP;
506523
tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);

drivers/char/tpm/tpm.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,20 @@ enum tpm2_structures {
8383
};
8484

8585
enum tpm2_return_codes {
86-
TPM2_RC_INITIALIZE = 0x0100,
87-
TPM2_RC_TESTING = 0x090A,
86+
TPM2_RC_HASH = 0x0083, /* RC_FMT1 */
87+
TPM2_RC_INITIALIZE = 0x0100, /* RC_VER1 */
8888
TPM2_RC_DISABLED = 0x0120,
89+
TPM2_RC_TESTING = 0x090A, /* RC_WARN */
8990
};
9091

9192
enum tpm2_algorithms {
9293
TPM2_ALG_SHA1 = 0x0004,
9394
TPM2_ALG_KEYEDHASH = 0x0008,
9495
TPM2_ALG_SHA256 = 0x000B,
95-
TPM2_ALG_NULL = 0x0010
96+
TPM2_ALG_SHA384 = 0x000C,
97+
TPM2_ALG_SHA512 = 0x000D,
98+
TPM2_ALG_NULL = 0x0010,
99+
TPM2_ALG_SM3_256 = 0x0012,
96100
};
97101

98102
enum tpm2_command_codes {
@@ -138,7 +142,6 @@ struct tpm_vendor_specific {
138142
unsigned long base; /* TPM base address */
139143

140144
int irq;
141-
int probed_irq;
142145

143146
int region_size;
144147
int have_region;

drivers/char/tpm/tpm2-cmd.c

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
#include "tpm.h"
19+
#include <crypto/hash_info.h>
1920
#include <keys/trusted-type.h>
2021

2122
enum tpm2_object_attributes {
@@ -104,6 +105,19 @@ struct tpm2_cmd {
104105
union tpm2_cmd_params params;
105106
} __packed;
106107

108+
struct tpm2_hash {
109+
unsigned int crypto_id;
110+
unsigned int tpm_id;
111+
};
112+
113+
static struct tpm2_hash tpm2_hash_map[] = {
114+
{HASH_ALGO_SHA1, TPM2_ALG_SHA1},
115+
{HASH_ALGO_SHA256, TPM2_ALG_SHA256},
116+
{HASH_ALGO_SHA384, TPM2_ALG_SHA384},
117+
{HASH_ALGO_SHA512, TPM2_ALG_SHA512},
118+
{HASH_ALGO_SM3_256, TPM2_ALG_SM3_256},
119+
};
120+
107121
/*
108122
* Array with one entry per ordinal defining the maximum amount
109123
* of time the chip could take to return the result. The values
@@ -429,8 +443,20 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
429443
{
430444
unsigned int blob_len;
431445
struct tpm_buf buf;
446+
u32 hash;
447+
int i;
432448
int rc;
433449

450+
for (i = 0; i < ARRAY_SIZE(tpm2_hash_map); i++) {
451+
if (options->hash == tpm2_hash_map[i].crypto_id) {
452+
hash = tpm2_hash_map[i].tpm_id;
453+
break;
454+
}
455+
}
456+
457+
if (i == ARRAY_SIZE(tpm2_hash_map))
458+
return -EINVAL;
459+
434460
rc = tpm_buf_init(&buf, TPM2_ST_SESSIONS, TPM2_CC_CREATE);
435461
if (rc)
436462
return rc;
@@ -452,12 +478,26 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
452478
tpm_buf_append_u8(&buf, payload->migratable);
453479

454480
/* public */
455-
tpm_buf_append_u16(&buf, 14);
481+
if (options->policydigest)
482+
tpm_buf_append_u16(&buf, 14 + options->digest_len);
483+
else
484+
tpm_buf_append_u16(&buf, 14);
456485

457486
tpm_buf_append_u16(&buf, TPM2_ALG_KEYEDHASH);
458-
tpm_buf_append_u16(&buf, TPM2_ALG_SHA256);
459-
tpm_buf_append_u32(&buf, TPM2_ATTR_USER_WITH_AUTH);
460-
tpm_buf_append_u16(&buf, 0); /* policy digest size */
487+
tpm_buf_append_u16(&buf, hash);
488+
489+
/* policy */
490+
if (options->policydigest) {
491+
tpm_buf_append_u32(&buf, 0);
492+
tpm_buf_append_u16(&buf, options->digest_len);
493+
tpm_buf_append(&buf, options->policydigest,
494+
options->digest_len);
495+
} else {
496+
tpm_buf_append_u32(&buf, TPM2_ATTR_USER_WITH_AUTH);
497+
tpm_buf_append_u16(&buf, 0);
498+
}
499+
500+
/* public parameters */
461501
tpm_buf_append_u16(&buf, TPM2_ALG_NULL);
462502
tpm_buf_append_u16(&buf, 0);
463503

@@ -488,8 +528,12 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
488528
out:
489529
tpm_buf_destroy(&buf);
490530

491-
if (rc > 0)
492-
rc = -EPERM;
531+
if (rc > 0) {
532+
if ((rc & TPM2_RC_HASH) == TPM2_RC_HASH)
533+
rc = -EINVAL;
534+
else
535+
rc = -EPERM;
536+
}
493537

494538
return rc;
495539
}
@@ -583,7 +627,9 @@ static int tpm2_unseal(struct tpm_chip *chip,
583627
return rc;
584628

585629
tpm_buf_append_u32(&buf, blob_handle);
586-
tpm2_buf_append_auth(&buf, TPM2_RS_PW,
630+
tpm2_buf_append_auth(&buf,
631+
options->policyhandle ?
632+
options->policyhandle : TPM2_RS_PW,
587633
NULL /* nonce */, 0,
588634
0 /* session_attributes */,
589635
options->blobauth /* hmac */,

drivers/char/tpm/tpm_crb.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,17 +284,9 @@ static int crb_acpi_add(struct acpi_device *device)
284284

285285
chip->vendor.priv = priv;
286286

287-
/* Default timeouts and durations */
288-
chip->vendor.timeout_a = msecs_to_jiffies(TPM2_TIMEOUT_A);
289-
chip->vendor.timeout_b = msecs_to_jiffies(TPM2_TIMEOUT_B);
290-
chip->vendor.timeout_c = msecs_to_jiffies(TPM2_TIMEOUT_C);
291-
chip->vendor.timeout_d = msecs_to_jiffies(TPM2_TIMEOUT_D);
292-
chip->vendor.duration[TPM_SHORT] =
293-
msecs_to_jiffies(TPM2_DURATION_SHORT);
294-
chip->vendor.duration[TPM_MEDIUM] =
295-
msecs_to_jiffies(TPM2_DURATION_MEDIUM);
296-
chip->vendor.duration[TPM_LONG] =
297-
msecs_to_jiffies(TPM2_DURATION_LONG);
287+
rc = tpm_get_timeouts(chip);
288+
if (rc)
289+
return rc;
298290

299291
chip->acpi_dev_handle = device->handle;
300292

drivers/char/tpm/tpm_ibmvtpm.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static int tpm_ibmvtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count)
9090
return 0;
9191
}
9292

93-
sig = wait_event_interruptible(ibmvtpm->wq, ibmvtpm->res_len != 0);
93+
sig = wait_event_interruptible(ibmvtpm->wq, !ibmvtpm->tpm_processing_cmd);
9494
if (sig)
9595
return -EINTR;
9696

@@ -125,7 +125,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
125125
struct ibmvtpm_dev *ibmvtpm;
126126
struct ibmvtpm_crq crq;
127127
__be64 *word = (__be64 *)&crq;
128-
int rc;
128+
int rc, sig;
129129

130130
ibmvtpm = (struct ibmvtpm_dev *)TPM_VPRIV(chip);
131131

@@ -141,18 +141,35 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
141141
return -EIO;
142142
}
143143

144+
if (ibmvtpm->tpm_processing_cmd) {
145+
dev_info(ibmvtpm->dev,
146+
"Need to wait for TPM to finish\n");
147+
/* wait for previous command to finish */
148+
sig = wait_event_interruptible(ibmvtpm->wq, !ibmvtpm->tpm_processing_cmd);
149+
if (sig)
150+
return -EINTR;
151+
}
152+
144153
spin_lock(&ibmvtpm->rtce_lock);
154+
ibmvtpm->res_len = 0;
145155
memcpy((void *)ibmvtpm->rtce_buf, (void *)buf, count);
146156
crq.valid = (u8)IBMVTPM_VALID_CMD;
147157
crq.msg = (u8)VTPM_TPM_COMMAND;
148158
crq.len = cpu_to_be16(count);
149159
crq.data = cpu_to_be32(ibmvtpm->rtce_dma_handle);
150160

161+
/*
162+
* set the processing flag before the Hcall, since we may get the
163+
* result (interrupt) before even being able to check rc.
164+
*/
165+
ibmvtpm->tpm_processing_cmd = true;
166+
151167
rc = ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]),
152168
be64_to_cpu(word[1]));
153169
if (rc != H_SUCCESS) {
154170
dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed rc=%d\n", rc);
155171
rc = 0;
172+
ibmvtpm->tpm_processing_cmd = false;
156173
} else
157174
rc = count;
158175

@@ -515,6 +532,7 @@ static void ibmvtpm_crq_process(struct ibmvtpm_crq *crq,
515532
case VTPM_TPM_COMMAND_RES:
516533
/* len of the data in rtce buffer */
517534
ibmvtpm->res_len = be16_to_cpu(crq->len);
535+
ibmvtpm->tpm_processing_cmd = false;
518536
wake_up_interruptible(&ibmvtpm->wq);
519537
return;
520538
default:

drivers/char/tpm/tpm_ibmvtpm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct ibmvtpm_dev {
4545
wait_queue_head_t wq;
4646
u16 res_len;
4747
u32 vtpm_version;
48+
bool tpm_processing_cmd;
4849
};
4950

5051
#define CRQ_RES_BUF_SIZE PAGE_SIZE

0 commit comments

Comments
 (0)