Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4869433pjb; Mon, 27 Jul 2020 07:14:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyg+qtjR4f063RbT2aNjqm+qqlbtOrM67gxluIHe6fHUubcsXCvRAVClkzlSEwZBI5svZ+4 X-Received: by 2002:a17:906:23e9:: with SMTP id j9mr20729456ejg.107.1595859274058; Mon, 27 Jul 2020 07:14:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595859274; cv=none; d=google.com; s=arc-20160816; b=KN6br3ynrHJ7TEwlOs2AWj/Wj95lAXnekDzFr7+tuUHxNJE4qgfzHUeCRmN9DVwrso SBHgztYj/Est6ESASzHe4REmzhe4WzrhAo7mGQCa7FsubiSQYy08w9jD/rf6IoONe/oj 82s1eSVpv4LhElXOTorCxB2Pfz0lY+BTJgD0zIn1Z0jjIaMd5vTnEslIQKo7OsCUbcyo l3NgMIxkW07Ha46EIA011t6NGxbZ11+GGf3iiC8fBNYftwYetPSOUfwKqJ8evm+Sa/00 tC8CKJb6+s1d2X+I+7GtlUPM1mbYc/vNajJ4PZnS3hLhLh8G/o2FE9dz9XVZ6a029+hK IH5w== 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=nJ3daeuWvdBQVj260jSUQmi0fM1pwLlnVaLFYGRZ/Qg=; b=A0/GR608IZP37bO5R728cfXAYT8kAfGeQx1RzCNFJqJT/w3o43c6i90AZC1GDjImst 96j1dCkF0bCplxi68jpHPzac1RFG+HqGeltPiijecU4El2QbjmftGrhIZzcLrgwnZwVt fJvGSpV0ImUxVm5a56n4bNtZ8B+lfeHv6yc/m9uwnnWI9xJTtQwm/BXZwQl9fLf3nePg Paxrs90NiYdpa3aBZdL0q1XH37VphCqQHpzcnF/xJ/sk+MgKFaJbdmVWYLRaD/SlFVH3 R/UTOhJ7ouQkywgekblT/cdgwmgXSArCoj1bfHKsfnmXEC8bhPErRbxUg9yowjz/3ta9 45Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nnqanGUJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ds18si6840064ejc.591.2020.07.27.07.14.11; Mon, 27 Jul 2020 07:14:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nnqanGUJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730240AbgG0OMl (ORCPT + 99 others); Mon, 27 Jul 2020 10:12:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:37046 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730231AbgG0OMi (ORCPT ); Mon, 27 Jul 2020 10:12:38 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 6366D20838; Mon, 27 Jul 2020 14:12:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859157; bh=W6z7dnpeGGRWpWZZKzTCo6fCMQg2u8gAj9/OmC7aNfg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nnqanGUJQ5KFSvTnLSc5wXQEw4DV00O2SH9PmzHHEH57Y3asQhXuwWIC8Uk1LbM0I DxQ7as1EzTVbVe3ikizGTO28HQZqPuD2SqdZYUEsWAu8wq96be0QFRs/BXp49IGysr 6Kj+k2E27uQIJK5+4nD98UnxuSEP7mmHiXB6WAz8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ian Abbott Subject: [PATCH 4.19 68/86] staging: comedi: addi_apci_1500: check INSN_CONFIG_DIGITAL_TRIG shift Date: Mon, 27 Jul 2020 16:04:42 +0200 Message-Id: <20200727134917.830175777@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134914.312934924@linuxfoundation.org> References: <20200727134914.312934924@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 fc846e9db67c7e808d77bf9e2ef3d49e3820ce5d upstream. The `INSN_CONFIG` comedi instruction with sub-instruction code `INSN_CONFIG_DIGITAL_TRIG` includes a base channel in `data[3]`. This is used as a right shift amount for other bitmask values without being checked. Shift amounts greater than or equal to 32 will result in undefined behavior. Add code to deal with this, adjusting the checks for invalid channels so that enabled channel bits that would have been lost by shifting are also checked for validity. Only channels 0 to 15 are valid. Fixes: a8c66b684efaf ("staging: comedi: addi_apci_1500: rewrite the subdevice support functions") Cc: #4.0+: ef75e14a6c93: staging: comedi: verify array index is correct before using it Cc: #4.0+ Signed-off-by: Ian Abbott Link: https://lore.kernel.org/r/20200717145257.112660-5-abbotti@mev.co.uk Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/addi_apci_1500.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) --- a/drivers/staging/comedi/drivers/addi_apci_1500.c +++ b/drivers/staging/comedi/drivers/addi_apci_1500.c @@ -452,13 +452,14 @@ static int apci1500_di_cfg_trig(struct c struct apci1500_private *devpriv = dev->private; unsigned int trig = data[1]; unsigned int shift = data[3]; - unsigned int hi_mask = data[4] << shift; - unsigned int lo_mask = data[5] << shift; - unsigned int chan_mask = hi_mask | lo_mask; - unsigned int old_mask = (1 << shift) - 1; + unsigned int hi_mask; + unsigned int lo_mask; + unsigned int chan_mask; + unsigned int old_mask; unsigned int pm; unsigned int pt; unsigned int pp; + unsigned int invalid_chan; if (trig > 1) { dev_dbg(dev->class_dev, @@ -466,7 +467,20 @@ static int apci1500_di_cfg_trig(struct c return -EINVAL; } - if (chan_mask > 0xffff) { + if (shift <= 16) { + hi_mask = data[4] << shift; + lo_mask = data[5] << shift; + old_mask = (1U << shift) - 1; + invalid_chan = (data[4] | data[5]) >> (16 - shift); + } else { + hi_mask = 0; + lo_mask = 0; + old_mask = 0xffff; + invalid_chan = data[4] | data[5]; + } + chan_mask = hi_mask | lo_mask; + + if (invalid_chan) { dev_dbg(dev->class_dev, "invalid digital trigger channel\n"); return -EINVAL; }