Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dmidecode fails when booted with 1f123ac2359cd923e9144f944a4bddf597fddbb5 #249

Closed
jyong2 opened this issue Jan 18, 2021 · 13 comments
Closed

Comments

@jyong2
Copy link
Contributor

jyong2 commented Jan 18, 2021

When booted with shim, dmidecode fails to run:

# dmidecode -t baseboard
# dmidecode 3.2
# SMBIOS entry point at 0x748cd000
Found SMBIOS entry point in EFI, reading table from /dev/mem.
# No SMBIOS nor DMI entry point found, sorry.

Any ideas about this?

Edit: formatting

@jyong2
Copy link
Contributor Author

jyong2 commented Jan 27, 2021

Bisect seems to be suggesting fecc2df, tested on qemu 5.1.0.

@jsetje
Copy link
Collaborator

jsetje commented Mar 11, 2021

With secure boot enabled, lockdown prevents reads from /dev/mem. Newer dmidecode should be using sysfs instead.

Can you help us establish if you're seeing this change in behavior with or without secure boot enabled?

If you're seeing it with secure boot enabled, then the /dev/mem failure is expected and prior to that fix your kernel was failing to enforce lockdown.

If you're seeing it with secure boot disabled, then something else may have changed, and we should look into this further.

@jyong2
Copy link
Contributor Author

jyong2 commented Mar 12, 2021

dmidecode does use sysfs when possible, it works fine with the older shim, but the dmi tables entries are missing in the newer shim, causing it to fallback to /dev/mem. This happens regardless of secureboot or not.

I should also mention I am using ovmf edk2-stable201911 as part of Yocto Project.

@jyong2
Copy link
Contributor Author

jyong2 commented Mar 15, 2021

As of 018b74d commit, I am still getting errors:

root@intel-corei7-64:~# dmidecode -t baseboard
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.

Wrong DMI structures length: 383 bytes announced, only 16 bytes available.
Invalid entry length (0). DMI table is broken! Stop.

@jyong2
Copy link
Contributor Author

jyong2 commented Mar 15, 2021

Still same for 39b96c0

root@intel-corei7-64:~# dmidecode
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.
9 structures occupying 383 bytes.
Table at 0x1FBCF000.

Wrong DMI structures length: 383 bytes announced, only 16 bytes available.
Invalid entry length (0). DMI table is broken! Stop.

root@intel-corei7-64:~# dmidecode -t baseboard
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.

Wrong DMI structures length: 383 bytes announced, only 16 bytes available.
Invalid entry length (0). DMI table is broken! Stop.

@jyong2
Copy link
Contributor Author

jyong2 commented Mar 18, 2021

7defee6 seems to be working, very strange. It might have something to do with switch to the gitsubmodule copy of gnu-efi.

@jyong2
Copy link
Contributor Author

jyong2 commented Mar 29, 2021

Issue seems to be happening sporadically while on real hardware, I'm not sure what else is happening.

@jyong2
Copy link
Contributor Author

jyong2 commented Apr 15, 2021

Found a likely buffer overflow in import_mok_state() introduced in fecc2df:

for (i = 0; mok_state_variables[i].name != NULL; i++) {
..
		if (v->data && v->data_size) {
			config_sz += v->data_size;
			config_sz += sizeof(config_template);
		}
}
...
gBS->AllocatePages
...
for (i = 0; p && mok_state_variables[i].name != NULL; i++) {
...
p += sizeof(config_template);
p += v->data_size;

if (p) {
  ...
  CopyMem(p, &config_template, sizeof(config_template));
  ...
}

There is an extra sizeof(config_template) write at the end of p. Adding a one liner:
config_sz += sizeof(config_template);
to line mok.c line 998 should resolve it.

@jyong2
Copy link
Contributor Author

jyong2 commented Apr 16, 2021

Strange, line 998 already has it to begin with(?), please ignore my last message.

Edit: not sure how I missed line 998 already having it but looks like the issue is in the 2nd loop where p is advanced by sizeof(config_template) regardless when v->data_size is 0, while the size calculation skips it.

jyong2 added a commit to jyong2/shim that referenced this issue Apr 19, 2021
Fix the case where data_size is 0, so config_template is
not implicitly copied like the size calculation above.

upstream-status: rhboot#249

Signed-off-by: Jonathan Yong <jonathan.yong@intel.com>
@jyong2
Copy link
Contributor Author

jyong2 commented Apr 22, 2021

@jsetje ping? Tested on Tiger Lake, Ice Lake and Comet Lake boards.

jyong2 added a commit to jyong2/shim that referenced this issue May 25, 2021
Fix the case where data_size is 0, so config_template is
not implicitly copied like the size calculation above.

upstream-status: rhboot#249

Signed-off-by: Jonathan Yong <jonathan.yong@intel.com>
@lcp
Copy link
Collaborator

lcp commented Jun 28, 2021

For the record, I encountered a firmware crash due to this bug. When booting my testing AArch64 shim, the firmware crashed with the following message:

ASSERT [Fat] /home/abuild/rpmbuild/BUILD/edk2-edk2-stable202105/FatPkg/EnhancedFatDxe/DirectoryCache.c(146): CR has Bad Signature

It turned out that shim accidentally overwrote the directory cache of the Fat driver and zeroed several fields of struct FAT_ODIR including Signature. With the similar fix as #365, the crash was gone and the system booted as expected.

vathpela pushed a commit that referenced this issue Jul 20, 2021
Fix the case where data_size is 0, so config_template is
not implicitly copied like the size calculation above.

upstream-status: #249

Signed-off-by: Jonathan Yong <jonathan.yong@intel.com>
@frozencemetery
Copy link
Member

I think this was closed with #365.

@jsetje
Copy link
Collaborator

jsetje commented Feb 10, 2022

For folks dealing with shims that don't have this fix:

Another symptom of this bug is that importing a single mok cert will break at least a couple versions of OVMF and hang the system. Since the corruption is caused by overrunning a buffer that's rounded to page size, two certs can be added as a workaround once the system is recovered.

At least on OVMF this symptom is (unsurprisingly) masked by 361.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants