tpm/eventlog: Use kvmalloc() for event log buffer
Subsystems (2)
PATCH 1/1 tpm/eventlog: Use kvmalloc() for event log buffer
The TPM2 ACPI table may request a large size for the event log, and it may be over the max size of kmalloc(). When this happens, the driver spews the kernel WARNING at the probe time, but the error is eventually ignored in the caller side, and it results in the missing TPM event log exposure.
This patch replaces the devm_kmalloc() call with kvmalloc() to allow larger sizes. Since there is no devm variant for kvmalloc(), now it's managed manually via devres_alloc() and devres_add().
--- drivers/char/tpm/eventlog/acpi.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/char/tpm/eventlog/acpi.c +18 -3
@@ -63,6 +63,13 @@ static bool tpm_is_tpm2_log(void *bios_event_log, u64 len)return n ==0 ; } +static void bios_event_log_release (struct device *dev,void *res) +{ +void **logp = res; + +kvfree (*logp); +} +/* read binary bios log */ int tpm_read_log_acpi (struct tpm_chip *chip) {
@@ -71,6 +78,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip)void __iomem *virt;u64 len, start;struct tpm_bios_log *log; +void **logp;struct acpi_table_tpm2 *tbl;struct acpi_tpm2_phy *tpm2_phy;int format;
@@ -136,9 +144,16 @@ int tpm_read_log_acpi(struct tpm_chip *chip) }/* malloc EventLog space */ - log->bios_event_log =devm_kmalloc (&chip->dev, len,GFP_KERNEL ); -if (!log->bios_event_log) + logp =devres_alloc (bios_event_log_release,sizeof (*logp),GFP_KERNEL ); +if (!logp)return -ENOMEM ; +devres_add (&chip->dev, logp); + log->bios_event_log =kvmalloc (len,GFP_KERNEL ); +if (!log->bios_event_log) { + ret = -ENOMEM ; + goto err; + } + *logp = log->bios_event_log; log->bios_event_log_end = log->bios_event_log + len;
@@ -164,7 +179,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip)return format; err: -devm_kfree (&chip->dev, log->bios_event_log); +devres_release (&chip->dev, bios_event_log_release,NULL ,NULL ); log->bios_event_log =NULL ;return ret; }
Signature · 1 line
2.43.0
Dear Takashi,
Thank you for the patch.
Am 07.11.24 um 12:18 schrieb Takashi Iwai:
Quoted 2 lines
The TPM2 ACPI table may request a large size for the event log, and it may be over the max size of
kmalloc(). When this happens, the driver
What is kmalloc()’s maximum size?
Quoted 7 lines
spews the kernel WARNING at the probe time, but the error is eventually ignored in the caller side, and it results in the missing TPM event log exposure.
This patch replaces the
devm_kmalloc()call withkvmalloc()to allow larger sizes. Since there is no devm variant forkvmalloc(), now it's managed manually viadevres_alloc()anddevres_add().
As the access to the bug report is restricted, are you at liberty to share the system you’ve seen this on?
Quoted 54 lines
Reported-and-tested-by Andy Liang <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- drivers/char/tpm/eventlog/acpi.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)drivers/char/tpm/eventlog/acpi.c +17
-2@@ -63,6 +63,13 @@ static bool tpm_is_tpm2_log(void *bios_event_log, u64 len)return n ==0 ; } +static void bios_event_log_release (struct device *dev,void *res) +{ +void **logp = res; + +kvfree (*logp); +} +/* read binary bios log */ int tpm_read_log_acpi (struct tpm_chip *chip) {@@ -71,6 +78,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip)void __iomem *virt;u64 len, start;struct tpm_bios_log *log; +void **logp;struct acpi_table_tpm2 *tbl;struct acpi_tpm2_phy *tpm2_phy;int format;@@ -136,9 +144,16 @@ int tpm_read_log_acpi(struct tpm_chip *chip) }/* malloc EventLog space */ - log->bios_event_log =devm_kmalloc (&chip->dev, len,GFP_KERNEL ); -if (!log->bios_event_log) + logp =devres_alloc (bios_event_log_release,sizeof (*logp),GFP_KERNEL ); +if (!logp)return -ENOMEM ; +devres_add (&chip->dev, logp); + log->bios_event_log =kvmalloc (len,GFP_KERNEL ); +if (!log->bios_event_log) { + ret = -ENOMEM ; + goto err; + } + *logp = log->bios_event_log; log->bios_event_log_end = log->bios_event_log + len;
drivers/char/tpm/eventlog/acpi.c int tpm_read_log_acpi(struct tpm_chip *chip) · line 185
Quoted 8 lines
drivers/char/tpm/eventlog/acpi.c +1
-1@@ -164,7 +179,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip)return format; err: -devm_kfree (&chip->dev, log->bios_event_log); +devres_release (&chip->dev, bios_event_log_release,NULL ,NULL ); log->bios_event_log =NULL ;return ret; }
The diff looks good to me.
Kind regards,
Paul
Quoted 11 lines · Paul Menzel
Dear Takashi,
Thank you for the patch.
Am 07.11.24 um 12:18 schrieb Takashi Iwai:
Quoted 2 lines
The TPM2 ACPI table may request a large size for the event log, and it may be over the max size of
kmalloc(). When this happens, the driverWhat is kmalloc()’s maximum size?
128kB or so, IIRC.
And according Andy, the table can be over 4MB.
Quoted 10 lines
Quoted 7 lines
spews the kernel WARNING at the probe time, but the error is eventually ignored in the caller side, and it results in the missing TPM event log exposure.
This patch replaces the
devm_kmalloc()call withkvmalloc()to allow larger sizes. Since there is no devm variant forkvmalloc(), now it's managed manually viadevres_alloc()anddevres_add().As the access to the bug report is restricted, are you at liberty to share the system you’ve seen this on?
Likely yes, as it was reported to SLE15. Sorry for that.
Basically the info provided there was almost what I put in the description; the driver got the kernel WARNING and Andy tested my patch.
If any further info is required, at best ask HPE people here in Cc.
thanks,
Takashi
Quoted 64 lines
Quoted 47 lines
Reported-and-tested-by Andy Liang <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- drivers/char/tpm/eventlog/acpi.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)drivers/char/tpm/eventlog/acpi.c +15
-2@@ -63,6 +63,13 @@ static bool tpm_is_tpm2_log(void *bios_event_log, u64 len)return n ==0 ; } +static void bios_event_log_release(struct device *dev, void *res) +{ +void **logp = res; + +kvfree (*logp); +} +/* read binary bios log */ int tpm_read_log_acpi (struct tpm_chip *chip) {@@ -71,6 +78,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip)void __iomem *virt;u64 len, start;struct tpm_bios_log *log; +void **logp;struct acpi_table_tpm2 *tbl;struct acpi_tpm2_phy *tpm2_phy;int format;@@ -136,9 +144,16 @@ int tpm_read_log_acpi(struct tpm_chip *chip) }/* malloc EventLog space */ - log->bios_event_log =devm_kmalloc (&chip->dev, len,GFP_KERNEL ); -if (!log->bios_event_log) + logp =devres_alloc (bios_event_log_release,sizeof (*logp),GFP_KERNEL ); +if (!logp)return -ENOMEM ; +devres_add (&chip->dev, logp); + log->bios_event_log =kvmalloc (len,GFP_KERNEL ); +if (!log->bios_event_log) { + ret = -ENOMEM ; + goto err; + }drivers/char/tpm/eventlog/acpi.c int tpm_read_log_acpi(struct tpm_chip *chip)
Quoted 10 lines
drivers/char/tpm/eventlog/acpi.c +2
-1+ *logp = log->bios_event_log; log->bios_event_log_end = log->bios_event_log + len; @@ -164,7 +179,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip) return format; err: -devm_kfree (&chip->dev, log->bios_event_log); +devres_release (&chip->dev, bios_event_log_release,NULL ,NULL ); log->bios_event_log =NULL ;return ret; }The diff looks good to me.
Kind regards,
Paul
Quoted 8 lines · Takashi Iwai
Quoted 6 lines · Paul Menzel
Dear Takashi,
Thank you for the patch.
Quoted 8 lines
Quoted 5 lines
Am 07.11.24 um 12:18 schrieb Takashi Iwai:
Quoted 2 lines
The TPM2 ACPI table may request a large size for the event log, and it may be over the max size of
kmalloc(). When this happens, the driverWhat is kmalloc()’s maximum size?
128kB or so, IIRC.
And according Andy, the table can be over 4MB.
Can you copy the contents of the file on that machine and tell us what size it has:
cp /sys/kernel/security/tpm0/binary_bios_measurements ./
I wonder what the BIOS on that system writes into this file and wouldn't exclude a buggy BIOS indicating wrong size and producing a much smaller log.
Quoted 15 lines · Stefan Berger
Quoted 12 lines · Takashi Iwai
Quoted 10 lines · Paul Menzel
Dear Takashi,
Thank you for the patch.
Am 07.11.24 um 12:18 schrieb Takashi Iwai:
Quoted 2 lines
The TPM2 ACPI table may request a large size for the event log, and it may be over the max size of kmalloc(). When this happens, the driver
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
What is kmalloc()’s maximum size?
128kB or so, IIRC.
And according Andy, the table can be over 4MB.Can you copy the contents of the file on that machine and tell us what size it has:
cp
/sys/kernel/security/tpm0/binary_bios_measurements./
Actually, you may need to have the contents parsed by a user space tool since the driver does not detect where the actual end may be:
tsseventextend -if ./binary_bios_measurements -sim -v
This may give you a feeling for how much is in that file and then you'd have to truncate it into half for example and see whether it still parses the same. My point is that we haven't seen such excessive-sized logs so far and following the parsing above we may find something like this more useful than allocating possibly large amounts of memory that a buggy ACPI table indicates (+ notify manufacturer):
if (len > MAX_TPM_LOG_SIZE) {
dev_err(&chip->dev, "Truncated excessive-sized TPM log of %d
bytes\n", len);
len = MAX_TPM_LOG_SIZE;}
If you send me the log I'd look at it.
Quoted 4 lines
I wonder what the BIOS on that system writes into this file and wouldn't exclude a buggy BIOS indicating wrong size and producing a much smaller log.
Quoted 42 lines · Stefan Berger
Quoted 17 lines · Stefan Berger
Quoted 14 lines · Takashi Iwai
Quoted 11 lines · Paul Menzel
Dear Takashi,
Thank you for the patch.
Am 07.11.24 um 12:18 schrieb Takashi Iwai:
Quoted 2 lines
The TPM2 ACPI table may request a large size for the event log, and it may be over the max size of kmalloc(). When this happens, the driver
What is kmalloc()’s maximum size?
Quoted 7 lines
Quoted 2 lines
128kB or so, IIRC.
And according Andy, the table can be over 4MB.Can you copy the contents of the file on that machine and tell us what size it has:
cp
/sys/kernel/security/tpm0/binary_bios_measurements./Actually, you may need to have the contents parsed by a user space tool since the driver does not detect where the actual end may be:
tsseventextend -if ./binary_bios_measurements -sim -v
This may give you a feeling for how much is in that file and then you'd have to truncate it into half for example and see whether it still parses the same. My point is that we haven't seen such excessive-sized logs so far and following the parsing above we may find something like this more useful than allocating possibly large amounts of memory that a buggy ACPI table indicates (+ notify manufacturer):
Quoted 7 lines
if (len > MAX_TPM_LOG_SIZE) { dev_err(&chip->dev, "Truncated excessive-sized TPM log of %d bytes\n", len); len = MAX_TPM_LOG_SIZE;}
If you send me the log I'd look at it.
It's rather a question Andy; could you check give the requested info?
thanks,
Takashi
Quoted 51 lines
Quoted 48 lines · Stefan Berger
Quoted 17 lines · Stefan Berger
Quoted 14 lines · Takashi Iwai
Quoted 12 lines · Paul Menzel
Dear Takashi,
Thank you for the patch.
Am 07.11.24 um 12:18 schrieb Takashi Iwai:
Quoted 3 lines
The TPM2 ACPI table may request a large size for the event log, and it may be over the max size of kmalloc(). When this happens, the driver
What is kmalloc()’s maximum size?
Quoted 7 lines
Quoted 2 lines
128kB or so, IIRC.
And according Andy, the table can be over 4MB.Can you copy the contents of the file on that machine and tell us what size it has:
cp
/sys/kernel/security/tpm0/binary_bios_measurements./Actually, you may need to have the contents parsed by a user space tool since the driver does not detect where the actual end may be:
tsseventextend -if ./binary_bios_measurements -sim -v
This may give you a feeling for how much is in that file and then you'd have to truncate it into half for example and see whether it still parses the same. My point is that we haven't seen such excessive-sized logs so far and following the parsing above we may find something like this more useful than allocating possibly large amounts of memory that a buggy ACPI table indicates (+ notify
manufacturer):if (len > MAX_TPM_LOG_SIZE) { dev_err(&chip->dev, "Truncated excessive-sized TPM log of %d bytes\n", len); len = MAX_TPM_LOG_SIZE;}
Quoted 3 lines
Quoted 1 line
If you send me the log I'd look at it.
It's rather a question Andy; could you check give the requested info?
https://elixir.bootlin.com/linux/v6.8/source/arch/x86/include/asm/page_types.h#L10
#define PAGE_SHIFT 12
#define KMALLOC_SHIFT_MAX (MAX_PAGE_ORDER + PAGE_SHIFT)
https://elixir.bootlin.com/linux/v6.8/source/include/linux/mmzone.h#L30
#define MAX_PAGE_ORDER 10
https://elixir.bootlin.com/linux/v6.8/source/include/linux/slab.h#L309
#define KMALLOC_MAX_SIZE (1UL << KMALLOC_SHIFT_MAX)
The max size = (1UL << MAX_PAGE_ORDER + PAGE_SHIFT) = ( 1UL << (10 + 12)) = 2^22 =4,194,304 (4MB)
For the x86, the max size is 4MB.
Quoted 3 lines
thanks,
Takashi
Quoted 61 lines · Andy (Linux Ecosystem Engineering)
Quoted 52 lines
Quoted 48 lines · Stefan Berger
Quoted 17 lines · Stefan Berger
Quoted 14 lines · Takashi Iwai
Quoted 12 lines · Paul Menzel
Dear Takashi,
Thank you for the patch.
Am 07.11.24 um 12:18 schrieb Takashi Iwai:
Quoted 3 lines
The TPM2 ACPI table may request a large size for the event log, and it may be over the max size of kmalloc(). When this happens, the driver
What is kmalloc()’s maximum size?
Quoted 7 lines
Quoted 2 lines
128kB or so, IIRC.
And according Andy, the table can be over 4MB.Can you copy the contents of the file on that machine and tell us what size it has:
cp
/sys/kernel/security/tpm0/binary_bios_measurements./Actually, you may need to have the contents parsed by a user space tool since the driver does not detect where the actual end may be:
tsseventextend -if ./binary_bios_measurements -sim -v
This may give you a feeling for how much is in that file and then you'd have to truncate it into half for example and see whether it still parses the same. My point is that we haven't seen such excessive-sized logs so far and following the parsing above we may find something like this more useful than allocating possibly large amounts of memory that a buggy ACPI table indicates (+ notify
manufacturer):if (len > MAX_TPM_LOG_SIZE) { dev_err(&chip->dev, "Truncated excessive-sized TPM log of %d bytes\n", len); len = MAX_TPM_LOG_SIZE;}
Quoted 3 lines
Quoted 1 line
If you send me the log I'd look at it.
It's rather a question Andy; could you check give the requested info?
https://elixir.bootlin.com/linux/v6.8/source/arch/x86/include/asm/page_types.h#L10
#definePAGE_SHIFT12
#defineKMALLOC_SHIFT_MAX(MAX_PAGE_ORDER+PAGE_SHIFT)
Quoted 8 lines
https://elixir.bootlin.com/linux/v6.8/source/include/linux/mmzone.h#L30
#defineMAX_PAGE_ORDER10https://elixir.bootlin.com/linux/v6.8/source/include/linux/slab.h#L309
#defineKMALLOC_MAX_SIZE(1UL <<KMALLOC_SHIFT_MAX)
The max size = (1UL <<MAX_PAGE_ORDER+PAGE_SHIFT) = ( 1UL << (10 + 12)) = 2^22 =4,194,304 (4MB)For the x86, the max size is 4MB.
Thanks, it was already corrected by Jarkko :)
But what I meant was about the requests:
Quoted 1 line
cp
/sys/kernel/security/tpm0/binary_bios_measurements./
and
Quoted 1 line
tsseventextend -if ./binary_bios_measurements -sim -v
mentioned in the above. Could you provide the info?
thanks,
Takashi
Quoted 76 lines
Quoted 65 lines · Andy (Linux Ecosystem Engineering)
Quoted 51 lines
Quoted 47 lines · Stefan Berger
Quoted 5 lines · Stefan Berger
Quoted 2 lines · Takashi Iwai
Quoted 1 line · Paul Menzel
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Dear Takashi,
Thank you for the patch.
Am 07.11.24 um 12:18 schrieb Takashi Iwai:
Quoted 1 line
The TPM2 ACPI table may request a large size for the event
log, >>>> and it may be over the max size of kmalloc(). When this happens, >>>> the driver >>> >>> What is kmalloc()’s maximum size?
Quoted 5 lines
Quoted 3 lines
128kB or so, IIRC.
And according Andy, the table can be over 4MB.Can you copy the contents of the file on that machine and tell
us > what size it has:
Quoted 2 lines
cp
/sys/kernel/security/tpm0/binary_bios_measurements./Actually, you may need to have the contents parsed by a user space
tool since the driver does not detect where the actual end may be:tsseventextend -if ./binary_bios_measurements -sim -v
This may give you a feeling for how much is in that file and then
you'd have to truncate it into half for example and see whether it still parses the same. My point is that we haven't seen such excessive-sized logs so far and following the parsing above we may find something like this more useful than allocating possibly large amounts of memory that a buggy ACPI table indicates (+ notify manufacturer):if (len > MAX_TPM_LOG_SIZE) { dev_err(&chip->dev, "Truncated excessive-sized TPM log of %d bytes\n", len); len = MAX_TPM_LOG_SIZE;}
Quoted 3 lines
Quoted 1 line
If you send me the log I'd look at it.
It's rather a question Andy; could you check give the requested info?
https://elixir.bootlin.com/linux/v6.8/source/arch/x86/include/asm/page
_types.h#L10
#definePAGE_SHIFT12
#defineKMALLOC_SHIFT_MAX(MAX_PAGE_ORDER+PAGE_SHIFT)https://elixir.bootlin.com/linux/v6.8/source/include/linux/mmzone.h#L3
0
#defineMAX_PAGE_ORDER10Quoted 6 lines
https://elixir.bootlin.com/linux/v6.8/source/include/linux/slab.h#L309
#defineKMALLOC_MAX_SIZE(1UL <<KMALLOC_SHIFT_MAX) The max size = (1UL <<MAX_PAGE_ORDER+PAGE_SHIFT) = ( 1UL << (10 + 12)) = 2^22 =4,194,304 (4MB)For the x86, the max size is 4MB.
Thanks, it was already corrected by Jarkko :) But what I meant was about the requests:
Quoted 7 lines
Quoted 1 line
cp
/sys/kernel/security/tpm0/binary_bios_measurements./and
Quoted 1 line
tsseventextend -if ./binary_bios_measurements -sim -v
mentioned in the above. Could you provide the info?
Please check the attached file. The file has also been uploaded to the SUSE Bugzilla. Thank you.
Quoted 3 lines
thanks,
Takashi
Jarkko Sakkinen
maintainerQuoted 78 lines · Andy (Linux Ecosystem Engineering) Liang
Quoted 78 lines
Quoted 65 lines · Andy (Linux Ecosystem Engineering)
Quoted 51 lines
Quoted 47 lines · Stefan Berger
Quoted 5 lines · Stefan Berger
Quoted 2 lines · Takashi Iwai
Quoted 1 line · Paul Menzel
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Dear Takashi,
Thank you for the patch.
Am 07.11.24 um 12:18 schrieb Takashi Iwai:
Quoted 1 line
The TPM2 ACPI table may request a large size for the event
log, >>>> and it may be over the max size of kmalloc(). When this happens, >>>> the driver >>> >>> What is kmalloc()’s maximum size?
Quoted 5 lines
Quoted 3 lines
128kB or so, IIRC.
And according Andy, the table can be over 4MB.Can you copy the contents of the file on that machine and tell
us > what size it has:
Quoted 2 lines
cp
/sys/kernel/security/tpm0/binary_bios_measurements./Actually, you may need to have the contents parsed by a user space
tool since the driver does not detect where the actual end may be:tsseventextend -if ./binary_bios_measurements -sim -v
This may give you a feeling for how much is in that file and then
you'd have to truncate it into half for example and see whether it still parses the same. My point is that we haven't seen such excessive-sized logs so far and following the parsing above we may find something like this more useful than allocating possibly large amounts of memory that a buggy ACPI table indicates (+ notify manufacturer):if (len > MAX_TPM_LOG_SIZE) { dev_err(&chip->dev, "Truncated excessive-sized TPM log of %d bytes\n", len); len = MAX_TPM_LOG_SIZE;}
Quoted 3 lines
Quoted 1 line
If you send me the log I'd look at it.
It's rather a question Andy; could you check give the requested info?
https://elixir.bootlin.com/linux/v6.8/source/arch/x86/include/asm/page
_types.h#L10
#definePAGE_SHIFT12
#defineKMALLOC_SHIFT_MAX(MAX_PAGE_ORDER+PAGE_SHIFT)https://elixir.bootlin.com/linux/v6.8/source/include/linux/mmzone.h#L3
0
#defineMAX_PAGE_ORDER10Quoted 6 lines
https://elixir.bootlin.com/linux/v6.8/source/include/linux/slab.h#L309
#defineKMALLOC_MAX_SIZE(1UL <<KMALLOC_SHIFT_MAX) The max size = (1UL <<MAX_PAGE_ORDER+PAGE_SHIFT) = ( 1UL << (10 + 12)) = 2^22 =4,194,304 (4MB)For the x86, the max size is 4MB.
Thanks, it was already corrected by Jarkko :) But what I meant was about the requests:
Quoted 1 line
cp
/sys/kernel/security/tpm0/binary_bios_measurements./
Quoted 8 lines
Quoted 5 lines
and
Quoted 1 line
tsseventextend -if ./binary_bios_measurements -sim -v
mentioned in the above. Could you provide the info?
Please check the attached file. The file has also been uploaded to the SUSE Bugzilla. Thank you.
Please create a bug to kernel bugzilla and attach the file on that.
BR, Jarkko
Quoted 84 lines · Andy (Linux Ecosystem Engineering) Liang
Quoted 82 lines
Quoted 82 lines
Quoted 65 lines · Andy (Linux Ecosystem Engineering)
Quoted 51 lines
Quoted 47 lines · Stefan Berger
Quoted 5 lines · Stefan Berger
Quoted 2 lines · Takashi Iwai
Quoted 1 line · Paul Menzel
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Dear Takashi,
Thank you for the patch.
Am 07.11.24 um 12:18 schrieb Takashi Iwai:
Quoted 1 line
The TPM2 ACPI table may request a large size for the event
log, >>>> and it may be over the max size of
kmalloc(). When this happens, >>>> the driver >>> >>> What is kmalloc()’s maximum size?Quoted 5 lines
Quoted 3 lines
128kB or so, IIRC.
And according Andy, the table can be over 4MB.Can you copy the contents of the file on that machine and tell
us > what size it has:
Quoted 2 lines
cp
/sys/kernel/security/tpm0/binary_bios_measurements./Actually, you may need to have the contents parsed by a user space tool since the driver does not detect where the actual end may be:
tsseventextend -if ./binary_bios_measurements -sim -v
This may give you a feeling for how much is in that file and then you'd have to truncate it into half for example and see whether it still parses the same. My point is that we haven't seen such excessive-sized logs so far and following the parsing above we may find something like this more useful than allocating possibly large amounts of memory that a buggy ACPI table indicates (+ notify manufacturer):
if (len > MAX_TPM_LOG_SIZE) { dev_err(&chip->dev, "Truncated excessive-sized TPM log of %d bytes\n", len); len = MAX_TPM_LOG_SIZE;}
Quoted 3 lines
Quoted 1 line
If you send me the log I'd look at it.
It's rather a question Andy; could you check give the requested info?
https://elixir.bootlin.com/linux/v6.8/source/arch/x86/include/asm/page
_types.h#L10
#definePAGE_SHIFT12
#defineKMALLOC_SHIFT_MAX(MAX_PAGE_ORDER+PAGE_SHIFT)https://elixir.bootlin.com/linux/v6.8/source/include/linux/mmzone.h#L3
0
#defineMAX_PAGE_ORDER10Quoted 6 lines
https://elixir.bootlin.com/linux/v6.8/source/include/linux/slab.h#L309
#defineKMALLOC_MAX_SIZE(1UL <<KMALLOC_SHIFT_MAX) The max size = (1UL <<MAX_PAGE_ORDER+PAGE_SHIFT) = ( 1UL << (10 + 12)) = 2^22 =4,194,304 (4MB)For the x86, the max size is 4MB.
Thanks, it was already corrected by Jarkko :) But what I meant was about the requests:
Quoted 1 line
cp
/sys/kernel/security/tpm0/binary_bios_measurements./and
Quoted 1 line
tsseventextend -if ./binary_bios_measurements -sim -v
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
mentioned in the above. Could you provide the info?
Please check the attached file. The file has also been uploaded to the SUSE Bugzilla. Thank you.
Please create a bug to kernel bugzilla and attach the file on that.
BR, Jarkko
I created a ticket at below. Thank you.
Jarkko Sakkinen
maintainerQuoted 10 lines · Paul Menzel
Dear Takashi,
Thank you for the patch.
Am 07.11.24 um 12:18 schrieb Takashi Iwai:
Quoted 2 lines
The TPM2 ACPI table may request a large size for the event log, and it may be over the max size of
kmalloc(). When this happens, the driverWhat is kmalloc()’s maximum size?
For reference: https://elixir.bootlin.com/linux/v6.11.6/source/include/linux/slab.h#L367
So it would be 1UL << 22 i.e. 4 MB at least. Not sure if MAX_PAGE_ORDER is larger than 10 on x86-64.
BR, Jarkko
Quoted 11 lines · Jarkko Sakkinen
Quoted 9 lines · Paul Menzel
Dear Takashi,
Thank you for the patch.
Am 07.11.24 um 12:18 schrieb Takashi Iwai:
Quoted 2 lines
The TPM2 ACPI table may request a large size for the event log, and it may be over the max size of
kmalloc(). When this happens, the driver
Quoted 6 lines
Quoted 1 line
What is kmalloc()’s maximum size?
For reference: https://elixir.bootlin.com/linux/v6.11.6/source/include/linux/slab.h#L367
So it would be 1UL << 22 i.e. 4 MB at least. Not sure if
MAX_PAGE_ORDERis larger than 10 on x86-64.
Ah thanks, it has been changed.
Takashi
Jarkko Sakkinen
maintainerQuoted 5 lines · Takashi Iwai
The TPM2 ACPI table may request a large size for the event log, and it may be over the max size of
kmalloc(). When this happens, the driver spews the kernel WARNING at the probe time, but the error is eventually ignored in the caller side, and it results in the missing TPM event log exposure.
TPM2 ACPI table is data structure ;-) Just to make the commit message less confusing, please refer to active actors.
Quoted 8 lines
This patch replaces the
devm_kmalloc()call withkvmalloc()to allow larger sizes. Since there is no devm variant forkvmalloc(), now it's managed manually viadevres_alloc()anddevres_add().Reported-and-tested-by Andy Liang <[email protected]>
"You are not authorized to access bug #1232421. To see this bug, you must first log in to an account with the appropriate permissions."
Please remove this link as it gives no information without login access, *or* make it available w/o acocunt, *or* repost a bug to the kernel bugzilla.
I've been cursing SUSE accounts for over a year now. Never been able to successfully get either to the bugzilla or forums (still I get some weekly spam about the forums). And no, no interest to recall or figure out this problem.
Quoted 32 lines
Signed-off-by Takashi Iwai <[email protected]>--- drivers/char/tpm/eventlog/acpi.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)drivers/char/tpm/eventlog/acpi.c +8
-0@@ -63,6 +63,13 @@ static bool tpm_is_tpm2_log(void *bios_event_log, u64 len)return n ==0 ; } +static void bios_event_log_release (struct device *dev,void *res) +{ +void **logp = res; + +kvfree (*logp); +} +/* read binary bios log */ int tpm_read_log_acpi (struct tpm_chip *chip) {@@ -71,6 +78,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip)void __iomem *virt;u64 len, start;struct tpm_bios_log *log; +void **logp;struct acpi_table_tpm2 *tbl;struct acpi_tpm2_phy *tpm2_phy;int format;
drivers/char/tpm/eventlog/acpi.c int tpm_read_log_acpi(struct tpm_chip *chip) · line 149
Quoted 8 lines
drivers/char/tpm/eventlog/acpi.c +2
-2@@ -136,9 +144,16 @@ int tpm_read_log_acpi(struct tpm_chip *chip) }/* malloc EventLog space */ - log->bios_event_log =devm_kmalloc (&chip->dev, len,GFP_KERNEL ); -if (!log->bios_event_log) + logp =devres_alloc (bios_event_log_release,sizeof (*logp),GFP_KERNEL ); +if (!logp)return -ENOMEM ;
How big is it?
Quoted 11 lines
drivers/char/tpm/eventlog/acpi.c +7
-0+devres_add (&chip->dev, logp); + log->bios_event_log =kvmalloc (len,GFP_KERNEL ); +if (!log->bios_event_log) { + ret = -ENOMEM ; + goto err; + } + *logp = log->bios_event_log; log->bios_event_log_end = log->bios_event_log + len;
drivers/char/tpm/eventlog/acpi.c int tpm_read_log_acpi(struct tpm_chip *chip) · line 185
Quoted 8 lines
drivers/char/tpm/eventlog/acpi.c +1
-1@@ -164,7 +179,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip)return format; err: -devm_kfree (&chip->dev, log->bios_event_log); +devres_release (&chip->dev, bios_event_log_release,NULL ,NULL ); log->bios_event_log =NULL ;return ret; }
BR, Jarkko
Jarkko Sakkinen
maintainerQuoted 12 lines · Jarkko Sakkinen
Quoted 8 lines
This patch replaces the
devm_kmalloc()call withkvmalloc()to allow larger sizes. Since there is no devm variant forkvmalloc(), now it's managed manually viadevres_alloc()anddevres_add().Reported-and-tested-by Andy Liang <[email protected]>"You are not authorized to access bug #1232421. To see this bug, you must first log in to an account with the appropriate permissions."
Quoted 8 lines
Please remove this link as it gives no information without login access, *or* make it available w/o acocunt, *or* repost a bug to the kernel bugzilla.
I've been cursing SUSE accounts for over a year now. Never been able to successfully get either to the bugzilla or forums (still I get some weekly spam about the forums). And no, no interest to recall or figure out this problem.
Just a personal recommendation but I'd create a bug to kernel bugzilla and link that to the SUSE bug, and call it a day ;-) It would be the least friction approach.
BR, Jarkko
Quoted 18 lines · Jarkko Sakkinen
Quoted 16 lines · Jarkko Sakkinen
Quoted 8 lines
This patch replaces the
devm_kmalloc()call withkvmalloc()to allow larger sizes. Since there is no devm variant forkvmalloc(), now it's managed manually viadevres_alloc()anddevres_add().Reported-and-tested-by Andy Liang <[email protected]>"You are not authorized to access bug #1232421. To see this bug, you must first log in to an account with the appropriate permissions."
Please remove this link as it gives no information without login access, *or* make it available w/o acocunt, *or* repost a bug to the kernel bugzilla.
Quoted 8 lines
Quoted 4 lines
I've been cursing SUSE accounts for over a year now. Never been able to successfully get either to the bugzilla or forums (still I get some weekly spam about the forums). And no, no interest to recall or figure out this problem.
Just a personal recommendation but I'd create a bug to kernel bugzilla and link that to the SUSE bug, and call it a day ;-) It would be the least friction approach.
Andy, care to open a new entry on bugzilla.kernel.org?
thanks,
Takashi