Commit Graph

1007 Commits

Author SHA1 Message Date
Richard Hughes
48beb87faf Copy backend tags to the GUsbDevice when possible.
This allows the backend to identify the specific device for a specific phase.

For instance, there might be a pre-update runtime, a bootloader and a
post-update runtime and allowing tags to be saved to the backend object allows
us to identify each version of the same physical device.

This takes us one step closer to emulating a complete byte-perfect end-to-end
update without actual hardware installed.
2022-09-14 16:54:55 +01:00
Richard Hughes
139188a5b0 Allow adding backend tags to devices
This allows the backend to identify the specific device for a specific phase.

For instance, there might be a pre-update runtime, a bootloader and a
post-update runtime and allowing tags to be saved to the backend object allows
us to identify each version of the same physical device.

This takes us one step closer to emulating a complete byte-perfect end-to-end
update without actual hardware installed.
2022-09-14 16:54:55 +01:00
Richard Hughes
bfebede490 Add support for platform capability descriptors so devices can set quirks
This feature adds support for platform capability BOS descriptors which allows
the device itself to ship quirk data.

Use `sudo fwupdtool get-devices --save-backends=FILENAME` to save fake backend
devices to a file. This allows easy creation of self tests that do not require
physical hardware.
2022-09-13 12:07:35 +01:00
Richard Hughes
84a27ea8b9 Fix a fuzzing crash when parsing malicious FDT data 2022-09-12 13:48:45 +01:00
Richard Hughes
e358cc7bde Set the firmware contents even when subclassing ->parse() 2022-09-10 09:16:05 +01:00
Richard Hughes
ee57012df2 trivial: Work around a clang checker false-positive 2022-09-09 19:23:29 +01:00
Richard Hughes
01994a993a trivial: Fix impossible crash when the firmware search path is NULL
PVS: The 'contents' pointer was used unsafely after it was verified against nullptr.
2022-09-09 19:23:29 +01:00
Richard Hughes
9ab03d586e Fix aligning up addresses greater than 4GB
PVS: The size of the bit mask is less than the size of the first operand.
2022-09-09 19:23:29 +01:00
Richard Hughes
aa71485cc5 trivial: Fix a few theoretical memory leaks that can't happen in reality
PVS: The function was exited without releasing the 'str' pointer.
2022-09-09 19:23:29 +01:00
Richard Hughes
c3851c82c8 trivial: Remove duplicate line
PVS: Two identical blocks of text were found.
2022-09-09 19:23:29 +01:00
Richard Hughes
890a48045e trivial: Remove a duplicate line
The conditional expressions of the 'if' statements situated alongside each other are identical.
2022-09-09 19:23:29 +01:00
Richard Hughes
5014c87a2a trivial: Remove a condition that can never be non-valid
PVS: A part of conditional expression is always true: priv->children->len > 0.
2022-09-09 19:23:29 +01:00
Richard Hughes
d88e6b4a1e trivial: Relax the requirement that fu_firmware_set_bytes() can only be called once
PVS: Expression 'priv->bytes != NULL' is always false.
2022-09-09 19:23:29 +01:00
Richard Hughes
6a5eda0a44 trivial: Use G_GSSIZE_FORMAT in more places 2022-09-09 19:23:29 +01:00
Richard Hughes
80608dcac9 Allow setting the FuFirmware size when building firmware 2022-09-08 08:55:51 -05:00
Mario Limonciello
684c663dee trivial: add goshen ridge nvm version parsing 2022-09-08 09:56:33 +01:00
Richard Hughes
c43b981d63 Fix parsing uSWID uncompressed metadata
The magic offset is not required as we're working on a pre-offset GBytes.
2022-09-07 16:02:27 +01:00
Richard Hughes
9e3bd17c70 Fix parsing the coSWID firmware ID when encoded as a UUID 2022-09-07 16:02:27 +01:00
Richard Hughes
1d308b2361 trivial: Export fu_device_set_quirk_kv() for future use
This seems like a useful thing regardless.
2022-09-07 14:43:08 +01:00
Mario Limonciello
aebf33c4f6 trivial: libfwupdplugin: fix an error return string 2022-09-07 08:24:10 -05:00
Richard Hughes
89c16bfb2a Only parse the ARC_PARAMS section of the NVM if provided
The thunderbolt plugin reads in 0x80 bytes if we just want to know if a
firmware is native, and 0x224 if we just want the DIGITAL section. The reason
we do this is that reading the entire NVM is really slow.

