Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9456891pxu; Mon, 28 Dec 2020 17:14:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJwEyzqtkxUX37k4U9maALZWyL8+QVms4teTj7gaG6fhWcuiCWzhamRjVyyeYDqxpIe/t3kH X-Received: by 2002:a05:6402:1d15:: with SMTP id dg21mr43615363edb.280.1609204451397; Mon, 28 Dec 2020 17:14:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609204451; cv=none; d=google.com; s=arc-20160816; b=ACEfnGInolov+gigHzeSaS1aMoG09wr9bR4c70SMUknOW7GJJrgfQjUBYcvzQyDfMC 5zLqmR8mawiPTWkJ1ppEo8gUwqV0picR8Kbh+d59XcTDp12wjrQZCMqE0KAfg9XhDu5j vpawXkc2J7ElRxkVLx178sIZt0osB7naYOMKc8KBn+Rh53vJs87gwfvFyIykczKLLizb cdK1XUe6Pg4bE0z6DGSbi6TDvdEj2kqUUZ7KyNtmaKa5Tp/kmmt31sWU05owISsqHnEI wqlDxzaTxaVlg4lUaEsWtFMbuXNufI7dNbjBvkfHQBetjakF0iaqLcnewk14Jc9OME/5 fLag== 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=yPjG83n3+iaC38yJ8EcMgWW6plF6gDIlJwKaWAKo/L0=; b=ZpHaNl/trlpT1w+nsJK/MfzYY9QtUPjH9p0jr0Tf3fOM5OZRG5Vd85eg2U6YYpxTxj kKdgXeKvl9hvT5ldFw13W7uW0udQAVIZMOgdl2KSEv0Pb7uhRv7ZLfLWBAMD+lQx2tVb v3RaHdFcLEo2WK/90r4nGypxTfVTTek9Gomm735xktw/fmX452JtGEv0lBWWPIw0p1uK BpAIBEIRapsA6qisMCLPJ2RL7ROW5oMoMOUeDJa45mRrFOQQ7UY0w+GzhkyHXJlsE/xD bzR4JdfPvTvxgWOtgPOMS3a7l0O9Y+eX5Gw5bs/eXEGvDdNMU9k49irdeSs/vq64cSX6 OQyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EzDXmlts; 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 v11si20548300edx.226.2020.12.28.17.13.49; Mon, 28 Dec 2020 17:14:11 -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=EzDXmlts; 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 S1728835AbgL1QpJ (ORCPT + 99 others); Mon, 28 Dec 2020 11:45:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:53240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728837AbgL1M4u (ORCPT ); Mon, 28 Dec 2020 07:56:50 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 794E3229C6; Mon, 28 Dec 2020 12:56:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160170; bh=0C+GYIfeZWybqBTy4yX7z13bK34Q9hixK18jECqWek8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EzDXmltsFVBeOyF0aBHYG9geZeb6w0bD+nZX28Ha8gcv/h3/HtHvRHCIfQPGqr8KX 1oVPQhlwyJqJpaxJdVjmTOEuK9GoUCLB+Vx81uHbfyhLDIL7zG2bQ8q4BJg00sq2k0 S+j+MgKo1dQDa8vl1HA58sWsCi83YrDKorUDZFXU= 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.4 063/132] media: saa7146: fix array overflow in vidioc_s_audio() Date: Mon, 28 Dec 2020 13:49:07 +0100 Message-Id: <20201228124849.500961047@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124846.409999325@linuxfoundation.org> References: <20201228124846.409999325@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 0ca1e07ae7837..868af73c5536a 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