driverdev-devel.linuxdriverproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] staging: comedi: ni_routes: fix some regressions
@ 2020-01-14 18:25 Ian Abbott
  2020-01-14 18:25 ` [PATCH 1/2] staging: comedi: ni_routes: fix null dereference in ni_find_route_source() Ian Abbott
  2020-01-14 18:25 ` [PATCH 2/2] staging: comedi: ni_routes: allow partial routing information Ian Abbott
  0 siblings, 2 replies; 3+ messages in thread
From: Ian Abbott @ 2020-01-14 18:25 UTC (permalink / raw)
  To: devel; +Cc: Greg Kroah-Hartman, Ian Abbott, linux-kernel, Spencer Olson

Fix some regressions resulting from the routing functionality
implemented for the National Instruments comedi drivers in kernel 4.20
when board-specific routing information is absent.

Patch 1 fixes a null pointer dereference, but the set-up of asynchronous
commands that use external triggers on boards with missing
board-specific routing information will now fail gracefully with an
error.

Patch 2 allows routing values for the device family to be filled in even
if the board-specific routing information is missing, which should allow
asynchronous commands that use external triggers to be used on these
boards.

1) staging: comedi: ni_routes: fix null dereference in ni_find_route_source()
2) staging: comedi: ni_routes: allow partial routing information

 drivers/staging/comedi/drivers/ni_routes.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Cc: Spencer Olson <olsonse@umich.edu>

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] staging: comedi: ni_routes: fix null dereference in ni_find_route_source()
  2020-01-14 18:25 [PATCH 0/2] staging: comedi: ni_routes: fix some regressions Ian Abbott
@ 2020-01-14 18:25 ` Ian Abbott
  2020-01-14 18:25 ` [PATCH 2/2] staging: comedi: ni_routes: allow partial routing information Ian Abbott
  1 sibling, 0 replies; 3+ messages in thread
From: Ian Abbott @ 2020-01-14 18:25 UTC (permalink / raw)
  To: devel
  Cc: Greg Kroah-Hartman, linux-kernel, stable, Ian Abbott, Spencer E . Olson

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: 4bb90c87abbe ("staging: comedi: add interface to ni routing table information")
Cc: <stable@vger.kernel.org> # 4.20+
Cc: Spencer E. Olson <olsonse@umich.edu>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 drivers/staging/comedi/drivers/ni_routes.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/staging/comedi/drivers/ni_routes.c b/drivers/staging/comedi/drivers/ni_routes.c
index 673d732dcb8f..9627bd1d2a78 100644
--- a/drivers/staging/comedi/drivers/ni_routes.c
+++ b/drivers/staging/comedi/drivers/ni_routes.c
@@ -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)
-- 
2.24.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] staging: comedi: ni_routes: allow partial routing information
  2020-01-14 18:25 [PATCH 0/2] staging: comedi: ni_routes: fix some regressions Ian Abbott
  2020-01-14 18:25 ` [PATCH 1/2] staging: comedi: ni_routes: fix null dereference in ni_find_route_source() Ian Abbott
@ 2020-01-14 18:25 ` Ian Abbott
  1 sibling, 0 replies; 3+ messages in thread
From: Ian Abbott @ 2020-01-14 18:25 UTC (permalink / raw)
  To: devel
  Cc: Greg Kroah-Hartman, linux-kernel, stable, Ian Abbott, Spencer E . Olson

This patch fixes a regression on setting up asynchronous commands to use
external trigger sources when board-specific routing information is
missing.

`ni_find_device_routes()` (called via `ni_assign_device_routes()`) finds
the table of register values for the device family and the set of valid
routes for the specific board.  If both are found,
`tables->route_values` is set to point to the table of register values
for the device family and `tables->valid_routes` is set to point to the
list of valid routes for the specific board.  If either is not found,
both `tables->route_values` and `tables->valid_routes` are left set at
their initial null values (initialized by `ni_assign_device_routes()`)
and the function returns `-ENODATA`.

Returning an error results in some routing functionality being disabled.
Unfortunately, leaving `table->route_values` set to `NULL` also breaks
the setting up of asynchronous commands that are configured to use
external trigger sources.  Calls to `ni_check_trigger_arg()` or
`ni_check_trigger_arg_roffs()` while checking the asynchronous command
set-up would result in a null pointer dereference if
`table->route_values` is `NULL`.  The null pointer dereference is fixed
in another patch, but it now results in failure to set up the
asynchronous command.  That is a regression from the behavior prior to
commit 347e244884c3 ("staging: comedi: tio: implement global tio/ctr
routing") and commit 56d0b826d39f ("staging: comedi: ni_mio_common:
implement new routing for TRIG_EXT").

Change `ni_find_device_routes()` to set `tables->route_values` and/or
`tables->valid_routes` to valid information even if the other one can
only be set to `NULL` due to missing information.  The function will
still return an error in that case.  This should result in
`tables->valid_routes` being valid for all currently supported device
families even if the board-specific routing information is missing.
That should be enough to fix the regression on setting up asynchronous
commands to use external triggers for boards with missing routing
information.

Fixes: 347e244884c3 ("staging: comedi: tio: implement global tio/ctr routing")
Fixes: 56d0b826d39f ("staging: comedi: ni_mio_common: implement new routing for TRIG_EXT").
Cc: <stable@vger.kernel.org> # 4.20+
Cc: Spencer E. Olson <olsonse@umich.edu>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 drivers/staging/comedi/drivers/ni_routes.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_routes.c b/drivers/staging/comedi/drivers/ni_routes.c
index 9627bd1d2a78..8f398b30f5bf 100644
--- a/drivers/staging/comedi/drivers/ni_routes.c
+++ b/drivers/staging/comedi/drivers/ni_routes.c
@@ -72,9 +72,6 @@ static int ni_find_device_routes(const char *device_family,
 		}
 	}
 
-	if (!rv)
-		return -ENODATA;
-
 	/* Second, find the set of routes valid for this device. */
 	for (i = 0; ni_device_routes_list[i]; ++i) {
 		if (memcmp(ni_device_routes_list[i]->device, board_name,
@@ -84,12 +81,12 @@ static int ni_find_device_routes(const char *device_family,
 		}
 	}
 
-	if (!dr)
-		return -ENODATA;
-
 	tables->route_values = rv;
 	tables->valid_routes = dr;
 
+	if (!rv || !dr)
+		return -ENODATA;
+
 	return 0;
 }
 
-- 
2.24.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-01-14 18:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-14 18:25 [PATCH 0/2] staging: comedi: ni_routes: fix some regressions Ian Abbott
2020-01-14 18:25 ` [PATCH 1/2] staging: comedi: ni_routes: fix null dereference in ni_find_route_source() Ian Abbott
2020-01-14 18:25 ` [PATCH 2/2] staging: comedi: ni_routes: allow partial routing information Ian Abbott

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).