Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9180051pxu; Mon, 28 Dec 2020 08:34:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJzzcih4tyAdtClb0sD/eT4xjAmcbJcluyDjIwWT+l0JGZ3LZ9dW8Imnt8SycDIB0wWhMXgV X-Received: by 2002:a17:906:5f97:: with SMTP id a23mr43536027eju.128.1609173245720; Mon, 28 Dec 2020 08:34:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609173245; cv=none; d=google.com; s=arc-20160816; b=Np86qv24vMhIa8nYBmBL8Xd4iCD+7oUJmRZmEvtzArV8WJgks/+jL+nsobgfVXpmqO 5l0FM/zJxhFvZ4SBlUaoPV41aJotWm4kVaMCYlOxnh+eoWA2MzuTl5lX5qd224yRKZHG GQNrUI3cziZLt0Ice7Pn9f07oExBawKa6G8tB0Lsaq1G+h0wvBoG0D4F49lNLip2G/S1 wjjnVIogg7VYX67Qe4Q/RYUZlyJPCcK80WuaPOWCgt1Rcis6EFJxNn3Tq4447JuqOZEw ckOO13viQ4KgfXDf9F9XA2OPRjyu50Frcp3Z8fR0F9YHS4ywzcdoToG6UC1I6mgXIkuZ Xr4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2f8K3GiMpPXYnGxgG/YVnhsFK1CDjtdiUjxTfHNv93o=; b=JeWwuFRT+y2cue1TBeSGc3nSbvR8zjpMS6E2jJLODo6yTIqZsvSDqiv7DPzYn2su2f 2GHGANZMI2YFNSbSabx77/zgmpY1ove+nt8rwxCz1YgRYpBjp/6N8cYIIMGJc/IX0TwY xBWP4Z8T9xo3bEkIHxbB2xLtGHIDxLQlD9WvDPISKHiCJG8fcBCTXR8g0x6CSmSrLg18 YpwPV+bGIhJxyoGB84xozQKXHBIIo7IwmHyeco9WB0+vANIIjGdb1OZNFPOp7F/FHtg6 AQ4NWlVPvewM05CIfItGCK+Yds4Oz2oHZo1QefSCNAAdH0lluviRVO5NlGwZaFEQiZPq gPSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZmCQE5Ca; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dd1si18691346ejb.357.2020.12.28.08.33.42; Mon, 28 Dec 2020 08:34:05 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=ZmCQE5Ca; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730454AbgL1NEb (ORCPT + 99 others); Mon, 28 Dec 2020 08:04:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:60156 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730412AbgL1NEU (ORCPT ); Mon, 28 Dec 2020 08:04:20 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 19E94208B6; Mon, 28 Dec 2020 13:04:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160644; bh=zRCEZ6P3oZffdYMkmna1aRcGAqJZVYCCMLN1xZ4mHu0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZmCQE5CaLbzFCyRYhG7Da3aWF6wwD5b82Sn46BNDqDuFqx1LEz2jnF2C7S4TgMR4I ZZ1SAT33HewpleKj0wCuRK7W9IHgzzs4TzjDIyCG/wzWtyY65/E+wjDlPHlTYg2SDT i45+EQLJUbnI7q/EorgEMULrXkEkCweqaLTwvBlE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.9 091/175] media: saa7146: fix array overflow in vidioc_s_audio() Date: Mon, 28 Dec 2020 13:49:04 +0100 Message-Id: <20201228124857.660257549@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124853.216621466@linuxfoundation.org> References: <20201228124853.216621466@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter [ Upstream commit 8e4d86e241cf035d6d3467cd346e7ce490681937 ] The "a->index" value comes from the user via the ioctl. The problem is that the shift can wrap resulting in setting "mxb->cur_audinput" to an invalid value, which later results in an array overflow. Fixes: 6680427791c9 ("[media] mxb: fix audio handling") Signed-off-by: Dan Carpenter Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/pci/saa7146/mxb.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/media/pci/saa7146/mxb.c b/drivers/media/pci/saa7146/mxb.c index 504d788076392..3e8753c9e1e47 100644 --- a/drivers/media/pci/saa7146/mxb.c +++ b/drivers/media/pci/saa7146/mxb.c @@ -652,16 +652,17 @@ static int vidioc_s_audio(struct file *file, void *fh, const struct v4l2_audio * struct mxb *mxb = (struct mxb *)dev->ext_priv; DEB_D("VIDIOC_S_AUDIO %d\n", a->index); - if (mxb_inputs[mxb->cur_input].audioset & (1 << a->index)) { - if (mxb->cur_audinput != a->index) { - mxb->cur_audinput = a->index; - tea6420_route(mxb, a->index); - if (mxb->cur_audinput == 0) - mxb_update_audmode(mxb); - } - return 0; + if (a->index >= 32 || + !(mxb_inputs[mxb->cur_input].audioset & (1 << a->index))) + return -EINVAL; + + if (mxb->cur_audinput != a->index) { + mxb->cur_audinput = a->index; + tea6420_route(mxb, a->index); + if (mxb->cur_audinput == 0) + mxb_update_audmode(mxb); } - return -EINVAL; + return 0; } #ifdef CONFIG_VIDEO_ADV_DEBUG -- 2.27.0