From patchwork Tue Sep 1 15:08:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 310285 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2BFCC43461 for ; Tue, 1 Sep 2020 16:45:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9FF8A2067C for ; Tue, 1 Sep 2020 16:45:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598978742; bh=SF7cbSp+8aJt7HKiEK1+h754VI5LCsyUECgtetCo9QU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=czkK/ZHP+8iSAWwJK511tQGG8+SxJOCs8teUGarIytiZSjQWp35BMQcfUxxonpgXa wqjtHZrFdYQMi80MZ+vlPIKRlCXPs5cr5P1kTKFgeo5SSjpuearGBxGeKN+9aRqSMR boVSVBER1cm3xbFVqda+8G5kiUuNmYcWmxUr02s4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730241AbgIAQpY (ORCPT ); Tue, 1 Sep 2020 12:45:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:54462 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729628AbgIAP12 (ORCPT ); Tue, 1 Sep 2020 11:27:28 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1815420FC3; Tue, 1 Sep 2020 15:27:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598974047; bh=SF7cbSp+8aJt7HKiEK1+h754VI5LCsyUECgtetCo9QU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U2Q+lc269T40l1R4u5CeYLzdqmRbKm1UQ7WBNl26wLbjccX2+MNn+tUgOudMKV+G+ ByjD+TXDFnxj5wY+oUu1Vl9RAsT9sF+2R6hEBdnFIYsDKeus268J0gdAXMblw+0MN6 qkEDHDHzfZXjHO1lbAcmF4p9fPG4vyQ9iFyZaIo0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jia-Ju Bai , Sean Young , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.4 023/214] media: pci: ttpci: av7110: fix possible buffer overflow caused by bad DMA value in debiirq() Date: Tue, 1 Sep 2020 17:08:23 +0200 Message-Id: <20200901150954.080109684@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200901150952.963606936@linuxfoundation.org> References: <20200901150952.963606936@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jia-Ju Bai [ Upstream commit 6499a0db9b0f1e903d52f8244eacc1d4be00eea2 ] The value av7110->debi_virt is stored in DMA memory, and it is assigned to data, and thus data[0] can be modified at any time by malicious hardware. In this case, "if (data[0] < 2)" can be passed, but then data[0] can be changed into a large number, which may cause buffer overflow when the code "av7110->ci_slot[data[0]]" is used. To fix this possible bug, data[0] is assigned to a local variable, which replaces the use of data[0]. Signed-off-by: Jia-Ju Bai Signed-off-by: Sean Young Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/pci/ttpci/av7110.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/media/pci/ttpci/av7110.c b/drivers/media/pci/ttpci/av7110.c index d0cdee1c6eb0b..bf36b1e22b635 100644 --- a/drivers/media/pci/ttpci/av7110.c +++ b/drivers/media/pci/ttpci/av7110.c @@ -406,14 +406,15 @@ static void debiirq(unsigned long cookie) case DATA_CI_GET: { u8 *data = av7110->debi_virt; + u8 data_0 = data[0]; - if ((data[0] < 2) && data[2] == 0xff) { + if (data_0 < 2 && data[2] == 0xff) { int flags = 0; if (data[5] > 0) flags |= CA_CI_MODULE_PRESENT; if (data[5] > 5) flags |= CA_CI_MODULE_READY; - av7110->ci_slot[data[0]].flags = flags; + av7110->ci_slot[data_0].flags = flags; } else ci_get_data(&av7110->ci_rbuffer, av7110->debi_virt,