linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: vidtv: fix read after free
@ 2020-11-30  9:28 Cengiz Can
  2020-12-02 12:17 ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 2+ messages in thread
From: Cengiz Can @ 2020-11-30  9:28 UTC (permalink / raw)
  To: Daniel W . S . Almeida, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, Cengiz Can

`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 <cengiz@kernel.wtf>
---
 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);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] media: vidtv: fix read after free
  2020-11-30  9:28 [PATCH] media: vidtv: fix read after free Cengiz Can
@ 2020-12-02 12:17 ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 2+ messages in thread
From: Mauro Carvalho Chehab @ 2020-12-02 12:17 UTC (permalink / raw)
  To: Cengiz Can; +Cc: Daniel W . S . Almeida, linux-media, linux-kernel

Hi Cengiz,

Em Mon, 30 Nov 2020 12:28:26 +0300
Cengiz Can <cengiz@kernel.wtf> 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 <cengiz@kernel.wtf>

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-12-02 12:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-30  9:28 [PATCH] media: vidtv: fix read after free Cengiz Can
2020-12-02 12:17 ` Mauro Carvalho Chehab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).