If we can see the firmware is smaller than the ARC section, read all the
expected data and return success without adding a payload.
2022-09-06 20:45:38 +01:00
Richard Hughes
1faac75aa5 Ensure the context is set for all backends
This isn't required right now, but new functionality is much easier to add if
we know the context has always been set.
2022-09-06 20:30:21 +01:00
Richard Hughes
709af2a269 Add shared functionality to get the parsed kernel cmdline 2022-09-02 14:35:48 +01:00
Mario Limonciello
ad461d504d bios-settings: Fix plugin functionality
By moving the attribute loading into udev it was loading too late
and plugins couldn't use it.  Move the loading to earlier in the
daemon and ignore add events if we already have attributes loaded.

Fixes: #4979
2022-08-31 09:21:07 -05:00
Richard Hughes
bdfe66a16e trivial: Fix an integer overflow issue when parsing oprom images
Fixes https://oss-fuzz.com/testcase-detail/4524947132776448
2022-08-30 17:34:33 +01:00
Richard Hughes
16b463334e Export the generic Intel Thunderbolt firmware format
This is being used for other products, e.g. USB4 docks.

If non-Intel firmware is being used (e.g. ASMedia) then the explicit
calls to `fu_intel_thunderbolt_nvm_new()` can be changed to something
like `fu_firmware_new_from_gtypes()` with all the formats listed.
2022-08-30 14:20:14 +01:00
Richard Hughes
eec6de6985 Fix applying the latest DBX update on machines with 20200729.x64 installed
Use a hardcoded list of last-set dbx checksums to fix the reported version
when required.
2022-08-26 16:29:28 +01:00
Mario Limonciello
506730879d trivial: fix a minor logic error in sb/3rd party commit 2022-08-25 20:25:17 -05:00
Mario Limonciello
22b477bff5 trivial: don't allow turning on secure boot if 3rd party CA is off
Turning on UEFI secure boot on Lenovo systems with 3rd party CA
turned off will cause a boot loop.
2022-08-25 16:28:38 -05:00
Mario Limonciello
afd661963b trivial: move the FwupdBiosSetting read only map into a hashtable
This is probably going to grow in the future, so make it more efficient.
2022-08-25 14:05:24 -05:00
Mario Limonciello
df07318f36 Move FwupdBiosSetting description database into libfwupdplugin
This needs to be handled by the daemon so that all GUI clients will
be able to load translations as well.

The translations will be distributed with fwupd, and any GUI client
should look up the translations.
2022-08-25 14:05:24 -05:00
Richard Hughes
a5397c6836 Add a new vfunc to check if two firmwares are compatible
For future use.
2022-08-25 15:30:07 +01:00
Mario Limonciello
04c2186edc Add support for loading default BIOS settings policy
A user can place a JSON file in /etc/fwupd/bios-settings.d/ with
the default desired policy for the machine.

fwupd will load this policy on startup to ensure BIOS settings
are set as desired by the system administrator.
2022-08-24 12:59:42 -05:00
Mario Limonciello
2f9cb74c59 trivial: don't assume we know about pending_reboot
The `pending_reboot` variable is tracked by the kernel, make sure
that it is updated from the kernel when BIOS settings are changed.
2022-08-24 12:59:42 -05:00
Richard Hughes
fa2df1eed6 Use ID_VENDOR_ID and ID_MODEL_ID fallbacks
Some udev subsystems run probers to populate the values, rather than
just the kernel providing the sysfs files. Support reading these too.
2022-08-24 15:54:58 +01:00
Mario Limonciello
b7b0ce533d trivial: Unify ambiguity between bios-attrs and bios-settings
These are currently used interchangeably since there was indecisiveness
which to use as the feature was being developed.

As outward facing it will be named with "settings", change all uses
in the code to match this.
2022-08-24 07:20:01 -05:00
Richard Hughes
c886fb8f71 Include vfat in the list of possible BDP partition types
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2119436
2022-08-24 09:41:46 +01:00
Mario Limonciello
2045578d20 trivial: add a debugging statement to indicate BIOS settings work 2022-08-22 09:29:08 -05:00
Mario Limonciello
01d120efda trivial: Make BIOS setting parsing errors less verbose by default
The `--verbose` output for getting BIOS setting info is very noisy
on Lenovo systems due to a mismatch for the driver behavior and
kernel API.

Hide most of it behind an optional environment variable
`FWUPD_BIOS_SETTING_VERBOSE`.
2022-08-22 09:29:08 -05:00
Mario Limonciello
82e2d613aa Add GUIDs using MODALIAS as well
This will allow targeting the same thing that kernel drivers use to load the hardware
2022-08-22 06:03:19 -05:00
Mario Limonciello
2536bf462c Allow running get-bios-settings without root or PK
The only information that is secret is the `current_value`.
Augment the d-bus call to determine whether the caller needs this
information.

* If `fwupdmgr` is launched as root it will be provided.
* If `fwupdmgr` is launched with `--authenticate` it will be requested
  and PK will be engaged.
2022-08-11 09:52:26 -05:00
Mario Limonciello
7ddbe5e0b3 trivial: don't let people try to turn off UEFI secure boot
The firmware from both Dell and Lenovo actually blocks this, but the
error message is pretty confusing.

```
$ sudo fwupdtool set-bios-setting SecureBoot Disable
17:39:40:0249 FuBiosAttrs          KERNEL BUG: thinklmi doesn't export a 'type' attribute
Loading…                 [-                                      ]
failed to write 7 bytes to 17: Invalid argument
```
2022-08-10 11:09:31 -05:00
Mario Limonciello
5f0bb3dc8f Add support for translation for the sample Dell BIOS setting strings 2022-08-10 10:17:25 -05:00
Mario Limonciello
3e5fce5ffa trivial: ignore strings files in directory with drivers not attributes 2022-08-10 10:17:25 -05:00
Mario Limonciello
d51364a8b1 trivial: don't set target BIOS attribute for read only attributes
If an attribute is read only, then we'll have a failure trying to
set it.  So don't offer a target value so clients won't try to set
an attribute.x
2022-08-10 08:20:49 -05:00
Mario Limonciello
fdfdaed911 trivial: bios-attrs: fix a logic bug in lenovo string extraction
Several enumeration attributes were missing their final values
2022-08-05 14:39:48 -05:00
Mario Limonciello
04fd943abd trivial: fix a documentation comment mistake 2022-08-01 12:39:19 -05:00
Richard Hughes
0beed2f138 Store the current BIOS value in a security attribute
We can't very-well ask the user to 'change it back' if we do not tell
them what it is set to already.
2022-08-01 15:45:43 +01:00
Richard Hughes
934002553a Allow loading BIOS attributes for host emulation 2022-08-01 13:32:12 +01:00
Richard Hughes
77006b75eb Set the target value on the security attribute
Semantically it is the desire of the security attribute, not the bios
attribute, i.e. you could imagine that a specific attribute would have
to be *foo or bar or baz* for HSI-1 and *only foo* for HSI-2

Also make it easier to add possible BIOS attribute target values in
plugin code.
2022-08-01 07:12:18 +01:00
Mario Limonciello
7660222240 Add a unique identifier to all BIOSAttr objects
This identifier can be used by plugins or the daemon to disambiguate
behavior between two different drivers.

Set it up so that plugins don't NEED to use it, but optionally can
find attributes by either name or ID
2022-07-29 11:31:50 -05:00
Richard Hughes
93266d36be Fix a crash when parsing an empty BIOS attribute 2022-07-29 12:57:35 +01:00
Richard Hughes
4a78fed13c trivial: Check input parameters to fu_strsplit() 2022-07-29 12:57:35 +01:00
Mario Limonciello
5ded4f44fe Add support for reading and writing firmware attributes
This support is comprehensive:
 * Client library support
 * Daemon support
 * plugin support
 * Client tool support (with new commands)
2022-07-28 17:30:57 -05:00
Richard Hughes
829258401e Allow plugins and backends to print debugging information to the console
This is really useful for debugging.
2022-07-28 16:10:06 +01:00
Richard Hughes
b6ad1f248e trivial: Use fu_bytes_new_offset() in more places 2022-07-25 17:07:33 +01:00
Richard Hughes
0e74b89282 trivial: Enable fatal-criticals harder when fuzzing 2022-07-25 17:07:33 +01:00
Richard Hughes
66532a1293 trivial: Make fuzzing less verbose 2022-07-25 17:07:33 +01:00
Richard Hughes
9188060ce2 trivial: Reduce the debug output when fuzzing
At the moment the log is ~150,000 lines, and quite a bit of CPU time is
being spent just generating ignored XML for successful runs.
2022-07-25 17:07:33 +01:00
Mario Limonciello
4a02a154fe trivial: don't use /proc/self/exe on Windows
Fixes: #4864
2022-07-24 09:27:16 -05:00
Richard Hughes
8dc50c086f Fix a crash when a peripheral uses _USE_PARENT_FOR_BATTERY
Call the parent class method to avoid getting stuck in a recursive loop
which eventually causes the daemon to segfault.
2022-07-21 21:27:24 +01:00
Richard Hughes
74e9b04b39 trivial: Return a more invalid value if FWUPD_IS_DEVICE() fails
We don't want to return something that's actually the initial value.
2022-07-21 21:27:24 +01:00
Richard Hughes
221238b4c0 trivial: Allow each device to specify a different acquiesce delay
Different device classes may need different values, and these may need
modifying by quirks. Also use 50ms to flush out any pending events.
2022-07-21 15:27:04 +01:00
Richard Hughes
4f9b455880 Add UDev devices to the _REQUIRES_ACQUIESCE opt-in 2022-07-21 15:27:04 +01:00
Mario Limonciello
445a8af362 fu-smbios: Fix parsing smbios data
When support was added for falling back to SMBIOS data from the kernel
in /sys/class/dmi, we inadvertently stopped caring about the data parsed
directly from DMI tables as first priority.  This caused a regression in
hwids from some OEMs that relied upon IDs that could only be properly built
from DMI tables, not the kernel /sys/class/dmi interface.

