Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4880100pjb; Mon, 27 Jul 2020 07:28:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhNmIIoDRLML1FHbjlNAaLDTDM0qc9VuNatlRst+/l/UAxouTixd3DQhwZupuKjaPdq1qa X-Received: by 2002:a50:d655:: with SMTP id c21mr2812815edj.49.1595860109581; Mon, 27 Jul 2020 07:28:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595860109; cv=none; d=google.com; s=arc-20160816; b=xYR4QMVZ7zfzFQ3xQtDkIfpeTulxSmsADgW/4zsjlStV2a9mNaE4fncGLbKZNimKFk +340Gor/11Ba6G1Gg0h/R5SBlneUkXKebxKLVzsxZF+fmxJ1hcq46R0yHSwjpc0di7Qt nRdyO5xZ7o2ZlnBI2K8MLrMaXxwlOMCX3F5sTNiXApyblBwdJP50tk1on4uOeTDCAg/k WbZOfkE5pwbxrHstGWmNBJt06f+6gsnORfvnyG1nG36roujAhwtVPFLfO7sFp4er+iir 5lV4dFrJ/QKddYVbVjEoNit2PB7b/Nt9TV+hm9yUh9zUYuNeVH/CxNeHqtFcespwJcmu HqBQ== 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=lezci3kGg7b7zsg07ru8pHJcsFGFBfK5dD0urCzRYMw=; b=jtkiwmjDdNmEu7uhIe0mL62Yc1q92e7yXxIxYtkp6x8BfF2mYTrTEgkFshDGUDDbAR gaJrEi8dl9u9xVxuNaAazgZ8dwe7XG83HOkKnFsed5Di5jP9z1QscGm68jQ+9Ie+Wu88 t/WKE3O5BLQkWfucF7GuFvQVzp7VlH8fkD7t18VY6c9MxlB3LxZpg0fszAvOQkvX9vV0 1LLkiDFqxDAAe1kO+2/lt0ybo4keIKm2W1AUbM4DMwlPjRjKEwqfp3r4pfqrfSuVkCSC aW9vpMy9xKWRzRjpZMUAyIev+HDKiHFFcBO48z6wf+CPnSvRZOfcu62/O5MLIyMRfpsN lc8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TsVCFZ6Y; 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 dp1si8707309ejc.708.2020.07.27.07.28.06; Mon, 27 Jul 2020 07:28:29 -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=TsVCFZ6Y; 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 S1732631AbgG0O0h (ORCPT + 99 others); Mon, 27 Jul 2020 10:26:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:56820 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732623AbgG0O0d (ORCPT ); Mon, 27 Jul 2020 10:26:33 -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 8DAD520663; Mon, 27 Jul 2020 14:26:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859993; bh=JGHlMZQJ1xpEdottcTaPnLzS+nCY083XoLYz11gR/Lw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TsVCFZ6YISYvLsjE1s3UtosvQyoIGK2XNDw0C3t/7aKdVxN4uO7Ubnk23a53QDLbv /1E5RN8LkRHvNDD1CKhQVgJ7HonCzsDNv0eVkqA2uZAa6kHXiNJOyeWbW7Nvu3oNjJ yTS0ovtZ7bC5I2dJhYOBh9ywrXZe8GsQHChzYnLE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ian Abbott Subject: [PATCH 5.7 147/179] staging: comedi: addi_apci_1032: check INSN_CONFIG_DIGITAL_TRIG shift Date: Mon, 27 Jul 2020 16:05:22 +0200 Message-Id: <20200727134939.828869275@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134932.659499757@linuxfoundation.org> References: <20200727134932.659499757@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 0bd0db42a030b75c20028c7ba6e327b9cb554116 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. Fixes: 33cdce6293dcc ("staging: comedi: addi_apci_1032: conform to new INSN_CONFIG_DIGITAL_TRIG") Cc: #3.8+ Signed-off-by: Ian Abbott Link: https://lore.kernel.org/r/20200717145257.112660-3-abbotti@mev.co.uk Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/addi_apci_1032.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) --- a/drivers/staging/comedi/drivers/addi_apci_1032.c +++ b/drivers/staging/comedi/drivers/addi_apci_1032.c @@ -106,14 +106,22 @@ static int apci1032_cos_insn_config(stru unsigned int *data) { struct apci1032_private *devpriv = dev->private; - unsigned int shift, oldmask; + unsigned int shift, oldmask, himask, lomask; switch (data[0]) { case INSN_CONFIG_DIGITAL_TRIG: if (data[1] != 0) return -EINVAL; shift = data[3]; - oldmask = (1U << shift) - 1; + if (shift < 32) { + oldmask = (1U << shift) - 1; + himask = data[4] << shift; + lomask = data[5] << shift; + } else { + oldmask = 0xffffffffu; + himask = 0; + lomask = 0; + } switch (data[2]) { case COMEDI_DIGITAL_TRIG_DISABLE: devpriv->ctrl = 0; @@ -136,8 +144,8 @@ static int apci1032_cos_insn_config(stru devpriv->mode2 &= oldmask; } /* configure specified channels */ - devpriv->mode1 |= data[4] << shift; - devpriv->mode2 |= data[5] << shift; + devpriv->mode1 |= himask; + devpriv->mode2 |= lomask; break; case COMEDI_DIGITAL_TRIG_ENABLE_LEVELS: if (devpriv->ctrl != (APCI1032_CTRL_INT_ENA | @@ -154,8 +162,8 @@ static int apci1032_cos_insn_config(stru devpriv->mode2 &= oldmask; } /* configure specified channels */ - devpriv->mode1 |= data[4] << shift; - devpriv->mode2 |= data[5] << shift; + devpriv->mode1 |= himask; + devpriv->mode2 |= lomask; break; default: return -EINVAL;