Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp400660pxa; Fri, 21 Aug 2020 10:06:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjanz7yBee44IGiKphb2XPa0LDvSfbyzl80YI51xORmNQR25iZftTvvn2yg0OB5NvM+lDo X-Received: by 2002:aa7:c604:: with SMTP id h4mr3786284edq.336.1598029609959; Fri, 21 Aug 2020 10:06:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598029609; cv=none; d=google.com; s=arc-20160816; b=0PC/X84oNGqzY4yizD02xFmL5eh6/lfJR+4svIuQY7Sf5e8icIdmroQohO7PFEaJhu HR/uOFTafSe7T5Bbg7SfM7jGy4B6fke5cyzSS5ktCZe/8eyWdZ7ZcmkeI0qZ4c+f5of+ DVrUDssUZnQ30G3GoLSEgjuYugtd57UyoLvjNhzDDd33TBlQQsH/ceLOjB0EL6zE724y 9421tqdRHmTkKmM4CdJ4Ic/l4cJyp/bguB0yUy75CrM6soxFm3Tr4pbM5O+eg5ggpVOz BYjjzFxcTp++O1TgJ4QISVnbPkQDXVO5N0tw2MdQQcSZEJav3DJavRhsJD6+7oeNX43X WkAQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Rfx3YgJQyQgCESNlrqaclgUNgPEEOD2bXQ06viiruvg=; b=VTmRFQH7UJlrem4Qmp4s1Atd8eB4Ez/fT6gJTht8CBMNV3W42usRAlffVmc0FP0ROl diIcT8oGz/dKfXEvcKVJCXCl9kO98iKaYPJJZFcspqV4Hx5ur719Fcdt8dJ0sEk11sNy KqfWzLOTxoikkKyeMh9TWinaDoOpgtkoBfOtVv9De4oq6RgaGLM3Y20Qz35X2KedfbE/ vsYFlskQRmsDIgHTWVHp/wv1scEfYnXH7DOVHXgRT2vOfueerpxpgd/Za0YdeV1AxuQ6 /GbsjwL/KVqsMrFf9+NT1fqqOjRUM69vB5coVjtJgiLne+kjgsdL4O/JmjR9ivOubT31 Hidg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HUXaTiSE; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w13si1725562ede.238.2020.08.21.10.06.26; Fri, 21 Aug 2020 10:06:49 -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=HUXaTiSE; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728614AbgHUREX (ORCPT + 99 others); Fri, 21 Aug 2020 13:04:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:49910 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727841AbgHUQSy (ORCPT ); Fri, 21 Aug 2020 12:18:54 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C617022CAF; Fri, 21 Aug 2020 16:18:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598026697; bh=QWOGaXnMi9tVxvefm+GLsgAaLy1fnmwknssikhptLsE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HUXaTiSECigHCdMRuPL56DjoOngDRqswACKz8iuDYb7Pmn5zrY6QWZhtwQuz1VXnn Cd8j2NOzHA9f0Cnhh5XiOTs7AGOS61mjAK1yWGKVQiXaU0aXOUxbya2l2v/bIT9q+c TvGgXwn7xcjaMDbH8xRcjffAnWlgwUWMaLYX4O8A= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jia-Ju Bai , Sean Young , Mauro Carvalho Chehab , Sasha Levin , linux-media@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 08/38] media: pci: ttpci: av7110: fix possible buffer overflow caused by bad DMA value in debiirq() Date: Fri, 21 Aug 2020 12:17:37 -0400 Message-Id: <20200821161807.348600-8-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200821161807.348600-1-sashal@kernel.org> References: <20200821161807.348600-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 d6816effb8786..d02b5fd940c12 100644 --- a/drivers/media/pci/ttpci/av7110.c +++ b/drivers/media/pci/ttpci/av7110.c @@ -424,14 +424,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