Commit Graph

6 Commits

Author SHA1 Message Date
Mark Langsdorf 8718eb48bb firmware_loader: Fix memory leak in firmware upload
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318

commit 789bba82f63c3e81dce426ba457fc7905b30ac6e
Author: Russ Weight <russell.h.weight@intel.com>
Date:   Tue Aug 30 17:25:18 2022 -0700

In the case of firmware-upload, an instance of struct fw_upload is
allocated in firmware_upload_register(). This data needs to be freed
in fw_dev_release(). Create a new fw_upload_free() function in
sysfs_upload.c to handle the firmware-upload specific memory frees
and incorporate the missing kfree call for the fw_upload structure.

Fixes: 97730bbb242c ("firmware_loader: Add firmware-upload support")
Cc: stable <stable@kernel.org>
Signed-off-by: Russ Weight <russell.h.weight@intel.com>
Link: https://lore.kernel.org/r/20220831002518.465274-1-russell.h.weight@intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-25 15:20:23 -04:00
Mark Langsdorf fda3ab0b1c firmware_loader: Fix use-after-free during unregister
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318

commit 8b40c38e37492b5bdf8e95b46b5cca9517a9957a
Author: Russ Weight <russell.h.weight@intel.com>
Date:   Mon Aug 29 10:45:57 2022 -0700

In the following code within firmware_upload_unregister(), the call to
device_unregister() could result in the dev_release function freeing the
fw_upload_priv structure before it is dereferenced for the call to
module_put(). This bug was found by the kernel test robot using
CONFIG_KASAN while running the firmware selftests.

  device_unregister(&fw_sysfs->dev);
  module_put(fw_upload_priv->module);

The problem is fixed by copying fw_upload_priv->module to a local variable
for use when calling device_unregister().

Fixes: 97730bbb242c ("firmware_loader: Add firmware-upload support")
Cc: stable <stable@kernel.org>
Reported-by: kernel test robot <oliver.sang@intel.com>
Reviewed-by: Matthew Gerlach <matthew.gerlach@linux.intel.com>
Signed-off-by: Russ Weight <russell.h.weight@intel.com>
Link: https://lore.kernel.org/r/20220829174557.437047-1-russell.h.weight@intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-25 15:20:23 -04:00
Mark Langsdorf 12cbe32e96 firmware_loader: describe 'module' parameter of firmware_upload_register()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318

commit 6370b04f24bc10c1f2056c0f12dd651ac0121a6f
Author: Bagas Sanjaya <bagasdotme@gmail.com>
Date: Mon, 2 May 2022 12:14:56 +0700

Stephen Rothwell reported kernel-doc warning:

drivers/base/firmware_loader/sysfs_upload.c:285: warning: Function parameter or member 'module' not described in 'firmware_upload_register'

Fix the warning by describing the 'module' parameter.

Link: https://lore.kernel.org/linux-next/20220502083658.266d55f8@canb.auug.org.au/
Fixes: 97730bbb242cde ("firmware_loader: Add firmware-upload support")
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Russ Weight <russell.h.weight@intel.com>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Cc: Linux Next Mailing List <linux-next@vger.kernel.org>
Reviewed-by: Russ Weight <russell.h.weight@intel.com>
Signed-off-by: Bagas Sanjaya <bagasdotme@gmail.com>
Link: https://lore.kernel.org/r/20220502051456.30741-1-bagasdotme@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-25 15:20:23 -04:00
Mark Langsdorf 952d6c7edf firmware_loader: Move definitions from sysfs_upload.h to sysfs.h
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318

commit f8ae07f4b8bfde0f33761e1a1aaee45a4e85e9d6
Author: Russ Weight <russell.h.weight@intel.com>
Date: Tue, 26 Apr 2022 13:03:56 -0700

Move definitions required by sysfs.c from sysfs_upload.h to sysfs.h so
that sysfs.c does not need to include sysfs_upload.h.

Signed-off-by: Russ Weight <russell.h.weight@intel.com>
Link: https://lore.kernel.org/r/20220426200356.126085-3-russell.h.weight@intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-25 15:20:23 -04:00
Mark Langsdorf e34757c3de firmware_loader: Add sysfs nodes to monitor fw_upload
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318

commit 536fd8184b7dfa30e28e5b459e7c5c91c3a8063f
Author: Russ Weight <russell.h.weight@intel.com>
Date: Thu, 21 Apr 2022 14:22:01 -0700

Add additional sysfs nodes to monitor the transfer of firmware upload data
to the target device:

cancel: Write 1 to cancel the data transfer
error: Display error status for a failed firmware upload
remaining_size: Display the remaining amount of data to be transferred
status: Display the progress of the firmware upload

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Reviewed-by: Tianfei zhang <tianfei.zhang@intel.com>
Tested-by: Matthew Gerlach <matthew.gerlach@linux.intel.com>
Signed-off-by: Russ Weight <russell.h.weight@intel.com>
Link: https://lore.kernel.org/r/20220421212204.36052-6-russell.h.weight@intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-25 15:20:23 -04:00
Mark Langsdorf ae5143e8c7 firmware_loader: Add firmware-upload support
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318

commit 97730bbb242cde22b7140acd202ffd88823886c9
Author: Russ Weight <russell.h.weight@intel.com>
Date: Thu, 21 Apr 2022 14:22:00 -0700

Extend the firmware subsystem to support a persistent sysfs interface that
userspace may use to initiate a firmware update. For example, FPGA based
PCIe cards load firmware and FPGA images from local FLASH when the card
boots. The images in FLASH may be updated with new images provided by the
user at his/her convenience.

A device driver may call firmware_upload_register() to expose persistent
"loading" and "data" sysfs files. These files are used in the same way as
the fallback sysfs "loading" and "data" files. When 0 is written to
"loading" to complete the write of firmware data, the data is transferred
to the lower-level driver using pre-registered call-back functions. The
data transfer is done in the context of a kernel worker thread.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Reviewed-by: Tianfei zhang <tianfei.zhang@intel.com>
Tested-by: Matthew Gerlach <matthew.gerlach@linux.intel.com>
Signed-off-by: Russ Weight <russell.h.weight@intel.com>
Link: https://lore.kernel.org/r/20220421212204.36052-5-russell.h.weight@intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-25 15:20:18 -04:00