Link: https://bugs.launchpad.net/ubuntu/+source/fwupd/+bug/1982103
Fixes: 464425fb5 ("SMBIOS: try reading from /sys/class/dmi if direct access fails")
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
2022-07-20 16:23:56 -05:00
Richard Hughes
847151a51a Wait for the system to acquiesce after doing each update
We want to allow all the device hotplug events to be processed before
marking the update as completed. Otherwise, we might have a situation
where we have a child device attached to a parent, where we want to
update the parent, then the child. e.g.

 1. Add parent
 2. Add child
 3. Update parent
 4. Attach parent
 5. Wait for parent

...some time passes...

 6. Parent re-appears
 7. Update finishes, client indicates success

...child update is scheduled...
...which returns with failure as it does not exist...

 8. Add child

The child should have been added *before* the update completed to avoid
the caller from needing an unspecified delay as a *workaround*.
2022-07-20 19:10:12 +01:00
Richard Hughes
f336a43936 Avoid duplicate device actions where possible
This removes at least two open(),probe(),setup(),close() chains for the
common case where the vfuncs are not implemented.
2022-07-20 19:01:02 +01:00
Richard Hughes
62fc515714 Allow loading in emulated host profiles for debugging
This allows us to load sets of different host security attributes
for testing the various front end tools we have now. e.g.

    sudo FWUPD_HOST_EMULATE=thinkpad-p1-iommu.json.gz fwupd

or, using a non-compressed absolute path:

    sudo FWUPD_HOST_EMULATE=/tmp/test/thinkpad-p1-iommu.json fwupd

Data can be created with `./contrib/generate-emulation.py file.json`
and then can be manually modified if required. Running the script on
a file that already exists will just strip out any unneeded data, as
well as piping content into it using stdin.

As a precaution, the org.fwupd.hsi.HostEmulation attribute is added
so we do not ask the user to upload the HSI report. It also allows
the LVFS to ignore any HSI reports with this attribute for clients
that upload HSI reports regardless.

See https://github.com/fwupd/fwupd/discussions/4832
2022-07-18 16:27:59 +01:00
Richard Hughes
fdc5131dca Only validate source artifacts at cabinet load time
The LVFS was being over-eager, and setting 'binary' for both -- but
for new firmware it's important to specify the correct thing.
2022-07-18 16:12:43 +01:00
Richard Hughes
a5749f4d23 Set the HSI levels in a central place
This means we don't need to worry about changing multiple
implementations if the HSI levels change for a specific ID.

It also means we can fake HSI results in the future without having
to also store the 'correct' level in the input file.
2022-07-15 20:21:22 +01:00
Richard Hughes
dc91444b46 trivial: Export fu_security_attrs_get_by_appstream_id() for future use 2022-07-14 14:49:00 +01:00
Richard Hughes
0c51630991 Check firmware magic in a more standard way
Some parsers are ignoring the magic when using _FLAG_IGNORE_CHECKSUM
(which is wrong; fuzzers have no problem with enforcing a static prefix)
and other either disregard the offset or check the magic in an unsafe
way. Also, use FWUPD_ERROR_INVALID_FILE consistently for magic failure.

Add a vfunc, and move all the clever code into one place.
2022-07-14 14:48:15 +01:00
Richard Hughes
a06dedb253 trivial: Add a fu_memread_uint24_safe() to make some code more correct 2022-07-14 11:03:13 +01:00
Richard Hughes
1ffc2608b0 Check for overflow when copying buffers with huge offset values 2022-07-13 22:04:10 +01:00
Richard Hughes
56e5c1b7a9 Fix critical warning when parsing invalid FDT firmware
Never let firmware_current be NULL by checking for the root node ENDing.

