linuxhelper's kern_set_EFI_variable only sets default value for attr if no
value has been passed in. In some call-chains (uefi var-write) however None
is being passed in, resulting in the following error from:
struct.error: required argument is not an integer
Make attr optional input and override if value is None with default value.
Signed-off-by: Tamas K Lengyel <tamas.lengyel@oracle.com>
Currently the common.uefi.access_uefispec -a modify test modifications to variables
with the default variable attribute of nv | bs | rs (0x7). In this patch we make
this behavior more configurable.
By default the -a modify option will attempt to modify only the content of the variable,
but will not attempt to change the existing attributes of the variable. We have observed
cases where the test used this way uncovered more issues on variables where different
attributes were used and we did not attempt changing the attribute.
By specifying an optional attribute with -a modify,<attribute> the user can now test
variable modification with any attribute instead of just the currently hard-coded one.
Signed-off-by: Tamas K Lengyel <tamas.lengyel@oracle.com>
* Convert str to byte object in linuxhelper's kern_set_EFI_variable
This is required to be able to successfuly run the common.uefi.access_uefispec -a modify
test from under Linux and resolve the following error:
ERROR: Exception occurred during chipsec.modules.common.uefi.access_uefispec.run(): 'argument for 's' must be a bytes object'
Signed-off-by: Tamas K Lengyel <tamas.lengyel@oracle.com>
* Use recommended best practice isinstance for type checking
Co-authored-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
---------
Signed-off-by: Tamas K Lengyel <tamas.lengyel@oracle.com>
Co-authored-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
* Add Win Cert types to uefi_fv and spi_uefi
* Move uefi search to library.uefi folder
* Move uefi_fv to library.uefi
* Move uefi_compression to library.uefi>
* Move uefi_common to library.uefi
* Move uefi_platform to library.uefi
* Move spi_uefi to library.uefi
* Add library.uefi.sleep_scripts file
* Move S3 functionality into sleep_state file
* Add varstore and variable files to library.uefi
* Fixup Flake8 suggestions
* Rename library uefi files to remove uefi_
* This change changes the filename of any file under the library.uefi to remove the uefi as part of the name.
* Fix Errors when testing changes
Signed-off-by: brentholtsclaw <brent.holtsclaw@intel.com>
`print_buffer_bytes` can directly handle bytes, instead of converting
them to a string.
While at it, replace buggy calls to `print_buffer(buffer)` (when
`buffer` uses type `bytes`) with `print_buffer_bytes(buffer)`.
This fixes `./chipsec_util.py idt 0`. Before it failed with:
[CHIPSEC] Dumping IDT of 8 CPU threads
[cpu0] Physical Address: 0x000000036639E000
[cpu0] # of entries : 256
[cpu0] Contents (4 entries):
Traceback (most recent call last):
File "./chipsec_util.py", line 210, in <module>
sys.exit(main())
File "./chipsec_util.py", line 205, in main
return chipsecMain.main()
File "./chipsec_util.py", line 190, in main
comm.run()
File "chipsec/utilcmd/desc_cmd.py", line 84, in run
self.cs.msr.IDT_all(4)
File "chipsec/hal/msr.py", line 166, in IDT_all
self.IDT(tid, num_entries)
File "chipsec/hal/msr.py", line 158, in IDT
return self.dump_Descriptor_Table(cpu_thread_id, DESCRIPTOR_TABLE_CODE_IDTR, num_entries)
File "chipsec/hal/msr.py", line 144, in dump_Descriptor_Table
print_buffer(dt)
File "chipsec/logger.py", line 493, in print_buffer
prt_str = bytes2string(arr, length)
File "chipsec/logger.py", line 466, in bytes2string
num_string += [f'{ord(c):02X} ']
TypeError: ord() expected string of length 1, but int found
There was another bug in `hal/msr.py` where `ord(dt[...])` was used
instead of `dt`.
Signed-off-by: Nicolas Iooss <nicolas.iooss_git@polytechnique.org>
When running on native mode the initial bus enumeration does 64k pci
accesses and each one creates an instance of LEGACY_PCI.
The LEGACY_PCI object can be reused for the full lifetime of the helper
saving a couple seconds on each chipsec invocation.
Signed-off-by: Ignacio Hernandez <ignacio.hernandez@intel.com>
When the kernel module is already loaded, don't unload and try to load
it again.
This is not only useful during development where one might change the
kernel module code often and load it manually but also for setups that
lift the strict access restrictions to /dev/chipsec, e.g. to allow a
non-root group access to its interface.
Signed-off-by: Mathias Krause <minipli@grsecurity.net>
On Arch Linux, `chipsec_main` fails:
################################################################
## ##
## CHIPSEC: Platform Hardware Security Assessment Framework ##
## ##
################################################################
[CHIPSEC] Version 1.5.10
[CHIPSEC] Arguments:
insmod: ERROR: could not insert module /var/lib/dkms/chipsec/1.5.10/
5.11.6-arch1-1/x86_64/module/chipsec.ko.xz: Operation not permitted
ERROR: Message: "Could not start Linux Helper, are you running as Admin/root?
{}.format(err)"
Showing `{}.format(err)` is a bug caused by a misplaced quote. With the
quote in the right position, the error is clearer:
ERROR: Message: "Could not start Linux Helper, are you running as Admin/root?
Command '['insmod', '/var/lib/dkms/chipsec/1.5.10/5.11.6-arch1-1/
x86_64/module/chipsec.ko.xz', '', '']' returned non-zero exit
status 1."
mmap() makes all the accesses to memory using a byte granularity,
when dealing with mmio registers that is not optimal and need to
perform the access at dword granularity
Signed-off-by: Ignacio Hernandez <ignacio.hernandez@intel.com>