Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4879714pjb; Mon, 27 Jul 2020 07:27:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwBwIH5BvYI/31yjEjN8jMNRK+W7WAofw4ztKCaz8dnsbkeFCIAuq8Z2SMNXUigv0wsJuj X-Received: by 2002:aa7:d350:: with SMTP id m16mr7211210edr.169.1595860077981; Mon, 27 Jul 2020 07:27:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595860077; cv=none; d=google.com; s=arc-20160816; b=UGxYnYhsUC6m04I9u1Nf0DYORVqi/9WQaz53jX0pGExFFRFIQnUtpaY0aCcYa3fhLB IWMsc0saOaERiMoF45CWMPV6RMFQvmNh0/HqnYzgOJTyA5YB3vpUwx8f7fB+Cjc2iVAz NDg7Xl7JhgOWuDf3rFfveQiUcngp111tQryNbyTvoxp86EhC4B6Ayzkn1uW5qPIBgMpF N/OCh4WI2hmumJAxnya3kNOmx80uq1fdhL5K8Lui4yFFP1MbWpOA/HPthYPRGr7QspwR QqW2E2aUwtTyDvK6tZGIohGJkpZ/sAOHPS8D1w5t5tJa4fHlxjO62ZXWN2EByvvk++Pn wAdg== 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=oYlUTcjH69q6SUID5nEdCtqn7jGcoj8r6v/Si6hHHpw=; b=ZzKG0i6rYDSOpXXm/T6t1DoUrnCc8G1nXDdpitb0qSGCUCxyNmVvy14gbIFjdap+Z8 GMNMrsbBe/uIWgOFnaaTbFEtEE8UkmoAJnPuyjt4qmvQTKwzOy+w3oYsr0fMX0dZM2te 8zUHOtH7snReJDG6UwLXDuB0dZJrAdBZsVDuo55NlRkh5lmi3Xmdx0HDawQC5U8OD8Hc +8JDVIZ+vAbzKI/RSdt1lqY5G71I+xDR+3LfDfJahwlqoGCZG85BhJKnL9IOnq+jjqqZ MJMFO1IXcrWzmVn4gxvFkA8eAB0eaZExioOW6vGQJGLLmr4yGj/QntoaWaeHWb/ugTmq /Z6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wtEB5Db6; 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 t2si5805020edw.603.2020.07.27.07.27.35; Mon, 27 Jul 2020 07:27:57 -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=wtEB5Db6; 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 S1732587AbgG0O0W (ORCPT + 99 others); Mon, 27 Jul 2020 10:26:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:56484 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731976AbgG0O0Q (ORCPT ); Mon, 27 Jul 2020 10:26:16 -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 11696207FC; Mon, 27 Jul 2020 14:26:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859975; bh=wgQ+dqjWde6gj5sHLIy3LyLTb5h2Ed0FJyVL+Tfcgec=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wtEB5Db6gvD4Qi8BLEYwD/GeclQx2r3RvZOSCDJ+4fgz1b0Clr3XSegtHoNvQWZH1 MqM/h0gFXcvy76boty3hGWBknn3d/rAbWWQBb1NZZm41JlaYZaGChS15CuQDK8nHdp 1cIlVBl0Twsrrs8EuvFmnetUBbbTKP5OIOasjf/w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ian Abbott Subject: [PATCH 5.7 150/179] staging: comedi: addi_apci_1564: check INSN_CONFIG_DIGITAL_TRIG shift Date: Mon, 27 Jul 2020 16:05:25 +0200 Message-Id: <20200727134939.978739829@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 926234f1b8434c4409aa4c53637aa3362ca07cea 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: 1e15687ea472 ("staging: comedi: addi_apci_1564: add Change-of-State interrupt subdevice and required functions") Cc: #3.17+ Signed-off-by: Ian Abbott Link: https://lore.kernel.org/r/20200717145257.112660-4-abbotti@mev.co.uk Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/addi_apci_1564.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) --- a/drivers/staging/comedi/drivers/addi_apci_1564.c +++ b/drivers/staging/comedi/drivers/addi_apci_1564.c @@ -331,14 +331,22 @@ static int apci1564_cos_insn_config(stru unsigned int *data) { struct apci1564_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; @@ -362,8 +370,8 @@ static int apci1564_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 != (APCI1564_DI_IRQ_ENA | @@ -380,8 +388,8 @@ static int apci1564_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;