Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp818415pxu; Wed, 2 Dec 2020 04:22:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJz2vlRK3d9V2gtDebH/oK/Hc9SP5Ex5DyN51xNozcTq21rwhBGi2/2Fh1RsmqTsEf234pwc X-Received: by 2002:a17:906:5c53:: with SMTP id c19mr1964195ejr.31.1606911722880; Wed, 02 Dec 2020 04:22:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606911722; cv=none; d=google.com; s=arc-20160816; b=rz5/xqKeJBT2CAWp9OqvPmFjD+/+L/8RpoUvbjOtAILz+MGI8VN+1vt95S/YtuRGUJ qNmHXoqbJJOvSAm+ot+SIasPH/MU6b/fGXmlJlhoQiJb/v0jiwVNgYNwcn+yAJmQFQIJ XlLEWnulZKDotb4DGyNRCcmeGR8IX5Wse8HVhGrzWZ3zSbqgSGZsI63xfvS7WNrLBQvz 5ZP9Je6zBJkURfXXOYovw/WA88ucEfV+F6ZX4YGFJjIDGNi/A7bASafYFLkUvTZ+FBb1 d4jNrFewpYtT8j2sATW4NC9iu/Dwm4YQfARKiMC27r0h6FMiRZ7Tl/M+7j2zPrncQebi EX/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:dkim-signature :date; bh=xKDqtUG9xapIV6V0fWpuPjJYjgAfq0lVfgKj3pyr0L8=; b=OPcmUNklqu1e7gOwbRxwlfxjAznlwBKzLeGj7+Q86kKJVTTt/TvadXqeKz02+lN4nD mndU53SPH+FM/IQg64rfPzxzCVuhURzIQtIaetm9BGxCO/owJ7PohzktfP0HBJU/l+X/ 79oYBLIv8WkbpPuEBVnGlzPNp8bR9mfjDwMHC+ubI5bOPcP6UdXyjHe8zfGdAQBpHN4a u6sYOwYVc9C/aBLy+YJed1IBHdBbHKhgCZWpErlOYbPfuaMnwkkQqK6g66QfMvGQWVOo B0/pf8+IxhWGqMRF9UVvTGQBsI5F7HmKJe767fRv9pLhiZZzCcGaVncGttLR7Y+iRxnC Q/FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=saBL5IbI; 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 x17si1059643edq.475.2020.12.02.04.21.39; Wed, 02 Dec 2020 04:22:02 -0800 (PST) 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=saBL5IbI; 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 S2387553AbgLBMSG (ORCPT + 99 others); Wed, 2 Dec 2020 07:18:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:49572 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726479AbgLBMSG (ORCPT ); Wed, 2 Dec 2020 07:18:06 -0500 Date: Wed, 2 Dec 2020 13:17:21 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606911445; bh=nDpirUT4HzebNKlAZcQZP0UPN73yEY091GDvXLXiKoM=; h=From:To:Cc:Subject:In-Reply-To:References:From; b=saBL5IbI/rQj4VdWnSdQDRmPSP2MFwc7rVl8zznM8X1MRnx3kMIodra8LCR0YkGSU aOHWVq3ZnCJWt8VkS4JTajjvUkYFCyj1lepW0ZmCV3z5+Nmqtrlo8uBAFGhWsyefDt ayWru0XhVgT1XRzbcrfkcRJM9yxTvNGWVMA2XFXE= From: Mauro Carvalho Chehab To: Cengiz Can Cc: "Daniel W . S . Almeida" , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] media: vidtv: fix read after free Message-ID: <20201202131721.46ff17fc@coco.lan> In-Reply-To: <20201130092825.28532-1-cengiz@kernel.wtf> References: <20201130092825.28532-1-cengiz@kernel.wtf> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Cengiz, Em Mon, 30 Nov 2020 12:28:26 +0300 Cengiz Can escreveu: > `vidtv_channel_si_destroy` function has a call to > `vidtv_psi_pat_table_destroy` that frees Program Association Table. > > However it is followed by a loop that iterates over the count of Program > Map Tables. This obviously accesses an invalid memory. > > Eliminate this by making a copy of num_pmt before free'ing Program > Association Table and loop on it instead. > > Signed-off-by: Cengiz Can Collin sent me a similar fix. I'm applying his because: - it was sent first; - it uses a better approach: it just moves the vidtv_psi_pat_table_destroy() call to happen after freeing the PMT tables. So, it doesn't need an aux var. Regards, Mauro > --- > drivers/media/test-drivers/vidtv/vidtv_channel.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/drivers/media/test-drivers/vidtv/vidtv_channel.c b/drivers/media/test-drivers/vidtv/vidtv_channel.c > index 8ad6c0744d36..4af39a8786a7 100644 > --- a/drivers/media/test-drivers/vidtv/vidtv_channel.c > +++ b/drivers/media/test-drivers/vidtv/vidtv_channel.c > @@ -503,10 +503,13 @@ int vidtv_channel_si_init(struct vidtv_mux *m) > void vidtv_channel_si_destroy(struct vidtv_mux *m) > { > u32 i; > + u16 num_pmt; > + > + num_pmt = m->si.pat->num_pmt; > > vidtv_psi_pat_table_destroy(m->si.pat); > > - for (i = 0; i < m->si.pat->num_pmt; ++i) > + for (i = 0; i < num_pmt; ++i) > vidtv_psi_pmt_table_destroy(m->si.pmt_secs[i]); > > kfree(m->si.pmt_secs); Thanks, Mauro