Skip to content

Commit 55b3a0c

Browse files
committed
Merge branch 'next-general' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security
Pull general security subsystem updates from James Morris: "TPM (from Jarkko): - essential clean up for tpm_crb so that ARM64 and x86 versions do not distract each other as much as before - /dev/tpm0 rejects now too short writes (shorter buffer than specified in the command header - use DMA-safe buffer in tpm_tis_spi - otherwise mostly minor fixes. Smack: - base support for overlafs Capabilities: - BPRM_FCAPS fixes, from Richard Guy Briggs: The audit subsystem is adding a BPRM_FCAPS record when auditing setuid application execution (SYSCALL execve). This is not expected as it was supposed to be limited to when the file system actually had capabilities in an extended attribute. It lists all capabilities making the event really ugly to parse what is happening. The PATH record correctly records the setuid bit and owner. Suppress the BPRM_FCAPS record on set*id. TOMOYO: - Y2038 timestamping fixes" * 'next-general' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (28 commits) MAINTAINERS: update the IMA, EVM, trusted-keys, encrypted-keys entries Smack: Base support for overlayfs MAINTAINERS: remove David Safford as maintainer for encrypted+trusted keys tomoyo: fix timestamping for y2038 capabilities: audit log other surprising conditions capabilities: fix logic for effective root or real root capabilities: invert logic for clarity capabilities: remove a layer of conditional logic capabilities: move audit log decision to function capabilities: use intuitive names for id changes capabilities: use root_priveleged inline to clarify logic capabilities: rename has_cap to has_fcap capabilities: intuitive names for cap gain status capabilities: factor out cap_bprm_set_creds privileged root tpm, tpm_tis: use ARRAY_SIZE() to define TPM_HID_USR_IDX tpm: fix duplicate inline declaration specifier tpm: fix type of a local variables in tpm_tis_spi.c tpm: fix type of a local variable in tpm2_map_command() tpm: fix type of a local variable in tpm2_get_cc_attrs_tbl() tpm-dev-common: Reject too short writes ...
2 parents dee0277 + 34d8751 commit 55b3a0c

17 files changed

Lines changed: 385 additions & 279 deletions

‎MAINTAINERS‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5219,8 +5219,7 @@ F: fs/ext4/
52195219

52205220
Extended Verification Module (EVM)
52215221
M: Mimi Zohar <zohar@linux.vnet.ibm.com>
5222-
L: linux-ima-devel@lists.sourceforge.net
5223-
L: linux-security-module@vger.kernel.org
5222+
L: linux-integrity@vger.kernel.org
52245223
S: Supported
52255224
F: security/integrity/evm/
52265225

@@ -6847,9 +6846,7 @@ L: linux-crypto@vger.kernel.org
68476846
INTEGRITY MEASUREMENT ARCHITECTURE (IMA)
68486847
M: Mimi Zohar <zohar@linux.vnet.ibm.com>
68496848
M: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>
6850-
L: linux-ima-devel@lists.sourceforge.net
6851-
L: linux-ima-user@lists.sourceforge.net
6852-
L: linux-security-module@vger.kernel.org
6849+
L: linux-integrity@vger.kernel.org
68536850
T: git git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git
68546851
S: Supported
68556852
F: security/integrity/ima/
@@ -7632,18 +7629,16 @@ F: kernel/kexec*
76327629

76337630
KEYS-ENCRYPTED
76347631
M: Mimi Zohar <zohar@linux.vnet.ibm.com>
7635-
M: David Safford <safford@us.ibm.com>
7636-
L: linux-security-module@vger.kernel.org
7632+
L: linux-integrity@vger.kernel.org
76377633
L: keyrings@vger.kernel.org
76387634
S: Supported
76397635
F: Documentation/security/keys/trusted-encrypted.rst
76407636
F: include/keys/encrypted-type.h
76417637
F: security/keys/encrypted-keys/
76427638

76437639
KEYS-TRUSTED
7644-
M: David Safford <safford@us.ibm.com>
76457640
M: Mimi Zohar <zohar@linux.vnet.ibm.com>
7646-
L: linux-security-module@vger.kernel.org
7641+
L: linux-integrity@vger.kernel.org
76477642
L: keyrings@vger.kernel.org
76487643
S: Supported
76497644
F: Documentation/security/keys/trusted-encrypted.rst

‎drivers/char/tpm/tpm-dev-common.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ ssize_t tpm_common_write(struct file *file, const char __user *buf,
110110
return -EFAULT;
111111
}
112112

113+
if (in_size < 6 ||
114+
in_size < be32_to_cpu(*((__be32 *) (priv->data_buffer + 2)))) {
115+
mutex_unlock(&priv->buffer_mutex);
116+
return -EINVAL;
117+
}
118+
113119
/* atomic tpm command send and result receive. We only hold the ops
114120
* lock during this period so that the tpm can be unregistered even if
115121
* the char dev is held open.

‎drivers/char/tpm/tpm-sysfs.c‎

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,48 @@
2020
#include <linux/device.h>
2121
#include "tpm.h"
2222

23-
#define READ_PUBEK_RESULT_SIZE 314
23+
struct tpm_readpubek_out {
24+
u8 algorithm[4];
25+
u8 encscheme[2];
26+
u8 sigscheme[2];
27+
__be32 paramsize;
28+
u8 parameters[12];
29+
__be32 keysize;
30+
u8 modulus[256];
31+
u8 checksum[20];
32+
} __packed;
33+
2434
#define READ_PUBEK_RESULT_MIN_BODY_SIZE (28 + 256)
2535
#define TPM_ORD_READPUBEK 124
26-
static const struct tpm_input_header tpm_readpubek_header = {
27-
.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
28-
.length = cpu_to_be32(30),
29-
.ordinal = cpu_to_be32(TPM_ORD_READPUBEK)
30-
};
36+
3137
static ssize_t pubek_show(struct device *dev, struct device_attribute *attr,
3238
char *buf)
3339
{
34-
u8 *data;
35-
struct tpm_cmd_t tpm_cmd;
36-
ssize_t err;
37-
int i, rc;
40+
struct tpm_buf tpm_buf;
41+
struct tpm_readpubek_out *out;
42+
ssize_t rc;
43+
int i;
3844
char *str = buf;
3945
struct tpm_chip *chip = to_tpm_chip(dev);
46+
char anti_replay[20];
4047

41-
memset(&tpm_cmd, 0, sizeof(tpm_cmd));
42-
43-
tpm_cmd.header.in = tpm_readpubek_header;
44-
err = tpm_transmit_cmd(chip, NULL, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
45-
READ_PUBEK_RESULT_MIN_BODY_SIZE, 0,
46-
"attempting to read the PUBEK");
47-
if (err)
48-
goto out;
49-
50-
/*
51-
ignore header 10 bytes
52-
algorithm 32 bits (1 == RSA )
53-
encscheme 16 bits
54-
sigscheme 16 bits
55-
parameters (RSA 12->bytes: keybit, #primes, expbit)
56-
keylenbytes 32 bits
57-
256 byte modulus
58-
ignore checksum 20 bytes
59-
*/
60-
data = tpm_cmd.params.readpubek_out_buffer;
48+
memset(&anti_replay, 0, sizeof(anti_replay));
49+
50+
rc = tpm_buf_init(&tpm_buf, TPM_TAG_RQU_COMMAND, TPM_ORD_READPUBEK);
51+
if (rc)
52+
return rc;
53+
54+
tpm_buf_append(&tpm_buf, anti_replay, sizeof(anti_replay));
55+
56+
rc = tpm_transmit_cmd(chip, NULL, tpm_buf.data, PAGE_SIZE,
57+
READ_PUBEK_RESULT_MIN_BODY_SIZE, 0,
58+
"attempting to read the PUBEK");
59+
if (rc) {
60+
tpm_buf_destroy(&tpm_buf);
61+
return 0;
62+
}
63+
64+
out = (struct tpm_readpubek_out *)&tpm_buf.data[10];
6165
str +=
6266
sprintf(str,
6367
"Algorithm: %02X %02X %02X %02X\n"
@@ -68,21 +72,26 @@ static ssize_t pubek_show(struct device *dev, struct device_attribute *attr,
6872
"%02X %02X %02X %02X\n"
6973
"Modulus length: %d\n"
7074
"Modulus:\n",
71-
data[0], data[1], data[2], data[3],
72-
data[4], data[5],
73-
data[6], data[7],
74-
data[12], data[13], data[14], data[15],
75-
data[16], data[17], data[18], data[19],
76-
data[20], data[21], data[22], data[23],
77-
be32_to_cpu(*((__be32 *) (data + 24))));
75+
out->algorithm[0], out->algorithm[1], out->algorithm[2],
76+
out->algorithm[3],
77+
out->encscheme[0], out->encscheme[1],
78+
out->sigscheme[0], out->sigscheme[1],
79+
out->parameters[0], out->parameters[1],
80+
out->parameters[2], out->parameters[3],
81+
out->parameters[4], out->parameters[5],
82+
out->parameters[6], out->parameters[7],
83+
out->parameters[8], out->parameters[9],
84+
out->parameters[10], out->parameters[11],
85+
be32_to_cpu(out->keysize));
7886

