Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1899446pxk; Tue, 1 Sep 2020 10:19:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+UTrH9omRHZVTR/kP/eg3SxOVYOMNlcTlMmK7+U1lIfvu+2zLXQghVk9tPcoi0In744Pq X-Received: by 2002:a50:ec89:: with SMTP id e9mr2881031edr.32.1598980791300; Tue, 01 Sep 2020 10:19:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598980791; cv=none; d=google.com; s=arc-20160816; b=XJ6myp1X7Z5AkNgfVzObqELTSNfMbuTBYmo6aO+/I1KyLyJZHU4vozbLkxOIdO0xjw AqIT0eOgFSlv+UrrPmDWQIH4XaKf/njhXVVgBt73w0SQCRwsJziO/niypK9ATWqkHl2K 8bpwIbdNYWOVFgul/Mzv8Mz3A/iO/waAsVNjh9mHDMeCwqspK8SKEIXImoMjipSFv/We eyJqStF8+6kP5WB0UgHNyktb3lOVSRrVLdY/lt6BOXtT4U/NpQqKue+NMy74vB5bXjlC Hxsuj4KReu+LrRm6jT/jJcRgzTOzgK16u/nttMBFc2QshnyuwnhA8wt8MqV06YgWkrvN NCdA== 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=zKd1/B0AnuknvFkfgzrWmj9Qhs0pW+II5wMtpmrdnpw=; b=CjL7qRVeItAuW5j9ZPDz4yVv5WTGtgUE4mEc0ZjF3od80n3F+jtfiaNzS3tVgGY60R Lu2QDoKTyKijNu41JoT2UwqHTAX8xXnoQhQnped/VzaYRBMwwBWu1oSW89O02YEihRaj GZODkAgAUDHywnj4fRnSPB0hS02xkyf6owSfDnT0jJYT1rh6QYXCr3O3vIkypOkTgBvG 4z1h4DXvNvp4kbhBqCx/e9CYkT0AtVRA6EpOwqIJTc3Ih46SHWs0Ompo30Q5gSmiCmh6 S3F66vcbYBG5GqpfgwzS1e5FDzeTGIZX8iVvG9DNYTTsE25lJW11pQz6mKWER4IRkA3O V56g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zL7s7jJH; 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 i7si1147562ejo.230.2020.09.01.10.19.26; Tue, 01 Sep 2020 10:19:51 -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=zL7s7jJH; 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 S1732584AbgIARQq (ORCPT + 99 others); Tue, 1 Sep 2020 13:16:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:58102 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727864AbgIAPOY (ORCPT ); Tue, 1 Sep 2020 11:14:24 -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 C1B0120BED; Tue, 1 Sep 2020 15:14:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598973264; bh=cUGyqRoLKLvxQhBGrRQhHCN2eGOlJljyoYCfi1tGecU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zL7s7jJH4dGf3r8voSQcvOuWC7WQCTJ/kJYRpZrsUYXaj5cxoBXi42LjT592CHgw+ R6ENIZGAJP16SvGsMrISZPGavHEMXZlmQod8+js5BrjQH/wubdN8z5AY1Kb5oVAg7W LXRNxTjBrDC8M/XJ0CNXowqBjweb1ZOsBkeKj/Gc= 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 4.9 10/78] media: pci: ttpci: av7110: fix possible buffer overflow caused by bad DMA value in debiirq() Date: Tue, 1 Sep 2020 17:09:46 +0200 Message-Id: <20200901150925.249121062@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200901150924.680106554@linuxfoundation.org> References: <20200901150924.680106554@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 382caf200ba16..c313f51688f44 100644 --- a/drivers/media/pci/ttpci/av7110.c +++ b/drivers/media/pci/ttpci/av7110.c @@ -426,14 +426,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