Fix kernel buffer overruns caused by bit flips
Subsystems (2)
James Bottomley
maintainerv2 cover Fix kernel buffer overruns caused by bit flips
If a TPM is attached to a system via a serial bus on a platform that suffers bit flips, we can get back dangerously wrong data. This patch series aims never to do a direct copy into a kernel buffer based on an unchecked size value returned from the TPM.
Jeremy Boone (5):
tpm: fix potential buffer overruns caused by bit glitches on the bus
tpm: st33zp24: fix potential buffer overruns caused by bit glitches on
the bus
tpm_i2c_infineon: fix potential buffer overruns caused by bit glitches
on the bus
tpm_i2c_nuvoton: fix potential buffer overruns caused by bit glitches
on the bus
tpm_tis: fix potential buffer overruns caused by bit glitches on the
bus
drivers/char/tpm/st33zp24/st33zp24.c | 4 ++-- drivers/char/tpm/tpm-interface.c | 4 ++++ drivers/char/tpm/tpm2-cmd.c | 4 ++++ drivers/char/tpm/tpm_i2c_infineon.c | 5 +++-- drivers/char/tpm/tpm_i2c_nuvoton.c | 5 +++-- drivers/char/tpm/tpm_tis_core.c | 5 +++-- 6 files changed, 19 insertions(+), 8 deletions(-)
Signature · 1 line
2.12.3
James Bottomley
maintainerPATCH v2 2/5 tpm: st33zp24: fix potential buffer overruns caused by bit glitches on the bus
From: Jeremy Boone <[email protected]>
Discrete TPMs are often connected over slow serial buses which, on some platforms, can have glitches causing bit flips. In all the driver _recv() functions, we need to use a u32 to unmarshal the response size, otherwise a bit flip of the 31st bit would cause the expected variable to go negative, which would then try to read a huge amount of data. Also sanity check that the expected amount of data is large enough for the TPM header.
--- drivers/char/tpm/st33zp24/st33zp24.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/char/tpm/st33zp24/st33zp24.c +2 -2
@@ -457,7 +457,7 @@ static int st33zp24_recv(struct tpm_chip *chip, unsigned char *buf, size_t count) {int size =0 ; -int expected; +u32 expected;if (!chip)return -EBUSY ;
@@ -474,7 +474,7 @@ static int st33zp24_recv(struct tpm_chip *chip, unsigned char *buf, } expected =be32_to_cpu (*(__be32 *)(buf +2 )); -if (expected > count) { +if (expected > count || expected <TPM_HEADER_SIZE ) { size = -EIO ; goto out; }
Signature · 1 line
2.12.3
James Bottomley
maintainerPATCH v2 3/5 tpm_i2c_infineon: fix potential buffer overruns caused by bit glitches on the bus
In reply to James BottomleyFrom: Jeremy Boone <[email protected]>
Discrete TPMs are often connected over slow serial buses which, on some platforms, can have glitches causing bit flips. In all the driver _recv() functions, we need to use a u32 to unmarshal the response size, otherwise a bit flip of the 31st bit would cause the expected variable to go negative, which would then try to read a huge amount of data. Also sanity check that the expected amount of data is large enough for the TPM header.
--- drivers/char/tpm/tpm_i2c_infineon.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/char/tpm/tpm_i2c_infineon.c +3 -2
@@ -473,7 +473,8 @@ static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)static int tpm_tis_i2c_recv (struct tpm_chip *chip,u8 *buf,size_t count) {int size =0 ; -int expected, status; +int status; +u32 expected;if (count <TPM_HEADER_SIZE ) { size = -EIO ;
@@ -488,7 +489,7 @@ static int tpm_tis_i2c_recv(struct tpm_chip *chip, u8 *buf, size_t count) } expected =be32_to_cpu (*(__be32 *)(buf +2 )); -if ((size_t ) expected > count) { +if (((size_t ) expected > count) || (expected <TPM_HEADER_SIZE )) { size = -EIO ; goto out; }
Signature · 1 line
2.12.3
James Bottomley
maintainerPATCH v2 4/5 tpm_i2c_nuvoton: fix potential buffer overruns caused by bit glitches on the bus
In reply to James BottomleyFrom: Jeremy Boone <[email protected]>
Discrete TPMs are often connected over slow serial buses which, on some platforms, can have glitches causing bit flips. In all the driver _recv() functions, we need to use a u32 to unmarshal the response size, otherwise a bit flip of the 31st bit would cause the expected variable to go negative, which would then try to read a huge amount of data. Also sanity check that the expected amount of data is large enough for the TPM header.
--- drivers/char/tpm/tpm_i2c_nuvoton.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/char/tpm/tpm_i2c_nuvoton.c +3 -2
@@ -281,7 +281,8 @@ static int i2c_nuvoton_recv(struct tpm_chip *chip, u8 *buf, size_t count)struct device *dev = chip->dev.parent;struct i2c_client *client =to_i2c_client (dev);s32 rc; -int expected, status, burst_count, retries, size =0 ; +int status, burst_count, retries, size =0 ; +u32 expected;if (count <TPM_HEADER_SIZE ) {i2c_nuvoton_ready (chip);/* return to idle */
@@ -323,7 +324,7 @@ static int i2c_nuvoton_recv(struct tpm_chip *chip, u8 *buf, size_t count)* to machine native */ expected =be32_to_cpu (*(__be32 *) (buf +2 )); -if (expected > count) { +if (expected > count || expected < size) {dev_err (dev,"%s() expected > count\n" , __func__); size = -EIO ;continue ;
Signature · 1 line
2.12.3
James Bottomley
maintainerPATCH v2 5/5 tpm_tis: fix potential buffer overruns caused by bit glitches on the bus
In reply to James BottomleyFrom: Jeremy Boone <[email protected]>
Discrete TPMs are often connected over slow serial buses which, on some platforms, can have glitches causing bit flips. In all the driver _recv() functions, we need to use a u32 to unmarshal the response size, otherwise a bit flip of the 31st bit would cause the expected variable to go negative, which would then try to read a huge amount of data. Also sanity check that the expected amount of data is large enough for the TPM header.
--- drivers/char/tpm/tpm_tis_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/char/tpm/tpm_tis_core.c +3 -2
@@ -202,7 +202,8 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count) {struct tpm_tis_data *priv =dev_get_drvdata (&chip->dev);int size =0 ; -int expected, status; +int status; +u32 expected;if (count <TPM_HEADER_SIZE ) { size = -EIO ;
@@ -217,7 +218,7 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count) } expected =be32_to_cpu (*(__be32 *) (buf +2 )); -if (expected > count) { +if (expected > count || expected <TPM_HEADER_SIZE ) { size = -EIO ; goto out; }
Signature · 1 line
2.12.3
Quoted 16 lines · James Bottomley
If a TPM is attached to a system via a serial bus on a platform that suffers bit flips, we can get back dangerously wrong data. This patch series aims never to do a direct copy into a kernel buffer based on an unchecked size value returned from the TPM.
Jeremy Boone (5):
tpm: fix potential buffer overruns caused by bit glitches on the bus
tpm: st33zp24: fix potential buffer overruns caused by bit glitches on
the bus
tpm_i2c_infineon: fix potential buffer overruns caused by bit glitches
on the bus
tpm_i2c_nuvoton: fix potential buffer overruns caused by bit glitches
on the bus
tpm_tis: fix potential buffer overruns caused by bit glitches on the
bus
Quoted 10 lines
drivers/char/tpm/st33zp24/st33zp24.c | 4 ++-- drivers/char/tpm/tpm-interface.c | 4 ++++ drivers/char/tpm/tpm2-cmd.c | 4 ++++ drivers/char/tpm/tpm_i2c_infineon.c | 5 +++-- drivers/char/tpm/tpm_i2c_nuvoton.c | 5 +++-- drivers/char/tpm/tpm_tis_core.c | 5 +++-- 6 files changed, 19 insertions(+), 8 deletions(-)Signature · 1 line
o 2.12.3
I cannot test all of these but I'll put these to linux-next anyway. The changes are obvious and small scoped so if no one shouts they'll be part of the next PR.
I've tested the changes that affect tpm2-cmd.c, tpm-interface.c and tpm_tis_core.c. For HW specific changes tested-by's would be much appreciated but I don't think they will break anything.
Because these are quite critical fixes I wonder if I could do one more PR to 4.16?
/Jarkko
James Bottomley
maintainerQuoted 41 lines · Jarkko Sakkinen
Quoted 23 lines · James Bottomley
If a TPM is attached to a system via a serial bus on a platform that suffers bit flips, we can get back dangerously wrong data. This patch series aims never to do a direct copy into a kernel buffer based on an unchecked size value returned from the TPM.
Jeremy Boone (5):
tpm: fix potential buffer overruns caused by bit glitches on the
bus
tpm: st33zp24: fix potential buffer overruns caused by bit
glitches on
the bus
tpm_i2c_infineon: fix potential buffer overruns caused by bit
glitches
on the bus
tpm_i2c_nuvoton: fix potential buffer overruns caused by bit
glitches
on the bus
tpm_tis: fix potential buffer overruns caused by bit glitches on
the
busQuoted 10 lines
drivers/char/tpm/st33zp24/st33zp24.c | 4 ++-- drivers/char/tpm/tpm-interface.c | 4 ++++ drivers/char/tpm/tpm2-cmd.c | 4 ++++ drivers/char/tpm/tpm_i2c_infineon.c | 5 +++-- drivers/char/tpm/tpm_i2c_nuvoton.c | 5 +++-- drivers/char/tpm/tpm_tis_core.c | 5 +++-- 6 files changed, 19 insertions(+), 8 deletions(-)Signature · 1 line
o 2.12.3Reviewed-by Jarkko Sakkinen <[email protected]>I cannot test all of these but I'll put these to linux-next anyway. The changes are obvious and small scoped so if no one shouts they'll be part of the next PR.
Quoted 6 lines
I've tested the changes that affect
tpm2-cmd.c,tpm-interface.candtpm_tis_core.c. For HW specific changes tested-by's would be much appreciated but I don't think they will break anything.Because these are quite critical fixes I wonder if I could do one more PR to 4.16?
They're all cc'd to stable, so they'd make the stable updates to 4.16 regardless of when they're pulled. Since the merge window will close on Sunday and you have to go via James' tree, I'd say it would cause a lot of stress to try to make 4.16 but it's your call.
James
Quoted 49 lines · James Bottomley
Quoted 41 lines · Jarkko Sakkinen
Quoted 23 lines · James Bottomley
If a TPM is attached to a system via a serial bus on a platform that suffers bit flips, we can get back dangerously wrong data. This patch series aims never to do a direct copy into a kernel buffer based on an unchecked size value returned from the TPM.
Jeremy Boone (5):
tpm: fix potential buffer overruns caused by bit glitches on the
bus
tpm: st33zp24: fix potential buffer overruns caused by bit
glitches on
the bus
tpm_i2c_infineon: fix potential buffer overruns caused by bit
glitches
on the bus
tpm_i2c_nuvoton: fix potential buffer overruns caused by bit
glitches
on the bus
tpm_tis: fix potential buffer overruns caused by bit glitches on
the
busQuoted 10 lines
drivers/char/tpm/st33zp24/st33zp24.c | 4 ++-- drivers/char/tpm/tpm-interface.c | 4 ++++ drivers/char/tpm/tpm2-cmd.c | 4 ++++ drivers/char/tpm/tpm_i2c_infineon.c | 5 +++-- drivers/char/tpm/tpm_i2c_nuvoton.c | 5 +++-- drivers/char/tpm/tpm_tis_core.c | 5 +++-- 6 files changed, 19 insertions(+), 8 deletions(-)Signature · 1 line
o 2.12.3Reviewed-by Jarkko Sakkinen <[email protected]>I cannot test all of these but I'll put these to linux-next anyway. The changes are obvious and small scoped so if no one shouts they'll be part of the next PR.
Quoted 6 lines
I've tested the changes that affect
tpm2-cmd.c,tpm-interface.candtpm_tis_core.c. For HW specific changes tested-by's would be much appreciated but I don't think they will break anything.Because these are quite critical fixes I wonder if I could do one more PR to 4.16?
Quoted 6 lines
They're all cc'd to stable, so they'd make the stable updates to 4.16 regardless of when they're pulled. Since the merge window will close on Sunday and you have to go via James' tree, I'd say it would cause a lot of stress to try to make 4.16 but it's your call.
James
Agreed, thanks for input!
/Jarkko
Quoted 55 lines · Jarkko Sakkinen
Quoted 54 lines · James Bottomley
Quoted 41 lines · Jarkko Sakkinen
Quoted 23 lines · James Bottomley
If a TPM is attached to a system via a serial bus on a platform that suffers bit flips, we can get back dangerously wrong data. This patch series aims never to do a direct copy into a kernel buffer based on an unchecked size value returned from the TPM.
Jeremy Boone (5):
tpm: fix potential buffer overruns caused by bit glitches on the
bus
tpm: st33zp24: fix potential buffer overruns caused by bit
glitches on
the bus
tpm_i2c_infineon: fix potential buffer overruns caused by bit
glitches
on the bus
tpm_i2c_nuvoton: fix potential buffer overruns caused by bit
glitches
on the bus
tpm_tis: fix potential buffer overruns caused by bit glitches on
the
busQuoted 10 lines
drivers/char/tpm/st33zp24/st33zp24.c | 4 ++-- drivers/char/tpm/tpm-interface.c | 4 ++++ drivers/char/tpm/tpm2-cmd.c | 4 ++++ drivers/char/tpm/tpm_i2c_infineon.c | 5 +++-- drivers/char/tpm/tpm_i2c_nuvoton.c | 5 +++-- drivers/char/tpm/tpm_tis_core.c | 5 +++-- 6 files changed, 19 insertions(+), 8 deletions(-)Signature · 1 line
o 2.12.3Reviewed-by Jarkko Sakkinen <[email protected]>I cannot test all of these but I'll put these to linux-next anyway. The changes are obvious and small scoped so if no one shouts they'll be part of the next PR.
Quoted 6 lines
I've tested the changes that affect
tpm2-cmd.c,tpm-interface.candtpm_tis_core.c. For HW specific changes tested-by's would be much appreciated but I don't think they will break anything.Because these are quite critical fixes I wonder if I could do one more PR to 4.16?
They're all cc'd to stable, so they'd make the stable updates to 4.16 regardless of when they're pulled. Since the merge window will close on Sunday and you have to go via James' tree, I'd say it would cause a lot of stress to try to make 4.16 but it's your call.
Quoted 5 lines
Quoted 1 line
James
Agreed, thanks for input!
/Jarkko
They are now in master/next.
/Jarkko