From: Kees Cook <keescook@chromium.org>
To: Pi-Hsun Shih <pihsun@chromium.org>
Cc: Anton Vorontsov <anton@enomsg.org>,
Colin Cross <ccross@android.com>, Tony Luck <tony.luck@intel.com>,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] pstore: Set tfm to NULL on free_buf_for_compression.
Date: Mon, 20 May 2019 09:30:06 -0700 [thread overview]
Message-ID: <201905200928.08FE9977F3@keescook> (raw)
In-Reply-To: <20190520065120.245811-1-pihsun@chromium.org>
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
prev parent reply other threads:[~2019-05-20 16:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201905200928.08FE9977F3@keescook \
--to=keescook@chromium.org \
--cc=anton@enomsg.org \
--cc=ccross@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pihsun@chromium.org \
--cc=tony.luck@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox