Commit Graph

105 Commits

Author SHA1 Message Date
Richard Hughes
7453d59ccf trivial: Fix a small memory leak in the self tests 2021-10-27 15:57:53 +01:00
Richard Hughes
28678235cd Move the fuzzing files into the plugin directories
We only had to pile everything into the src/fuzzing/firmware directory
because honggfuzz could not cope with more than one input path.

This way each plugin is self contained and easy to copy.
Also, install the fuzzing builder objects as this fixes the installed
tests when srcdir does not exist.

Based on a patch by Jan Tojnar <jtojnar@gmail.com>, many thanks.
2021-10-22 15:24:05 +01:00
Richard Hughes
2d00cda464 Remove PLUGINBUILDDIR and use G_TEST_SRCDIR and G_TEST_BUILDDIR instead
This allows us to override the location we load data files from, which
allows us to do more kinds of installed tests in the future.

Also, move the global data/tests content into the place that it is used
as it was getting impossible to manage.
2021-10-21 18:36:22 +01:00
Richard Hughes
6235a8222a Share the Common Flash Memory Interface quirks between plugins
Now two plugins are using hardcoded SPI constants for various CFI chips,
and it makes sense to have some common quirk data that can be used by
both.

Add a FuSpiChip helper object that can be used by FuDevice subclasses
to get the specific SPI commands to use for each flash ID.
2021-10-20 12:19:39 +01:00
Richard Hughes
478e44bc19 trivial: Do not use g_assert() in self test code
Note that g_assert() should not be used in unit tests, since it is a
no-op when compiling with G_DISABLE_ASSERT. Use g_assert() in production
code, and g_assert_true() in unit tests.

See https://github.com/fwupd/fwupd/issues/3790
2021-09-24 22:20:21 +01:00
Richard Hughes
543ae52e23 Document some of the environment variables used by fwupd
Fixes https://github.com/fwupd/fwupd/issues/3760
2021-09-21 10:25:12 +01:00
Richard Hughes
3162c8540d Add new API for splitting an untrusted string
Using fu_common_strnsplit() has the drawback that a malicious user (or
a fuzzer!) could create a file with 5,000,000 newlines, and then pass
that into any parser that tokenizes into lines. This causes millions of
tiny allocations and quickly dirties hundreds of megabytes of RSS due
to heap overheads.

Rather than splitting a huge array and then processing each line, set
up a callback to process each line and only allocate the next string if
the token was parsed correctly. This means that we don't even dup the
buffer before we start parsing, rather than allocating everything and
then failing at the first hurdle.

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=38696
2021-09-17 14:46:45 +01:00
Richard Hughes
320f8d7d90 Update the child composite ID if the parent changes
Typically, this can be triggered with:

 * create parent
 * set parent physical ID
 * add new child to parent
 * set parent logical ID
2021-09-16 07:44:44 +01:00
Richard Hughes
40cd18fa97 Allow using a per-device global percentage completion
It's actually quite hard to build a front-end for fwupd at the moment
as you're never sure when the progress bar is going to zip back to 0%
and start all over again. Some plugins go 0..100% for write, others
go 0..100% for erase, then again for write, then *again* for verify.

By creating a helper object we can easily split up the progress of the
specific task, e.g. write_firmware().

We can encode at the plugin level "the erase takes 50% of the time, the
write takes 40% and the read takes 10%". This means we can have a
progressbar which goes up just once at a consistent speed.
2021-09-13 14:28:15 +01:00
Richard Hughes
9c6f676656 Actually check for parse errors when using fu_firmware_strparse_uintX_safe
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=38141
2021-09-05 15:46:00 +01:00
Mario Limonciello
41c00ff404 trivial: libfwupdplugin: make the self tests not overwrite source folders 2021-09-03 15:10:38 -05:00
Mario Limonciello
55de39c077 trivial: reformat the whole tree to match new format 2021-08-24 11:18:40 -05:00
Mario Limonciello
7ae233b7cf Forcefully set checksums found in cabinet files to lowercase
Archives uploaded to LVFS will have checksums written by hexdigest
and be set to lowercase, but hand generated archives this may not
be true.

For maximum compatibility with the most fwupd versions they should
be written in lowercase, but in case they aren't, convert to lowercase.

Reference https://github.com/fwupd/firmware-lenovo-thinkpad/issues/145
2021-08-18 14:18:28 -05:00
Richard Hughes
8f19ea75d3 Sanitize the device name harder 2021-08-03 15:45:37 +01:00
Richard Hughes
4daaabe451 trivial: Do not log a scary warning for the common case 2021-07-30 18:53:30 +01:00
Peter Marheine
464425fb5c SMBIOS: try reading from /sys/class/dmi if direct access fails
The raw SMBIOS tables that Linux exposes in /sys/firmware/dmi
are restricted to being readable by root only. If running as
non-root access is still permitted by fields that have been
pre-parsed by the kernel in /sys/class/dmi, most of which are
world-readable. This allows the daemon to load most HWIDs even
if running as a non-root user, as is done on Chromium OS.
2021-07-23 09:46:45 +01:00
Richard Hughes
f2fd6b0717 trivial: Do not save the self test quirk silo to disk
This also speeds up the tests as the amount of pointless i/o is reduced.

Fixes https://github.com/fwupd/fwupd/issues/3522
2021-07-22 12:51:47 +01:00
Richard Hughes
9c31d1fadd trivial: Set the FuContext on more devices 2021-07-12 19:01:55 +01:00
Richard Hughes
488f2e1f37 Export the EFI and IFD parsers
We'll need to use this from another plugin soon.
2021-07-12 10:33:38 +01:00
Richard Hughes
5458480356 Add a flag which inhibits children automatically
Fixes https://github.com/fwupd/fwupd/issues/3454
2021-07-07 12:50:27 +01:00
Richard Hughes
7b209bb2c1 Watch for children added or removed after setup has been completed
Some devices may 'discover' child devices during poll, rather than the
more usual case of adding them as children during setup.
2021-07-02 13:27:10 +01:00
Richard Hughes
1cee26eba9 Remove the vendor string from the device name where required
This means we don't display something like 'Logitech Logitech Product'
when showing the devices on one line.

This is now required in two plugins so move it to common code. Also
support setting the properties in either order to prevent regressions
when using the device name as part of the instance ID.
2021-06-30 18:43:07 +01:00
Richard Hughes
aaa77c6f51 Allow adding and removing custom flags on devices
The CustomFlags feature is a bit of a hack where we just join the flags
and store in the device metadata section as a string. This makes it
inefficient to check if just one flag exists as we have to split the
string to a temporary array each time.

Rather than adding to the hack by splitting, appending (if not exists)
then joining again, store the flags in the plugin privdata directly.

This allows us to support negating custom properties (e.g. ~hint) and
also allows quirks to append custom values without duplicating them on
each GUID match, e.g.

[USB\VID_17EF&PID_307F]
Plugin = customflag1
[USB\VID_17EF&PID_307F&HUB_0002]
Flags = customflag2

...would result in customflag1,customflag2 which is the same as you'd
get from an enumerated device flag doing the same thing.
2021-06-23 07:59:15 +01:00
Richard Hughes
a5a82ba519 trivial: Fix the FuDeviceInternalFlags conversion funcs 2021-06-15 10:18:24 +01:00
Mario Limonciello
73cdf067ed trivial: fixup includes for a variety of plugins 2021-06-14 10:12:45 +01:00
Richard Hughes
d783594ea5 Make fu_common_convert_to_gpt_type() FreeBSD compatible
Based on a patch by Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2021-06-07 19:54:12 +01:00
Richard Hughes
dfb46d9b56 trivial: Add fu_backend_get_devices() for future use 2021-05-25 17:17:45 +01:00
Richard Hughes
76602389ff Export FuBackend into libfwupdplugin for future use 2021-05-25 17:17:45 +01:00
Richard Hughes
3cb08d81c5 trivial: Remove unused variable from self tests 2021-05-21 15:34:21 +01:00
Richard Hughes
54d9de9290 Force the device locker to ->close() an aborted ->open()
Fixes https://github.com/fwupd/fwupd/issues/3187
2021-05-12 10:10:57 +01:00
Richard Hughes
ffcaf14021 trivial: Skip the fmap tests when memmem is not available 2021-05-04 09:45:03 +01:00
Richard Hughes
29e04f926d trivial: Skip the efivar tests on Windows 2021-05-04 09:45:03 +01:00
Richard Hughes
7b7eb9e9b5 trivial: Skip the lockdown tests on Windows 2021-05-04 09:45:03 +01:00
Richard Hughes
495302ca06 Support binary artifact resources in cabinet archives
Fixes the other half of https://github.com/fwupd/fwupd/issues/3193
2021-04-28 15:52:26 +01:00
Richard Hughes
c6bb21356f Support all hash types when loading cabinet archives
Fixes half of https://github.com/fwupd/fwupd/issues/3193
2021-04-27 15:41:44 +01:00
Richard Hughes
63bc42eace Add a composite ID that is used to identify all devices in the same physical package 2021-04-22 16:27:04 +01:00
Richard Hughes
e65d28d817 Add a utility to resign firmware files
This can be used like this:

    fwupdtool firmware-sign firmware.cab rhughes_signed.pem rhughes.key

