Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9246491pxu; Mon, 28 Dec 2020 10:20:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJxf8zRSGoOyXfEtASVjQT5c7PrCSAKkru97aVKzzdtyvsU2TtBT2saQyZc52l4YZVIZ5BXI X-Received: by 2002:a05:6402:3192:: with SMTP id di18mr42559923edb.332.1609179607935; Mon, 28 Dec 2020 10:20:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609179607; cv=none; d=google.com; s=arc-20160816; b=mt8NNpMqbR1SfVNLkf/pNJ33wiJtbRdHTzNsbloi/CQYmP0nj1YI8e/5dEJ/MNOadH oKp0EKaWetQ6KOhYa+j17Ydt79F46WzjSP/b0bEvUdFuYguPdlHnsli9rNLOtLY8fXUI 1sqaIiaFT8+XioIUlAG+b0tFN2OslRxayXZd9RtLTH2+ueFs0HyZT6q+7yOl89m8ZlOy KUiQo/ijnuk1IldLj7eG4RSTa/lAkAjMi6e76QngdBMQ5rijzPPjdIWWZI7qURGt1jmA h5u3OL2eVEijxZoXlo4HjZAFytTbCTYe2dGNhdhDSnzHL2zmh1hcY7KecbeNAqzWTUHs 5YDg== 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=Z8Yf4oFLhuO2C9429JjaJGsUsmLtpenPCVhOB/OI6cc=; b=FcqVahE6pDQVaunzArrVMHerxMnu1i0/nuUupsKtW/qkgs55zKV3Fsu4CtlKgfPcPM wUb5Ix3o6OTDtrrVv63G0c8pntroJ0/ODMS8q7k02b9DeLfMyd82AZ7XD/xdPr3RxVJ+ 2e5y5K1gPG8DpSYXREIHsDXHFIC01T1Snsoi/kEJnkpi4f53o7a2RDGON5WBkV7kzLP1 RZU91DLTOX1y1kyoD0NsUzqSL6N1ODH9LSzFegBfqx6bis9QtfDv3kkGWaLO0nEcNqrj lVhAI5//81CtbZw//G1Pw6B8y0aFym9cM8WCWdWQtZk2EtNvUIbll+ppFrKIoVoVU7n/ /E5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PURzhaCG; 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 v26si21983583edw.486.2020.12.28.10.19.45; Mon, 28 Dec 2020 10:20:07 -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=PURzhaCG; 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 S2390050AbgL1N3L (ORCPT + 99 others); Mon, 28 Dec 2020 08:29:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:57428 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390004AbgL1N2y (ORCPT ); Mon, 28 Dec 2020 08:28:54 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1F50D2063A; Mon, 28 Dec 2020 13:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609162118; bh=Hp8alQtj4CrxbLuUDe1MmVwKcsql+4byhR+E1rCjG/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PURzhaCGzeRQ/QQm1fdS7H2kJuk2Jvc/SNbeudab15Nknj6ZHbf7nysTPIx6/kfoe LgPOB6oTvagiOfbO+ruJR3/zUDxI6Fao+xIgZjVXf01lBYccmikAqzplTWqVXoRMyZ V16ue5bx7mWhNZs+E9MRCxjbXOBjsN6zVvatPe9g= 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.19 194/346] media: saa7146: fix array overflow in vidioc_s_audio() Date: Mon, 28 Dec 2020 13:48:33 +0100 Message-Id: <20201228124929.172709261@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124919.745526410@linuxfoundation.org> References: <20201228124919.745526410@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 6b5582b7c5955..6e25654da2567 100644 --- a/drivers/media/pci/saa7146/mxb.c +++ b/drivers/media/pci/saa7146/mxb.c @@ -653,16 +653,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