Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp1837524pxa; Sat, 29 Aug 2020 05:11:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzx4FXCE+N4kGOgUtgxP5DbAmOJcTrsYsuoQ7izg5HxsMQW2KMYPR7IJJD+sxt1Hl7RNeNs X-Received: by 2002:a50:8e11:: with SMTP id 17mr3333296edw.54.1598703114719; Sat, 29 Aug 2020 05:11:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598703114; cv=none; d=google.com; s=arc-20160816; b=cygJmKqagAmad0nR9NUzd5dsSygo0l5lEhs1uWx6qjDmutGmR8R1/FkSX9Oj66yDuD M3dyYywyvSAqkzozxOCZj1xAnj6GS28aaKjT6FUN6xovO62KKcimNvTYOJwuFDFsq637 9b1YmU3yk3K8A3piHV+U2tnBQucop6eNU1IJDP7mLMTJ0SQn13M0Ql+FoC/XIRprDYMz s+AxkrMOFwfptnDNC0TJQqkPZXXZtqcOGYFEtTm+keaX6mazePdBPibap3qZT2cWw4tj ALAUz0SDVxiu/HBYZdFK5skPInt8gSogD93VVZiwMQRsoaktVlkJRnTgbBk3ZjFU0Cjd fe/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=dE42dGR3/81/iyBVR8ojJchFD+RlSAK4NeV2RG7lHyM=; b=duuYT41jg54wgQnThaF7Pentke+rM35Q+5I1AADBffc17N6eZ+jeRP7lZqQPsgSUUc rklvjt4LR3xi+Ble7Bmje9V15tkUuKrdD+zS/XByH9xMLXryqZUa5XIWojTE9u1P+AHh 6PDBFTxwTlth1jGFXFhAGO/fjeuvo8PFNmPx269ZUTBJuU0Q0cB0/1CtqT6tKdd/lW9+ c1CznnShLTpGnJg9G8III7xWKUREZ5QGbLAMibC54PPJHI9B3mgaQdygGz+aTtHYbXu+ HyzdmsHp+mbAynaWGVPTLwt5Ba959APRK/cBmJvxAB4FpOEHcNuxYKFE3FZWoVSf1ojH fKpA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cx12si1549286edb.26.2020.08.29.05.11.29; Sat, 29 Aug 2020 05:11:54 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727923AbgH2MK0 (ORCPT + 99 others); Sat, 29 Aug 2020 08:10:26 -0400 Received: from jabberwock.ucw.cz ([46.255.230.98]:55288 "EHLO jabberwock.ucw.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726876AbgH2MKX (ORCPT ); Sat, 29 Aug 2020 08:10:23 -0400 Received: by jabberwock.ucw.cz (Postfix, from userid 1017) id ABEEE1C0B82; Sat, 29 Aug 2020 14:10:20 +0200 (CEST) Date: Sat, 29 Aug 2020 14:10:20 +0200 From: Pavel Machek To: Sasha Levin Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Jia-Ju Bai , Sean Young , Mauro Carvalho Chehab , linux-media@vger.kernel.org Subject: Re: [PATCH AUTOSEL 4.19 08/38] media: pci: ttpci: av7110: fix possible buffer overflow caused by bad DMA value in debiirq() Message-ID: <20200829121020.GA20944@duo.ucw.cz> References: <20200821161807.348600-1-sashal@kernel.org> <20200821161807.348600-8-sashal@kernel.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="W/nzBZO5zC0uMSeA" Content-Disposition: inline In-Reply-To: <20200821161807.348600-8-sashal@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --W/nzBZO5zC0uMSeA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi! > 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. >=20 > To fix this possible bug, data[0] is assigned to a local variable, which > replaces the use of data[0]. I'm pretty sure hardware capable of manipulating memory can work around any such checks, but... > +++ b/drivers/media/pci/ttpci/av7110.c > @@ -424,14 +424,15 @@ static void debiirq(unsigned long cookie) > case DATA_CI_GET: > { > u8 *data =3D av7110->debi_virt; > + u8 data_0 =3D data[0]; > =20 > - if ((data[0] < 2) && data[2] =3D=3D 0xff) { > + if (data_0 < 2 && data[2] =3D=3D 0xff) { > int flags =3D 0; > if (data[5] > 0) > flags |=3D CA_CI_MODULE_PRESENT; > if (data[5] > 5) > flags |=3D CA_CI_MODULE_READY; > - av7110->ci_slot[data[0]].flags =3D flags; > + av7110->ci_slot[data_0].flags =3D flags; This does not even do what it says. Compiler is still free to access data[0] multiple times. It needs READ_ONCE() to be effective. Best regards, Pavel --=20 (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blo= g.html --W/nzBZO5zC0uMSeA Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQRPfPO7r0eAhk010v0w5/Bqldv68gUCX0pFrAAKCRAw5/Bqldv6 8voQAJ9ExNyygKhg/hCWcFdC6iANTre5iQCdFZfPDfYl6rhOxjgz439HbYmQxIc= =J6Tm -----END PGP SIGNATURE----- --W/nzBZO5zC0uMSeA--