Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1653704 > unrolled thread

[PATCH] pstore: Fix leaked pstore_record in pstore_get_backend_records()

Started byDouglas Anderson <dianders@chromium.org>
First post2017-05-31 01:00 +0200
Last post2017-05-31 19:00 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] pstore: Fix leaked pstore_record in pstore_get_backend_records() Douglas Anderson <dianders@chromium.org> - 2017-05-31 01:00 +0200
    Re: [PATCH] pstore: Fix leaked pstore_record in pstore_get_backend_records() Kees Cook <keescook@chromium.org> - 2017-05-31 19:00 +0200

#1653704 — [PATCH] pstore: Fix leaked pstore_record in pstore_get_backend_records()

FromDouglas Anderson <dianders@chromium.org>
Date2017-05-31 01:00 +0200
Subject[PATCH] pstore: Fix leaked pstore_record in pstore_get_backend_records()
Message-ID<tMYhk-4Sk-15@gated-at.bofh.it>
When the "if (record->size <= 0)" test is true in
pstore_get_backend_records() it's pretty clear that nobody holds a
reference to the allocated pstore_record, yet we don't free it.

Let's free it.

Fixes: 2a2b0acf768c ("pstore: Allocate records on heap instead of stack")
Signed-off-by: Douglas Anderson <dianders@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 d468eec9b8a6..9defe98ff8b1 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -846,8 +846,10 @@ void pstore_get_backend_records(struct pstore_info *psi,
 		record->size = psi->read(record);
 
 		/* No more records left in backend? */
-		if (record->size <= 0)
+		if (record->size <= 0) {
+			kfree(record);
 			break;
+		}
 
 		decompress_record(record);
 		rc = pstore_mkfile(root, record);
-- 
2.13.0.219.gdb65acc882-goog

[toc] | [next] | [standalone]


#1654456

FromKees Cook <keescook@chromium.org>
Date2017-05-31 19:00 +0200
Message-ID<tNf8u-7mc-9@gated-at.bofh.it>
In reply to#1653704
On Tue, May 30, 2017 at 3:50 PM, Douglas Anderson <dianders@chromium.org> wrote:
> When the "if (record->size <= 0)" test is true in
> pstore_get_backend_records() it's pretty clear that nobody holds a
> reference to the allocated pstore_record, yet we don't free it.
>
> Let's free it.
>
> Fixes: 2a2b0acf768c ("pstore: Allocate records on heap instead of stack")
> Signed-off-by: Douglas Anderson <dianders@chromium.org>

Thanks! Applied for -next.

-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 d468eec9b8a6..9defe98ff8b1 100644
> --- a/fs/pstore/platform.c
> +++ b/fs/pstore/platform.c
> @@ -846,8 +846,10 @@ void pstore_get_backend_records(struct pstore_info *psi,
>                 record->size = psi->read(record);
>
>                 /* No more records left in backend? */
> -               if (record->size <= 0)
> +               if (record->size <= 0) {
> +                       kfree(record);
>                         break;
> +               }
>
>                 decompress_record(record);
>                 rc = pstore_mkfile(root, record);
> --
> 2.13.0.219.gdb65acc882-goog
>



-- 
Kees Cook
Pixel Security

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web