7987
for (i = 0; i < 256; i++) {
80-
str += sprintf(str, "%02X ", data[i + 28]);
88+
str += sprintf(str, "%02X ", out->modulus[i]);
8189
if ((i + 1) % 16 == 0)
8290
str += sprintf(str, "\n");
8391
}
84-
out:
92+
8593
rc = str - buf;
94+
tpm_buf_destroy(&tpm_buf);
8695
return rc;
8796
}
8897
static DEVICE_ATTR_RO(pubek);

‎drivers/char/tpm/tpm.h‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -345,17 +345,6 @@ enum tpm_sub_capabilities {
345345
TPM_CAP_PROP_TIS_DURATION = 0x120,
346346
};
347347

348-
struct tpm_readpubek_params_out {
349-
u8 algorithm[4];
350-
u8 encscheme[2];
351-
u8 sigscheme[2];
352-
__be32 paramsize;
353-
u8 parameters[12]; /*assuming RSA*/
354-
__be32 keysize;
355-
u8 modulus[256];
356-
u8 checksum[20];
357-
} __packed;
358-
359348
typedef union {
360349
struct tpm_input_header in;
361350
struct tpm_output_header out;
@@ -385,8 +374,6 @@ struct tpm_getrandom_in {
385374
} __packed;
386375

387376
typedef union {
388-
struct tpm_readpubek_params_out readpubek_out;
389-
u8 readpubek_out_buffer[sizeof(struct tpm_readpubek_params_out)];
390377
struct tpm_pcrread_in pcrread_in;
391378
struct tpm_pcrread_out pcrread_out;
392379
struct tpm_getrandom_in getrandom_in;
@@ -557,7 +544,7 @@ static inline void tpm_add_ppi(struct tpm_chip *chip)
557544
}
558545
#endif
559546

560-
static inline inline u32 tpm2_rc_value(u32 rc)
547+
static inline u32 tpm2_rc_value(u32 rc)
561548
{
562549
return (rc & BIT(7)) ? rc & 0xff : rc;
563550
}

‎drivers/char/tpm/tpm2-cmd.c‎

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -834,72 +834,43 @@ static const struct tpm_input_header tpm2_selftest_header = {
834834
};
835835

836836
/**
837-
* tpm2_continue_selftest() - start a self test
838-
*
839-
* @chip: TPM chip to use
840-
* @full: test all commands instead of testing only those that were not
841-
* previously tested.
842-
*
843-
* Return: Same as with tpm_transmit_cmd with exception of RC_TESTING.
844-
*/
845-
static int tpm2_start_selftest(struct tpm_chip *chip, bool full)
846-
{
847-
int rc;
848-
struct tpm2_cmd cmd;
849-
850-
cmd.header.in = tpm2_selftest_header;
851-
cmd.params.selftest_in.full_test = full;
852-
853-
rc = tpm_transmit_cmd(chip, NULL, &cmd, TPM2_SELF_TEST_IN_SIZE, 0, 0,
854-
"continue selftest");
855-
856-
/* At least some prototype chips seem to give RC_TESTING error
857-
* immediately. This is a workaround for that.
858-
*/
859-
if (rc == TPM2_RC_TESTING) {
860-
dev_warn(&chip->dev, "Got RC_TESTING, ignoring\n");
861-
rc = 0;
862-
}
863-
864-
return rc;
865-
}
866-
867-
/**
868-
* tpm2_do_selftest() - run a full self test
837+
* tpm2_do_selftest() - ensure that all self tests have passed
869838
*
870839
* @chip: TPM chip to use
871840
*
872841
* Return: Same as with tpm_transmit_cmd.
873842
*
874-
* During the self test TPM2 commands return with the error code RC_TESTING.
875-
* Waiting is done by issuing PCR read until it executes successfully.
843+
* The TPM can either run all self tests synchronously and then return
844+
* RC_SUCCESS once all tests were successful. Or it can choose to run the tests
845+
* asynchronously and return RC_TESTING immediately while the self tests still
846+
* execute in the background. This function handles both cases and waits until
847+
* all tests have completed.
876848
*/
877849
static int tpm2_do_selftest(struct tpm_chip *chip)
878850
{
879851
int rc;
880-
unsigned int loops;
881-
unsigned int delay_msec = 100;
882-
unsigned long duration;
883-
int i;
884-
885-
duration = tpm2_calc_ordinal_duration(chip, TPM2_CC_SELF_TEST);
852+
unsigned int delay_msec = 20;
853+
long duration;
854+
struct tpm2_cmd cmd;
886855

887-
loops = jiffies_to_msecs(duration) / delay_msec;
856+
duration = jiffies_to_msecs(
857+
tpm2_calc_ordinal_duration(chip, TPM2_CC_SELF_TEST));
888858

889-
rc = tpm2_start_selftest(chip, true);
890-
if (rc)
891-
return rc;
859+
while (duration > 0) {
860+
cmd.header.in = tpm2_selftest_header;
861+
cmd.params.selftest_in.full_test = 0;
892862

893-
for (i = 0; i < loops; i++) {
894-
/* Attempt to read a PCR value */
895-
rc = tpm2_pcr_read(chip, 0, NULL);
896-
if (rc < 0)
897-
break;
863+
rc = tpm_transmit_cmd(chip, NULL, &cmd, TPM2_SELF_TEST_IN_SIZE,
864+
0, 0, "continue selftest");
898865

899866
if (rc != TPM2_RC_TESTING)
900867
break;
901868

902869
tpm_msleep(delay_msec);
870+
duration -= delay_msec;
871+
872+
/* wait longer the next round */
873+
delay_msec *= 2;
903874
}
904875

905876
return rc;
@@ -1009,7 +980,7 @@ static int tpm2_get_cc_attrs_tbl(struct tpm_chip *chip)
1009980
{
1010981
struct tpm_buf buf;
1011982
u32 nr_commands;
1012-
u32 *attrs;
983+
__be32 *attrs;
1013984
u32 cc;
1014985
int i;
1015986
int rc;
@@ -1049,7 +1020,7 @@ static int tpm2_get_cc_attrs_tbl(struct tpm_chip *chip)
10491020

10501021
chip->nr_commands = nr_commands;
10511022

1052-
attrs = (u32 *)&buf.data[TPM_HEADER_SIZE + 9];
1023+
attrs = (__be32 *)&buf.data[TPM_HEADER_SIZE + 9];
10531024
for (i = 0; i < nr_commands; i++, attrs++) {
10541025
chip->cc_attrs_tbl[i] = be32_to_cpup(attrs);
10551026
cc = chip->cc_attrs_tbl[i] & 0xFFFF;

‎drivers/char/tpm/tpm2-space.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static int tpm2_map_command(struct tpm_chip *chip, u32 cc, u8 *cmd)
242242
struct tpm_space *space = &chip->work_space;
243243
unsigned int nr_handles;
244244
u32 attrs;
245-
u32 *handle;
245+
__be32 *handle;
246246
int i;
247247

248248
i = tpm2_find_cc(chip, cc);
@@ -252,7 +252,7 @@ static int tpm2_map_command(struct tpm_chip *chip, u32 cc, u8 *cmd)
252252
attrs = chip->cc_attrs_tbl[i];
253253
nr_handles = (attrs >> TPM2_CC_ATTR_CHANDLES) & GENMASK(2, 0);
254254

255-
handle = (u32 *)&cmd[TPM_HEADER_SIZE];
255+
handle = (__be32 *)&cmd[TPM_HEADER_SIZE];
256256
for (i = 0; i < nr_handles; i++, handle++) {
257257
if ((be32_to_cpu(*handle) & 0xFF000000) == TPM2_HT_TRANSIENT) {
258258
if (!tpm2_map_to_phandle(space, handle))

0 commit comments

Comments
 (0)