Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1874939pxk; Tue, 1 Sep 2020 09:46:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxW1ysWmFwRZ3l1ZY3TPOJpG0C4GttAKATkeb9HB9X+hxaZHVxQC4fZoWsl5bS7dEA1mLW X-Received: by 2002:a17:906:48d6:: with SMTP id d22mr2394446ejt.462.1598978782474; Tue, 01 Sep 2020 09:46:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598978782; cv=none; d=google.com; s=arc-20160816; b=drv27hX7hjXPhg5lAMAR/tuJtZITJW64uM+YEXvGY+xC46Zc3iJb6R0IaXfCM6yLhH gSV0kkr1xM06ZtIbTRwjdJXZ21E11TniHVlvhRBq/qmJL9j2DjQrUnvSYcf+klfWuQf1 dG8rKj9rLQit84viUPKvZ0W88H4PW9g8o9q7G2sS5Ul/XI10JL8zsUTgIUuKJupUrwa6 0feTHVYpkPTxwYevG2JTuDRFhgdSzhDeaEe2KPqdZTf4P0keBIzGl/PsCtE2FNLWFlHr oO+uaUHYMNBbVr5+ZwmWD7ziwv5Kz3fUv1UyeOgpPBBab/SaemQArknk8YpnY6YTqGqN HJPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vjjvF8AljV+pmZ4lVx0YJ/R7nY1NQYdb7K/nz6LOUsU=; b=loU3IXqfCz8oZEH2JiWWA9CeCBqqpYX/wV1HMpprtjpWyzetwaHytPUbFCrMPyP5o6 1gSWxDaTJM13oi84CIh5kSTmYC/lTy+tBEwFkj2WBiRB5qp8TrFggwq+x50BM7w0DQrb zCPEQFAdzYU1FCkAFvSCLZM7NwS8ejNFc3AMHQpVlepPuAke1uJIoniH3jwMLNLtq6xA aHI+KaeTi+t1S3Zv3knlWh3Z/8KiZ10lBtfNWO+AFdDIRbDG+WA+/Iheq3dsiYeF7Zdf lhfZe9RE0Wy7NVjcbYr+IoWf2bSQo6ODG3YFlsA8yTPGYTZIjbvj3EhM/dlKjtgri4RD Pt/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U2Q+lc26; 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=fail (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 i3si823437eds.570.2020.09.01.09.45.58; Tue, 01 Sep 2020 09:46:22 -0700 (PDT) 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=@kernel.org header.s=default header.b=U2Q+lc26; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728331AbgIAQp3 (ORCPT + 99 others); Tue, 1 Sep 2020 12:45:29 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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, -- 2.25.1