Skip to content

Commit c563579

Browse files
JDYuesumananna
authored andcommitted
remoteproc: core: Remove casting to rproc_handle_resource_t
There are four different callback functions that are used for the rproc_handle_resource_t callback that all have different second parameter types. rproc_handle_vdev -> struct fw_rsc_vdev rproc_handle_trace -> struct fw_rsc_trace rproc_handle_devmem -> struct fw_rsc_devmem rproc_handle_carveout -> struct fw_rsc_carveout These callbacks are cast to rproc_handle_resource_t so that there is no error about incompatible pointer types. Unfortunately, this is a Clang's Control-Flow Integrity checking violation, which verifies that the callback function's types match the prototypes exactly before jumping. [ 7.275750] Kernel panic - not syncing: CFI failure (target: rproc_handle_vdev+0x0/0x4) [ 7.283763] CPU: 2 PID: 1 Comm: init Tainted: G C O 5.4.70-03301-g527af2c96672 #17 [ 7.292463] Hardware name: NXP i.MX8MPlus EVK board (DT) [ 7.297779] Call trace: [ 7.300232] dump_backtrace.cfi_jt+0x0/0x4 [ 7.304337] show_stack+0x18/0x24 [ 7.307660] dump_stack+0xb8/0x114 [ 7.311069] panic+0x164/0x3d4 [ 7.314130] __ubsan_handle_cfi_check_fail_abort+0x0/0x14 [ 7.319533] perf_proc_update_handler+0x0/0xcc [ 7.323983] __cfi_check+0x63278/0x6a290 [ 7.327913] rproc_boot+0x3f8/0x738 [ 7.331404] rproc_add+0x68/0x110 [ 7.334738] imx_rproc_probe+0x5e4/0x708 [imx_rproc] [ 7.339711] platform_drv_probe+0xac/0xf0 [ 7.343726] really_probe+0x260/0x65c [ 7.347393] driver_probe_device+0x64/0x100 [ 7.351580] device_driver_attach+0x6c/0xac [ 7.355766] __driver_attach+0xdc/0x184 [ 7.359609] bus_for_each_dev+0x98/0x104 [ 7.363537] driver_attach+0x24/0x30 [ 7.367117] bus_add_driver+0x100/0x1e0 [ 7.370958] driver_register+0x78/0x114 [ 7.374800] __platform_driver_register+0x44/0x50 [ 7.379514] init_module+0x20/0xfe8 [imx_rproc] [ 7.384049] do_one_initcall+0x190/0x348 [ 7.387979] do_init_module+0x5c/0x210 [ 7.391731] load_module+0x2fbc/0x3590 [ 7.395485] __arm64_sys_finit_module+0xb8/0xec [ 7.400025] el0_svc_common+0xb4/0x19c [ 7.403777] el0_svc_handler+0x74/0x98 [ 7.407531] el0_svc+0x8/0xc [ 7.410419] SMP: stopping secondary CPUs [ 7.414648] Kernel Offset: disabled [ 7.418142] CPU features: 0x00010002,2000200c [ 7.422501] Memory Limit: none To fix this, change the second parameter of all functions to void * and use a local variable with the correct type so that everything works properly. With this, we can remove casting to rproc_handle_resource_t for these functions. Signed-off-by: Jindong Yue <[email protected]> Reviewed-by: Peng Fan <[email protected]> Reviewed-by: Sami Tolvanen <[email protected]> Reviewed-by: Mathieu Poirier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bjorn Andersson <[email protected]> [[email protected]: cherry-pick linux-next commit '2bf2346159bc' for v5.13] Signed-off-by: Suman Anna <[email protected]>
1 parent cd9d2e0 commit c563579

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

