Skip to content

Commit

Permalink
staging: comedi: ni_routes: fix null dereference in ni_find_route_sou…
Browse files Browse the repository at this point in the history
…rce()

In `ni_find_route_source()`, `tables->route_values` gets dereferenced.
However it is possible that `tables->route_values` is `NULL`, leading to
a null pointer dereference.  `tables->route_values` will be `NULL` if
the call to `ni_assign_device_routes()` during board initialization
returned an error due to missing device family routing information or
missing board-specific routing information.  For example, there is
currently no board-specific routing information provided for the
PCIe-6251 board and several other boards, so those are affected by this
bug.

The bug is triggered when `ni_find_route_source()` is called via
`ni_check_trigger_arg()` or `ni_check_trigger_arg_roffs()` when checking
the arguments for setting up asynchronous commands.  Fix it by returning
`-EINVAL` if `tables->route_values` is `NULL`.

Even with this fix, setting up asynchronous commands to use external
trigger sources for boards with missing routing information will still
fail gracefully.  Since `ni_find_route_source()` only depends on the
device family routing information, it would be better if that was made
available even if the board-specific routing information is missing.
That will be addressed by another patch.

Fixes: 4bb90c8 ("staging: comedi: add interface to ni routing table information")
Cc: <[email protected]> # 4.20+
Cc: Spencer E. Olson <[email protected]>
Signed-off-by: Ian Abbott <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
ian-abbott authored and gregkh committed Jan 15, 2020
1 parent bc80573 commit 01e20b6
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/staging/comedi/drivers/ni_routes.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,9 @@ int ni_find_route_source(const u8 src_sel_reg_value, int dest,
{
int src;

if (!tables->route_values)
return -EINVAL;

dest = B(dest); /* subtract NI names offset */
/* ensure we are not going to under/over run the route value table */
if (dest < 0 || dest >= NI_NUM_NAMES)
Expand Down

0 comments on commit 01e20b6

Please sign in to comment.