Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9173152pxu; Mon, 28 Dec 2020 08:23:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJwM7/Lonvj0SI5TBQ/lCsU3bAL4tAAFNQqFCwZMHYWKB0NiQQWJPpFVcCcEFTkQoqX5x61K X-Received: by 2002:a05:6402:352:: with SMTP id r18mr42058947edw.373.1609172615471; Mon, 28 Dec 2020 08:23:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609172615; cv=none; d=google.com; s=arc-20160816; b=DyFh5oyTDtAQzUnTh5WOjc2ClWvCELEPxcSe3SSmm5hMSXCEl+GfBbWSsyGXob/HUQ B5i4uMLjyft176aOLxvk38trLgQc2DBHK7G9SvY1CR+YIoxAG9+M2CZ/PBBdlMF9W4+N wAxP4qhpIkR9nzv1suqlLBd3jw4PFVkuPaB+BR9Uqn2NDEqSPIQZD+6iuQiElR7Z7lls umIRkyNOCcfWXx3Emkp6mOCCVit92z0fXbSvTrbs5+FksLGsNzRoOaGPpZ5VovK2mudV 5Sh7BSHXOQICb6e/tf2xUq8qUBZwxDkL6CkKEsa/zhIO4Qik+Laj2wbm+huPZAF0gTCa GRQA== 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=ttqVa1+LQhmIO7gmGdLhpl1yIoewVPKBDNTW4ur1B6E=; b=yDhyv3bqJx3KLMRKVzQKOKdggmSsqyJV2REIr4tDlv8pECoTztORrioA+uixA6vbJM HF0NA0y95yKw+3H3ASrvun2V7TAPrUevB86dOo2O3rO9Ez33BxdpQkk0oovIsvuMsmAB V+iPW0RxDlCODa4amGRJCzwnD2z2lcVcbjcMsGS35A9Cz39IPXDMZOw+iBgrzVvbRmXW tfoAusEMtyjyZpx10pNbkAMMcw9KNXW2+i+m5Q2SCDfON5TIIjyYWDi63r4VOZD/cP0V t25fYOqGyMGBIvKe0fzhMQakojyeNOWcLYhdj4DheDeZN//K5vvIn5Q5869Tl0P7xrbW t4KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tLn12beD; 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 hq10si19261163ejc.616.2020.12.28.08.23.11; Mon, 28 Dec 2020 08:23:35 -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=tLn12beD; 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 S2393655AbgL1QUi (ORCPT + 99 others); Mon, 28 Dec 2020 11:20:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:41874 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732287AbgL1NNo (ORCPT ); Mon, 28 Dec 2020 08:13:44 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id A9429206ED; Mon, 28 Dec 2020 13:13:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609161183; bh=eIVMUBNkTv4M0R1fszy82xARhHHZegL4HKM13ZAbDIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tLn12beDGqanOe4fOp221dMGFM6Au8id+G+eHazQYfGds5BWpD1kvoWTZ/GHzMdPP l/MPSswAeRVv7Nz4NV9GoDNaPOCurYTESQFQ5dSu5T4ibbBagkjopevFXFHNr5Giy4 wZnyx4ic8tJTR3Eu3A/Kh2mDjCS2LMfdQKwY1Fmg= 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.14 129/242] media: saa7146: fix array overflow in vidioc_s_audio() Date: Mon, 28 Dec 2020 13:48:54 +0100 Message-Id: <20201228124911.049823128@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@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 930218cc2de19..2e7bd82282caa 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