All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pstore: Set tfm to NULL on free_buf_for_compression.
@ 2019-05-20  6:51 Pi-Hsun Shih
  2019-05-20 16:30 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: Pi-Hsun Shih @ 2019-05-20  6:51 UTC (permalink / raw)
  Cc: Pi-Hsun Shih, Kees Cook, Anton Vorontsov, Colin Cross, Tony Luck,
	open list

Set tfm to NULL on free_buf_for_compression after crypto_free_comp.

This avoid a use-after-free when allocate_buf_for_compression and
free_buf_for_compression are called twice. Although
free_buf_for_compression freed the tfm, allocate_buf_for_compression
won't reinitialize the tfm since the tfm pointer is not NULL.

Fixes: 95047b0519c1 ("pstore: Refactor compression initialization")
Signed-off-by: Pi-Hsun Shih <pihsun@chromium.org>
---
 fs/pstore/platform.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 75887a269b64..8355a46638d0 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -347,8 +347,10 @@ static void allocate_buf_for_compression(void)
 
 static void free_buf_for_compression(void)
 {
-	if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && tfm)
+	if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && tfm) {
 		crypto_free_comp(tfm);
+		tfm = NULL;
+	}
 	kfree(big_oops_buf);
 	big_oops_buf = NULL;
 	big_oops_buf_sz = 0;
-- 
2.21.0.1020.gf2820cf01a-goog


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

* Re: [PATCH] pstore: Set tfm to NULL on free_buf_for_compression.
  2019-05-20  6:51 [PATCH] pstore: Set tfm to NULL on free_buf_for_compression Pi-Hsun Shih
@ 2019-05-20 16:30 ` Kees Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2019-05-20 16:30 UTC (permalink / raw)
  To: Pi-Hsun Shih; +Cc: Anton Vorontsov, Colin Cross, Tony Luck, open list

On Mon, May 20, 2019 at 02:51:19PM +0800, Pi-Hsun Shih wrote:
> Set tfm to NULL on free_buf_for_compression after crypto_free_comp.
> 
> This avoid a use-after-free when allocate_buf_for_compression and
> free_buf_for_compression are called twice. Although
> free_buf_for_compression freed the tfm, allocate_buf_for_compression
> won't reinitialize the tfm since the tfm pointer is not NULL.
> 
> Fixes: 95047b0519c1 ("pstore: Refactor compression initialization")
> Signed-off-by: Pi-Hsun Shih <pihsun@chromium.org>

Thank you! Yes, without this, reloading pstore backend modules would
cause bad behavior. :)

Applied; will send to Linus shortly.

-Kees

> ---
>  fs/pstore/platform.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
> index 75887a269b64..8355a46638d0 100644
> --- a/fs/pstore/platform.c
> +++ b/fs/pstore/platform.c
> @@ -347,8 +347,10 @@ static void allocate_buf_for_compression(void)
>  
>  static void free_buf_for_compression(void)
>  {
> -	if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && tfm)
> +	if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && tfm) {
>  		crypto_free_comp(tfm);
> +		tfm = NULL;
> +	}
>  	kfree(big_oops_buf);
>  	big_oops_buf = NULL;
>  	big_oops_buf_sz = 0;
> -- 
> 2.21.0.1020.gf2820cf01a-goog
> 

-- 
Kees Cook

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

end of thread, other threads:[~2019-05-20 16:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-20  6:51 [PATCH] pstore: Set tfm to NULL on free_buf_for_compression Pi-Hsun Shih
2019-05-20 16:30 ` Kees Cook

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.