drivers/remoteproc/remoteproc_core.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ static int copy_dma_range_map(struct device *to, struct device *from)
539539
/**
540540
* rproc_handle_vdev() - handle a vdev fw resource
541541
* @rproc: the remote processor
542-
* @rsc: the vring resource descriptor
542+
* @ptr: the vring resource descriptor
543543
* @offset: offset of the resource entry
544544
* @avail: size of available data (for sanity checking the image)
545545
*
@@ -564,9 +564,10 @@ static int copy_dma_range_map(struct device *to, struct device *from)
564564
*
565565
* Returns 0 on success, or an appropriate error code otherwise
566566
*/
567-
static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc,
567+
static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
568568
int offset, int avail)
569569
{
570+
struct fw_rsc_vdev *rsc = ptr;
570571
struct device *dev = &rproc->dev;
571572
struct rproc_vdev *rvdev;
572573
int i, ret;
@@ -684,7 +685,7 @@ void rproc_vdev_release(struct kref *ref)
684685
/**
685686
* rproc_handle_trace() - handle a shared trace buffer resource
686687
* @rproc: the remote processor
687-
* @rsc: the trace resource descriptor
688+
* @ptr: the trace resource descriptor
688689
* @offset: offset of the resource entry
689690
* @avail: size of available data (for sanity checking the image)
690691
*
@@ -698,9 +699,10 @@ void rproc_vdev_release(struct kref *ref)
698699
*
699700
* Returns 0 on success, or an appropriate error code otherwise
700701
*/
701-
static int rproc_handle_trace(struct rproc *rproc, struct fw_rsc_trace *rsc,
702+
static int rproc_handle_trace(struct rproc *rproc, void *ptr,
702703
int offset, int avail)
703704
{
705+
struct fw_rsc_trace *rsc = ptr;
704706
struct rproc_debug_trace *trace;
705707
struct device *dev = &rproc->dev;
706708
char name[15];
@@ -750,7 +752,7 @@ static int rproc_handle_trace(struct rproc *rproc, struct fw_rsc_trace *rsc,
750752
/**
751753
* rproc_handle_devmem() - handle devmem resource entry
752754
* @rproc: remote processor handle
753-
* @rsc: the devmem resource entry
755+
* @ptr: the devmem resource entry
754756
* @offset: offset of the resource entry
755757
* @avail: size of available data (for sanity checking the image)
756758
*
@@ -773,9 +775,10 @@ static int rproc_handle_trace(struct rproc *rproc, struct fw_rsc_trace *rsc,
773775
* and not allow firmwares to request access to physical addresses that
774776
* are outside those ranges.
775777
*/
776-
static int rproc_handle_devmem(struct rproc *rproc, struct fw_rsc_devmem *rsc,
778+
static int rproc_handle_devmem(struct rproc *rproc, void *ptr,
777779
int offset, int avail)
778780
{
781+
struct fw_rsc_devmem *rsc = ptr;
779782
struct rproc_mem_entry *mapping;
780783
struct device *dev = &rproc->dev;
781784
int ret;
@@ -954,7 +957,7 @@ static int rproc_release_carveout(struct rproc *rproc,
954957
/**
955958
* rproc_handle_carveout() - handle phys contig memory allocation requests
956959
* @rproc: rproc handle
957-
* @rsc: the resource entry
960+
* @ptr: the resource entry
958961
* @offset: offset of the resource entry
959962
* @avail: size of available data (for image validation)
960963
*
@@ -971,9 +974,9 @@ static int rproc_release_carveout(struct rproc *rproc,
971974
* pressure is important; it may have a substantial impact on performance.
972975
*/
973976
static int rproc_handle_carveout(struct rproc *rproc,
974-
struct fw_rsc_carveout *rsc,
975-
int offset, int avail)
977+
void *ptr, int offset, int avail)
976978
{
979+
struct fw_rsc_carveout *rsc = ptr;
977980
struct rproc_mem_entry *carveout;
978981
struct device *dev = &rproc->dev;
979982

@@ -1155,10 +1158,10 @@ EXPORT_SYMBOL(rproc_of_parse_firmware);
11551158
* enum fw_resource_type.
11561159
*/
11571160
static rproc_handle_resource_t rproc_loading_handlers[RSC_LAST] = {
1158-
[RSC_CARVEOUT] = (rproc_handle_resource_t)rproc_handle_carveout,
1159-
[RSC_DEVMEM] = (rproc_handle_resource_t)rproc_handle_devmem,
1160-
[RSC_TRACE] = (rproc_handle_resource_t)rproc_handle_trace,
1161-
[RSC_VDEV] = (rproc_handle_resource_t)rproc_handle_vdev,
1161+
[RSC_CARVEOUT] = rproc_handle_carveout,
1162+
[RSC_DEVMEM] = rproc_handle_devmem,
1163+
[RSC_TRACE] = rproc_handle_trace,
1164+
[RSC_VDEV] = rproc_handle_vdev,
11621165
};
11631166

11641167
/* handle firmware resource entries before booting the remote processor */

0 commit comments

Comments
 (0)