Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4818321ybl; Wed, 22 Jan 2020 05:20:41 -0800 (PST) X-Google-Smtp-Source: APXvYqzGpoEaUt4UrdkOV3WfWnIlkAEjw5MDQgh5pRHscT48YmoHLbt8f+DRJNiCO3qIRHePlrTy X-Received: by 2002:a9d:21f4:: with SMTP id s107mr7602216otb.102.1579699241157; Wed, 22 Jan 2020 05:20:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579699241; cv=none; d=google.com; s=arc-20160816; b=LnrvIoZeWOJ/wXz7TZGXc3o6I9d9OcmZnFb/rJlWgBll7HwsITvmMRxOGy+HtqbVbP 3rKK8o5J1a1iMhKpdF+dmbhcyS3lz6Cfwj/jiG3dlCP0nvqgdiogh2G39TR1cAmUMsBB lx+Y4kyM8CS/qNwRWoQiTFxn6URFKYwAC6p2fZac/MfXu9Ry16ceHMNvFnC39KIpTkxE ZDNGU5kywLPlPR4kr5cYnM8o1kWAszrb1oltRBGqysAxy8twmn4dFI4rX8asb4FBFyLl EncR4AQreu13DQzJserkp2XjdNXHHRxN8p0C/TC8RSOh/Ki17ZRz1HsC1YVmd7Badxwy GNqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RKSdp8HkFrKnLf0vqZxJ4TI6GxHgUjE5+r1jY/EoSwo=; b=zhw4yU3gi9fleTDUlHxGbK1dKVQNbr2WcomAAKxhcH8W8llodm+f75qGdcYktKqLps Mu6Akr5vZMdOdmWgRAEZWu9LVqtaQh6GQ3iz8yYzAKz/t7Hf+MyhQbiAjDiiK/7cKNfA LtJUO7ROcdJCKFZaEIQQ157UDuMCw8oXyyjoDreQUG7QEaXMRK3CpoEc31jKsrPAYgpN nLnS51ZQQmtQ3LAcf/5/pNn8rLsAmoQhF+PmCc5R9sHbP/nLNQ++z6cHDygy9PLPx+2i i0hfc3JQN7MT/HolYVFbJR88RBW+L5CVhw52TYrIP5ksYWgcLdlOxWj7KsSWgjA9cgtl Th3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=A9BJTv+7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h128si20365262oif.258.2020.01.22.05.20.29; Wed, 22 Jan 2020 05:20:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=A9BJTv+7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726170AbgAVNTH (ORCPT + 99 others); Wed, 22 Jan 2020 08:19:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:34846 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729534AbgAVNTC (ORCPT ); Wed, 22 Jan 2020 08:19:02 -0500 Received: from localhost (unknown [84.241.205.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CC335205F4; Wed, 22 Jan 2020 13:19:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579699142; bh=eGTOKWP2cniC/6Pqoc89aEbuIcifSHcRzi2ZdvM2NrA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A9BJTv+7xrgVij1llbfBAHiLK4gAbKnsaIt40W2UWbDAjGdeWnRnVBKgzS5GR8O42 gNHLsBeBqq+pJAZJE3n+ulkzw4oAZ8xlWjOBjb+aK4E2htZJdd/VQp8wJhg9BZJvGL M/ZAmSILxaTQNxydyUBjHzD8klz9aSpTJoPUQdRU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Spencer E. Olson" , Ian Abbott Subject: [PATCH 5.4 053/222] staging: comedi: ni_routes: fix null dereference in ni_find_route_source() Date: Wed, 22 Jan 2020 10:27:19 +0100 Message-Id: <20200122092837.416673594@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092833.339495161@linuxfoundation.org> References: <20200122092833.339495161@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ian Abbott commit 01e20b664f808a4f3048ca3f930911fd257209bd upstream. 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: # 4.20+ Cc: Spencer E. Olson Signed-off-by: Ian Abbott Link: https://lore.kernel.org/r/20200114182532.132058-2-abbotti@mev.co.uk Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/ni_routes.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/staging/comedi/drivers/ni_routes.c +++ b/drivers/staging/comedi/drivers/ni_routes.c @@ -489,6 +489,9 @@ int ni_find_route_source(const u8 src_se { 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)