tpm: fix buffer overflow in /dev/tpm0
PATCH 1/1 tpm: fix buffer overflow in /dev/tpm0
tpm_write() does not check whether the buffer has at least enough space for the header before passing it to tpm_transmit() so an overflow can happen.
--- drivers/char/tpm/tpm-interface.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/char/tpm/tpm-interface.c +3 -0
@@ -337,6 +337,9 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,u32 count, ordinal;unsigned long stop; +if (bufsiz <TPM_HEADER_SIZE ) +return -EINVAL ; +if (bufsiz >TPM_BUFSIZE ) bufsiz =TPM_BUFSIZE ;
Signature · 1 line
2.7.4
Quoted 5 lines · Jarkko Sakkinen
tpm_write()does not check whether the buffer has at least enough space for the header before passing it totpm_transmit()so an overflow can happen.Signed-off-by Jarkko Sakkinen <[email protected]>
This is usable neither as read nor write primitive for an exploit. Still it makes sense to validate the input here.
/Jarkko
Quoted 21 lines
--- drivers/char/tpm/tpm-interface.c | 3 +++ 1 file changed, 3 insertions(+)drivers/char/tpm/tpm-interface.c +3
-0@@ -337,6 +337,9 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,u32 count, ordinal;unsigned long stop; +if (bufsiz <TPM_HEADER_SIZE ) +return -EINVAL ; +if (bufsiz >TPM_BUFSIZE ) bufsiz =TPM_BUFSIZE ;Signature · 1 line
2.7.4
Quoted 9 lines · Jarkko Sakkinen
Quoted 5 lines · Jarkko Sakkinen
tpm_write()does not check whether the buffer has at least enough space for the header before passing it totpm_transmit()so an overflow can happen.This is usable neither as read nor write primitive for an exploit. Still it makes sense to validate the input here.
Cannot add fixes line for this one as it's from pre-GIT times...
/Jarkko
------------------------------------------------------------------------------
Quoted 3 lines · Jarkko Sakkinen
tpm_write()does not check whether the buffer has at least enough space for the header before passing it totpm_transmit()so an overflow can happen.
Eh?
tpm_write uses a hard wired buffer size of TPM_BUFSIZE when working with tpm_transmit.
in_size is never used except for the copy. We should probably fix that to sanity check the header length vs in_size.
That doesn't seem to be a security issue however because the header length is propery limited to TPM_BUFSIZE and the data buffer is allocated specifically for that process using kzalloc.
Jason
------------------------------------------------------------------------------
Quoted 10 lines · Jason Gunthorpe
Quoted 3 lines · Jarkko Sakkinen
tpm_write()does not check whether the buffer has at least enough space for the header before passing it totpm_transmit()so an overflow can happen.Eh?
tpm_writeuses a hard wired buffer size ofTPM_BUFSIZEwhen working withtpm_transmit.
Quoted 6 lines
in_sizeis never used except for the copy. We should probably fix that to sanity check the header length vsin_size.That doesn't seem to be a security issue however because the header length is propery limited to
TPM_BUFSIZEand the data buffer is allocated specifically for that process using kzalloc.
I was working on something else when I bumped into this. The commit message is not the best possible but still the issue is valid although it does not cause any imaginable harm because there is always TPM_BUFSIZE of room in the buffer passed by tpm_write.
I'll update the commit message not to speak about tpm_write.
"tpm_transmit() does not check whether the bufsiz can contain the TPM header. Add check for this and return -EINVAL if it the buffer is too small."
The check should be in tpm_transmit() and also the commit message should be only about that.
Quoted 1 line
Jason
/Jarkko
------------------------------------------------------------------------------