# \[PATCH V2\] video: fbdev: w100fb: Fix a potential double free.

- Subsystems: FRAMEBUFFER LAYER, THE REST
- Maintainers: Helge Deller, Linus Torvalds
- Status: LANDED (18722d48a6bb · 2020-05-06 18:22)
- Landed in mainline as 18722d48a6bb on 2020-05-06.
- List: linux-fbdev
- 2 messages, 2 authors
- Page: https://ratatoskr.run/linux-fbdev/2020/05/5955396/t

## \[PATCH V2\] video: fbdev: w100fb: Fix a potential double free.

- From: Christophe JAILLET \<hidden\>
- Date: 2020-05-06 18:19:23 
- Message: https://ratatoskr.run/linux-fbdev/2020/05/5955396.md

```text
Some memory is vmalloc'ed in the 'w100fb_save_vidmem' function and freed in
the 'w100fb_restore_vidmem' function. (these functions are called
respectively from the 'suspend' and the 'resume' functions)

However, it is also freed in the 'remove' function.

In order to avoid a potential double free, set the corresponding pointer
to NULL once freed in the 'w100fb_restore_vidmem' function.

Fixes: aac51f09d96a ("[PATCH] w100fb: Rewrite for platform independence")
Cc: Richard Purdie <redacted>
Cc: Antonino Daplas <redacted>
Cc: Bartlomiej Zolnierkiewicz <redacted>
Cc: <redacted> # v2.6.14+
Signed-off-by: Christophe JAILLET <redacted>
---
v2: - Add Cc: tags
    - Reword the commit message to give the names of the functions that
      allocate and free the memory. These functions are called from the
      suspend and resume function.
---
 drivers/video/fbdev/w100fb.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/video/fbdev/w100fb.c b/drivers/video/fbdev/w100fb.c
index 2d6e2738b792..d96ab28f8ce4 100644
--- a/drivers/video/fbdev/w100fb.c
+++ b/drivers/video/fbdev/w100fb.c
@@ -588,6 +588,7 @@ static void w100fb_restore_vidmem(struct w100fb_par *par)
 		memsize=par->mach->mem->size;
 		memcpy_toio(remapped_fbuf + (W100_FB_BASE-MEM_WINDOW_BASE), par->saved_extmem, memsize);
 		vfree(par->saved_extmem);
+		par->saved_extmem = NULL;
 	}
 	if (par->saved_intmem) {
 		memsize=MEM_INT_SIZE;
@@ -596,6 +597,7 @@ static void w100fb_restore_vidmem(struct w100fb_par *par)
 		else
 			memcpy_toio(remapped_fbuf + (W100_FB_BASE-MEM_WINDOW_BASE), par->saved_intmem, memsize);
 		vfree(par->saved_intmem);
+		par->saved_intmem = NULL;
 	}
 }
 
-- 
2.25.1
```

## Re: \[PATCH V2\] video: fbdev: w100fb: Fix a potential double free.

- From: Sam Ravnborg \<hidden\>
- Date: 2020-05-06 18:23:30 
- Message: https://ratatoskr.run/linux-fbdev/2020/05/5955404.md

```text
Hi Christophe
On Wed, May 06, 2020 at 08:19:02PM +0200, Christophe JAILLET wrote:
> Some memory is vmalloc'ed in the 'w100fb_save_vidmem' function and freed in
> the 'w100fb_restore_vidmem' function. (these functions are called
> respectively from the 'suspend' and the 'resume' functions)
> 
> However, it is also freed in the 'remove' function.
> 
> In order to avoid a potential double free, set the corresponding pointer
> to NULL once freed in the 'w100fb_restore_vidmem' function.
> 
> Fixes: aac51f09d96a ("[PATCH] w100fb: Rewrite for platform independence")
> Cc: Richard Purdie <redacted>
> Cc: Antonino Daplas <redacted>
> Cc: Bartlomiej Zolnierkiewicz <redacted>
> Cc: <redacted> # v2.6.14+
> Signed-off-by: Christophe JAILLET <redacted>

Thanks for the quick v2.
Applied to drm-misc-next.

	Sam

> ---
> v2: - Add Cc: tags
>     - Reword the commit message to give the names of the functions that
>       allocate and free the memory. These functions are called from the
>       suspend and resume function.
> ---
>  drivers/video/fbdev/w100fb.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/video/fbdev/w100fb.c b/drivers/video/fbdev/w100fb.c
> index 2d6e2738b792..d96ab28f8ce4 100644
> --- a/drivers/video/fbdev/w100fb.c
> +++ b/drivers/video/fbdev/w100fb.c
> @@ -588,6 +588,7 @@ static void w100fb_restore_vidmem(struct w100fb_par *par)
>  		memsize=par->mach->mem->size;
>  		memcpy_toio(remapped_fbuf + (W100_FB_BASE-MEM_WINDOW_BASE), par->saved_extmem, memsize);
>  		vfree(par->saved_extmem);
> +		par->saved_extmem = NULL;
>  	}
>  	if (par->saved_intmem) {
>  		memsize=MEM_INT_SIZE;
> @@ -596,6 +597,7 @@ static void w100fb_restore_vidmem(struct w100fb_par *par)
>  		else
>  			memcpy_toio(remapped_fbuf + (W100_FB_BASE-MEM_WINDOW_BASE), par->saved_intmem, memsize);
>  		vfree(par->saved_intmem);
> +		par->saved_intmem = NULL;
>  	}
>  }
>  
> -- 
> 2.25.1
```
