Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4888130pjb; Mon, 27 Jul 2020 07:38:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeThPEsjOP1BF6c3kQYrYTTvqewCI0W//hxXpiQD6Qp4dsdJPajYsm2plK3kbVqQDYdxBZ X-Received: by 2002:a17:906:e0c7:: with SMTP id gl7mr20261012ejb.264.1595860735530; Mon, 27 Jul 2020 07:38:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595860735; cv=none; d=google.com; s=arc-20160816; b=jPGe+IzVTxr7Mc4rDIFx3QgP2eIZRb4iv1dfFhKVpo8oHDyP3e1pr1SQB6/+O5bJ1O bJiAdn4fh1XQT92ZcnuiVYdHn031OWVMOGDPcEs4BZ6cXddaLYIJEfF0MC/zgfVlTES5 uoAZ69/XO5eieZi0rq3P71qfUXZGlPAF6bhstqffGF8yD9Kn8HYuBvlgxnMagc+BYS/h GrJ/YEqRtGkaGdKH69jid3fhz1MhdnxBY/hPoMBTA/02I5BeIINKnMewYeqRuJ4poxEk 8cxwggeaeTl5ZgLo32MYtFbr5vpa2l0nIzxIyxgPLJd+IzfFwQVhz7EpEv791AYhMl63 Bm/w== 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=jFr30lN35vamMK/XwPs2JVul70gJMZ6rH52BWB4ug9B5fDzrPshIMg2Qc5RwxCy7x9 ER+qBK74rjd8kMXvkw70YLaYT2yveEQ75Xw5HO4MwN6MF2KNIBKYBQbV1GvCaqokK+N9 yLXjVEL4GpIltebuOXMxQIHUuHU45vx761IW+oZtUAk8gwgNIMQHHJcv/6Qa/Miuc01U 6LJx8cjft8MbHvbxwbb3MRsYNBTrouwUWde9id0xfOJk1zcGU2Oabsgn1mIpk8axWCz5 vT0YI7BacXVW/CdUkyNncwhaWCa+Ui9kObu1CHPEgTzT35WwRUjgpu+mE2AKDw98bSiL AZQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="0xhRP/2W"; 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 a14si5716818eds.487.2020.07.27.07.38.33; Mon, 27 Jul 2020 07:38:55 -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="0xhRP/2W"; 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 S1730222AbgG0OMf (ORCPT + 99 others); Mon, 27 Jul 2020 10:12:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:36900 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730218AbgG0OMd (ORCPT ); Mon, 27 Jul 2020 10:12: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 6A3E520838; Mon, 27 Jul 2020 14:12:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859152; bh=JGHlMZQJ1xpEdottcTaPnLzS+nCY083XoLYz11gR/Lw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0xhRP/2WXJG7MUExTTJu9keE2uviJdmXYHy/epEjX7h8b5VXR51jM8DGdA7+LTgGC KmoLhRvbvTKKGjdhArW1qyUxELnYyIcvH33za5et6WMGOZab/qe7scRKbbEPZJO2Ds 8WAGmuBH622kYOSk758RZUcwHkVYnF+4motms9tk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ian Abbott Subject: [PATCH 4.19 66/86] staging: comedi: addi_apci_1032: check INSN_CONFIG_DIGITAL_TRIG shift Date: Mon, 27 Jul 2020 16:04:40 +0200 Message-Id: <20200727134917.737630098@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 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;