Test signing certificates can be generated using the example script here:
https://github.com/hughsie/libjcat/blob/master/contrib/build-certs.py although
these certificates should not be used for enterprise use.
2021-04-19 12:59:35 +01:00
Richard Hughes
7f6f525f21 Add fu_bytes_get_data_safe() to check for zero sized data
Fixes https://github.com/fwupd/fwupd/issues/3122
2021-04-10 13:20:07 +01:00
Richard Hughes
b333e0045c Split out a shared system context
There is a lot of code in fwupd that just assigns a shared object type to
a FuPlugin, and then for each device on that plugin assigns that same shared
object to each FuDevice.

Rather than proxy several kinds of information stores over two different levels
of abstraction create a 'context' which contains the shared *system* state
between the daemon, the plugins and the daemon.

This will allow us to hold other per-machine state in the future, for instance
the system battery level or AC state.
2021-04-01 21:11:29 +01:00
Richard Hughes
a3b8515e51 trivial: Inhibit when the *device* power is below the threshold 2021-03-31 19:19:46 +01:00
Richard Hughes
b9ac0bc029 Add fu_device_inhibit() to mark the device as non-updatable
We already have two things managing the UPDATABLE_HIDDEN->UPDATABLE transition,
and we're about to add a third.

Add a 'stackable' inhibit-style API so we do not accidentally mark a device as
updatable when it should remain hidden.
2021-03-31 19:19:46 +01:00
Richard Hughes
52441f28a4 Allow objects to deserialize to XML
This makes a lot more sense; we can parse a firmware and export the same XML
we would use in a .builder.xml file. This allows us to two two things:

 * Check we can round trip from XML -> binary -> XML

 * Using a .builder.xml file we can check ->write() is endian safe
2021-03-15 12:07:30 +00:00
Richard Hughes
58d52ede18 trivial: Add fu_common_align_up() for future usage 2021-03-10 17:06:57 +00:00
Richard Hughes
1981c63d58 Remove FuFirmwareImage and just use FuFirmware instead
This allows us to 'nest' firmware formats, and removes a ton of duplication.

The aim here is to deprecate FuFirmwareImage -- it's almost always acting
as a 'child' FuFirmware instance, and even copies most of the vfuncs to allow
custom types. If I'm struggling to work out what should be a FuFirmware and
what should be a FuFirmwareImage then a plugin author has no hope.

For simple payloads we were adding bytes into an image and then the image into
a firmware. This gets really messy when most plugins are treating the FuFirmware
*as* the binary firmware file.

The GBytes saved in the FuFirmware would be considered the payload with the
aim of not using FuFirmwareImage in the single-image case.
2021-03-09 21:14:12 +00:00
Richard Hughes
c81b755872 Be more strict for custom quirk keys
Rather than trying to guess typos, force each plugin to register the quirk
keys it supports, so we can show a sensible warning if required at startup on
the console.
2021-03-03 08:30:34 +00:00
Richard Hughes
7d132b728c Simplify the quirk file format
The best way of not getting something wrong is to not require it in the first
place...

All plugins now use DeviceInstanceId-style quirk matches and we can just drop
the prefix in all files. We were treating HwId=, Guid= and DeviceInstanceId= in
exactly the same way -- they're just converted to GUIDs when building the silo!
2021-03-03 08:30:34 +00:00
Richard Hughes
c3ecec575b fmap: Use memmem to find the FMAP signature
Trust glibc to optimize for the binary search, removing a oss-fuzz detected
crash with our bad pointer maths.
2021-02-11 20:27:20 +00:00
Richard Hughes
87a8091bed trivial: Fix a crash using fu_firmware_image_get_chunks()
Add a GError as it can return NULL for invalid circumstances. It's okay to
change the API as this symbol has not yet been in a tarball release.
2021-02-11 13:13:06 +00:00
Richard Hughes
98972f4a34 libfwupdplugin: Promote DfuFirmware to FuDfuseFirmware
Port the DFU plugin to use the new objects to make it act the same as all the
other plugins.
2021-02-01 19:34:28 +00:00
Richard Hughes
1d163528ab Add fu_firmware_new_from_gtypes() for future usage
This allows a plugin to define a 'set' of firmwares that it would find
acceptable, for instance either accepting DFU, DfuSe or just a plain binary.
2021-01-29 18:18:18 +00:00