Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9085396pxu; Mon, 28 Dec 2020 06:16:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJxVFJyMH7HutQjS6ifeUsiq+DfWA34eLL5slrPhBfW6fZ1BK2uBCixibunJI3W2ioJnifMR X-Received: by 2002:a17:906:8617:: with SMTP id o23mr41722694ejx.274.1609165005179; Mon, 28 Dec 2020 06:16:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609165005; cv=none; d=google.com; s=arc-20160816; b=DDYDyUTB0TZNRfiLklTOyaDhsFqEX2VmPJn+Z8w2Tgj+nGqFD4V1IdrGIxSIeyrmT8 nPKTZBmkFsHE4WdUDuG+A0sGLr8RCEOR/jx9hLRHh82cRxjKlDEKdgBNISYdoi6s5kLY KY0GVU73x5ZbPHKgnE+1FMzalhYm0B4i16yErmRLXOMm3N8ZKZlpPI5F0cpphgX9gV7i hTxplB/FM8YNhE9IfdoeidO5MqtzUfkaVEnKBFkYP7grX34YpChJdGY/RbgbS0FQiItr pTHxsB20xwknQfiBAdqz3lS3tYaOe+VxTKQSVaGtJn2kpEca7gEwmZJpqzhSymZq9WdI 9RwA== 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=O18CMdoHBoaIhTQcayfCcF6w/388OHGn76Ojy47qfyI=; b=fi2QrRP1xWfoTTASBtD6kYLAM0xwc3/5mM9TWy4iCdty44wud7tLu4b/dg3bmqIdJf hN1/arZuTXQ+4I0Wx6gQKHwvFslyIKv2RBuDS0vJ+1LJUAGm/PpHMqEJ7l8yZR9N0+A7 t/0leyxalbtWHPm2VWg9eSThKvELlif1fbmLHfTrdkl2/MPku75n68AlKQRSs+qkfGix M/CQTlcPzXrtE65Ui+fYKlbX9/Nx+aJ1O1auKWIE/tW8azXgavhzNo2Ff+s+vkI3SVWm ZR6o6vON4t7FiXSZeNsnRtROJ7t6kEok37GKwTnyc3VEqC8UZEG8U5FSp2hRkSPcdD7S N+Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VG5O70oB; 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 k1si20921012eds.84.2020.12.28.06.16.21; Mon, 28 Dec 2020 06:16:45 -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=VG5O70oB; 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 S2440358AbgL1OON (ORCPT + 99 others); Mon, 28 Dec 2020 09:14:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:49006 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2440331AbgL1OOI (ORCPT ); Mon, 28 Dec 2020 09:14:08 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3CDA7207B2; Mon, 28 Dec 2020 14:13:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609164807; bh=QjlvMhXC+TsKv1MKaxqRPcLPT0V6RXQTsrDNzbeJopA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VG5O70oB+/DtVSowzRhEk2LhjSCw4r1mHr4gBChCQ7l6yvUNQ5bVUiGhFCbRr7n05 2mhEBjQ4utVQ+2eWcrc1e3CsxXy9igNSVVYKqMFsgDUNiPDFFFMMMxqHC8GhBRRtgx M3PXNageNRQKcC3E92aRZIs3rRuwSJ38ATLJMV/c= 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 5.10 278/717] media: saa7146: fix array overflow in vidioc_s_audio() Date: Mon, 28 Dec 2020 13:44:36 +0100 Message-Id: <20201228125034.339868057@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@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 129a1f8ebe1ad..73fc901ecf3db 100644 --- a/drivers/media/pci/saa7146/mxb.c +++ b/drivers/media/pci/saa7146/mxb.c @@ -641,16 +641,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