Fixes https://oss-fuzz.com/testcase-detail/5454411320655872
2022-07-13 22:04:01 +01:00
Richard Hughes
3b71918346 trivial: Remove some dead code spotted by Coverity 2022-07-11 10:17:59 +01:00
Richard Hughes
71c0641394 trivial: Fix a -Wunused-function warning on Windows 2022-07-10 11:15:16 +01:00
Richard Hughes
a6b96e2330 Use the SHA256 binary hash for the quirk GResource key
There's no security issue, but it's one less thing I have to justify
during a security review.
2022-07-09 14:56:28 +01:00
Richard Hughes
15536eb1bc Do not make failing to parse the i2c bus number fatal
This acccidentally become more strict in bb548f15f0 and means there
should be no more false-positive daemon warnings at startup.

Fixes the 2nd half of https://github.com/fwupd/fwupd/discussions/4810
2022-07-08 17:24:26 +01:00
Richard Hughes
6f5ebc5492 Handle ENOTTY with the correct error code for ioctl calls
Fixes half of https://github.com/fwupd/fwupd/discussions/4810
2022-07-08 16:25:38 +01:00
Richard Hughes
cb0966858d Fix fuzzing timeout in the new IFW CPD parsing
Limit the number of images to an order of magnitide more than we've ever seen.

Fixes https://oss-fuzz.com/testcase-detail/4842982326534144
2022-07-08 15:17:25 +01:00
Richard Hughes
7a224007f2 Add support for Flat Image Tree aka FIT firmware 2022-07-08 14:05:20 +01:00
Richard Hughes
f3755ef708 Add support for Flattened Devicetree aka FDT firmware 2022-07-08 14:05:20 +01:00
Richard Hughes
57a1270bad Add fu_firmware_get_parent() for future use
Some firmware stacks images hierarchically, and it's useful to be able
to get the parent when unrolling them out into a linear format.
2022-07-05 16:47:18 +01:00
Richard Hughes
e6fee15d3c
Skip uSWID self tests when compiled without cbor support (#4800)
Fixes https://github.com/fwupd/fwupd/issues/4791
2022-07-05 10:20:46 +00:00
Richard Hughes
165b450e80 trivial: Fix a tiny memory leak caused by VENDOR_FROM_PARENT 2022-07-01 14:57:41 +01:00
Richard Hughes
be6af6d11c trivial: Fix a tiny memory leak when parsing oprom firmware 2022-07-01 13:57:18 +01:00
Richard Hughes
de31992522 trivial: Fix a tiny memory leak in the self tests 2022-07-01 13:57:18 +01:00
Richard Hughes
91cb4e7274 trivial: Relax some timings a little to fix running valgrind 2022-07-01 13:57:18 +01:00
Richard Hughes
726d20e498 Ensure more firmware formats can round-trip to and from XML
This greatly improves the coverage stats too.
2022-07-01 13:57:18 +01:00
Richard Hughes
95f7d23d58 Fix FuCfuOffer XML roundtrip 2022-07-01 13:57:18 +01:00
Richard Hughes
d7479423a0 trivial: Add SUBSYS instance data if *either* of the vendor or model are set 2022-06-30 19:06:38 +01:00
Richard Hughes
ced79fce4a Create the better device GType in the backend
It is weird to do this when constructing the object, and it allows us
to match PossiblePlugin quirk matches on potentially better instance
IDs added by the superclass.
2022-06-30 19:06:38 +01:00
Richard Hughes
bb548f15f0 Fix segfault when parsing an invalid i2c device
Confusingly, g_regex_match_full() returns FALSE and doesn't always set
the GError. Just use g_path_get_basename() and g_str_has_prefix().
2022-06-30 19:06:38 +01:00
Richard Hughes
7b96c2e6cd trivial: Implement FuMeiDevice->incorporate() 2022-06-30 19:06:38 +01:00
Richard Hughes
a694a1d915 trivial: Implement FuI2cDevice->incorporate() 2022-06-30 19:06:38 +01:00
Richard Hughes
006c75a82d trivial: Only print the MEI private data if set 2022-06-30 19:06:38 +01:00
Richard Hughes
a61bb37881 Build the quirk files into the daemon as a GResource
Interestingly, this increases the `fwupd` binary size by ~30kb but
reduces the installed size of /usr/share/fwupd/quirks.d by ~330kb.
2022-06-30 18:52:24 +01:00
Richard Hughes
6ac6372b2a trivial: Make the FuUdevDevice->to_string() more complete 2022-06-30 14:17:53 +01:00
Richard Hughes
c7b3cd5b8a Fix a hidraw regression
Ensure that udev_parent is actually set before checking it for NULL.
2022-06-30 14:17:53 +01:00