linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] pstore: check PSTORE_FLAGS_FRAGILE in pstore_unregister
@ 2015-10-23 14:56 Geliang Tang
  2015-10-23 14:56 ` [PATCH 2/2] efi-pstore: implement efivars_pstore_exit() Geliang Tang
  2015-10-23 16:54 ` [PATCH 1/2] pstore: check PSTORE_FLAGS_FRAGILE in pstore_unregister Kees Cook
  0 siblings, 2 replies; 4+ messages in thread
From: Geliang Tang @ 2015-10-23 14:56 UTC (permalink / raw)
  To: Anton Vorontsov, Colin Cross, Kees Cook, Tony Luck
  Cc: Geliang Tang, linux-kernel

When PSTORE_FLAGS_FRAGILE flag is set, only kmsg is registered in
pstore_register. So, under these circumstances, only kmsg needs to
be unregistered in pstore_unregister.

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 fs/pstore/platform.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 0aab920..7ad2038 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -496,9 +496,12 @@ EXPORT_SYMBOL_GPL(pstore_register);
 
 void pstore_unregister(struct pstore_info *psi)
 {
-	pstore_unregister_pmsg();
-	pstore_unregister_ftrace();
-	pstore_unregister_console();
+	if ((psi->flags & PSTORE_FLAGS_FRAGILE) == 0) {
+		pstore_unregister_pmsg();
+		pstore_unregister_ftrace();
+		pstore_unregister_console();
+	}
+
 	pstore_unregister_kmsg();
 
 	free_buf_for_compression();
-- 
2.5.0



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

* [PATCH 2/2] efi-pstore: implement efivars_pstore_exit()
  2015-10-23 14:56 [PATCH 1/2] pstore: check PSTORE_FLAGS_FRAGILE in pstore_unregister Geliang Tang
@ 2015-10-23 14:56 ` Geliang Tang
  2015-10-23 16:54 ` [PATCH 1/2] pstore: check PSTORE_FLAGS_FRAGILE in pstore_unregister Kees Cook
  1 sibling, 0 replies; 4+ messages in thread
From: Geliang Tang @ 2015-10-23 14:56 UTC (permalink / raw)
  To: Matt Fleming, Anton Vorontsov, Colin Cross, Kees Cook, Tony Luck
  Cc: Geliang Tang, linux-efi, linux-kernel

The original efivars_pstore_exit() is empty. I
 1) add a bufsize check statement.
 2) call pstore_unregister as it is defined now.
 3) free the memory and set bufsize to 0.

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 drivers/firmware/efi/efi-pstore.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/firmware/efi/efi-pstore.c b/drivers/firmware/efi/efi-pstore.c
index c8d794c..453ac19 100644
--- a/drivers/firmware/efi/efi-pstore.c
+++ b/drivers/firmware/efi/efi-pstore.c
@@ -393,6 +393,13 @@ static __init int efivars_pstore_init(void)
 
 static __exit void efivars_pstore_exit(void)
 {
+	if (!efi_pstore_info.bufsize)
+		return;
+
+	pstore_unregister(&efi_pstore_info);
+	kfree(efi_pstore_info.buf);
+	efi_pstore_info.buf = NULL;
+	efi_pstore_info.bufsize = 0;
 }
 
 module_init(efivars_pstore_init);
-- 
2.5.0



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

* Re: [PATCH 1/2] pstore: check PSTORE_FLAGS_FRAGILE in pstore_unregister
  2015-10-23 14:56 [PATCH 1/2] pstore: check PSTORE_FLAGS_FRAGILE in pstore_unregister Geliang Tang
  2015-10-23 14:56 ` [PATCH 2/2] efi-pstore: implement efivars_pstore_exit() Geliang Tang
@ 2015-10-23 16:54 ` Kees Cook
  2015-10-25  2:22   ` Geliang Tang
  1 sibling, 1 reply; 4+ messages in thread
From: Kees Cook @ 2015-10-23 16:54 UTC (permalink / raw)
  To: Geliang Tang; +Cc: Anton Vorontsov, Colin Cross, Tony Luck, LKML

On Fri, Oct 23, 2015 at 7:56 AM, Geliang Tang <geliangtang@163.com> wrote:
> When PSTORE_FLAGS_FRAGILE flag is set, only kmsg is registered in
> pstore_register. So, under these circumstances, only kmsg needs to
> be unregistered in pstore_unregister.
>
> Signed-off-by: Geliang Tang <geliangtang@163.com>

Would it make more sense to have the pstore_unregister_* calls be
defensive, like kfree() is? In other words, it would be safe to call
them, even if they hadn't been registered?

Either way, I'm fine with this. Good catch!

-Kees

> ---
>  fs/pstore/platform.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
> index 0aab920..7ad2038 100644
> --- a/fs/pstore/platform.c
> +++ b/fs/pstore/platform.c
> @@ -496,9 +496,12 @@ EXPORT_SYMBOL_GPL(pstore_register);
>
>  void pstore_unregister(struct pstore_info *psi)
>  {
> -       pstore_unregister_pmsg();
> -       pstore_unregister_ftrace();
> -       pstore_unregister_console();
> +       if ((psi->flags & PSTORE_FLAGS_FRAGILE) == 0) {
> +               pstore_unregister_pmsg();
> +               pstore_unregister_ftrace();
> +               pstore_unregister_console();
> +       }
> +
>         pstore_unregister_kmsg();
>
>         free_buf_for_compression();
> --
> 2.5.0
>
>



-- 
Kees Cook
Chrome OS Security

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

* Re: [PATCH 1/2] pstore: check PSTORE_FLAGS_FRAGILE in pstore_unregister
  2015-10-23 16:54 ` [PATCH 1/2] pstore: check PSTORE_FLAGS_FRAGILE in pstore_unregister Kees Cook
@ 2015-10-25  2:22   ` Geliang Tang
  0 siblings, 0 replies; 4+ messages in thread
From: Geliang Tang @ 2015-10-25  2:22 UTC (permalink / raw)
  To: Kees Cook
  Cc: Anton Vorontsov, Colin Cross, Tony Luck, linux-kernel, Geliang Tang

On Fri, Oct 23, 2015 at 09:54:31AM -0700, Kees Cook wrote:
> On Fri, Oct 23, 2015 at 7:56 AM, Geliang Tang <geliangtang@163.com> wrote:
> > When PSTORE_FLAGS_FRAGILE flag is set, only kmsg is registered in
> > pstore_register. So, under these circumstances, only kmsg needs to
> > be unregistered in pstore_unregister.
> >
> > Signed-off-by: Geliang Tang <geliangtang@163.com>
> 
> Would it make more sense to have the pstore_unregister_* calls be
> defensive, like kfree() is? In other words, it would be safe to call
> them, even if they hadn't been registered?
> 
> Either way, I'm fine with this. Good catch!
> 
> -Kees
> 

Thanks for your reply.

pstore_unregister_* is defensive as you expected. I have tested it. it
is safe to call them if they haven't been registered. This won't cause
any trouble.

But logically, we should check this flag in pstore_unregister.

-Geliang Tang

> > ---
> >  fs/pstore/platform.c | 9 ++++++---
> >  1 file changed, 6 insertions(+), 3 deletions(-)
> >
> > diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
> > index 0aab920..7ad2038 100644
> > --- a/fs/pstore/platform.c
> > +++ b/fs/pstore/platform.c
> > @@ -496,9 +496,12 @@ EXPORT_SYMBOL_GPL(pstore_register);
> >
> >  void pstore_unregister(struct pstore_info *psi)
> >  {
> > -       pstore_unregister_pmsg();
> > -       pstore_unregister_ftrace();
> > -       pstore_unregister_console();
> > +       if ((psi->flags & PSTORE_FLAGS_FRAGILE) == 0) {
> > +               pstore_unregister_pmsg();
> > +               pstore_unregister_ftrace();
> > +               pstore_unregister_console();
> > +       }
> > +
> >         pstore_unregister_kmsg();
> >
> >         free_buf_for_compression();
> > --
> > 2.5.0
> >
> >
> 
> 
> 
> -- 
> Kees Cook
> Chrome OS Security


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

end of thread, other threads:[~2015-10-25  2:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-23 14:56 [PATCH 1/2] pstore: check PSTORE_FLAGS_FRAGILE in pstore_unregister Geliang Tang
2015-10-23 14:56 ` [PATCH 2/2] efi-pstore: implement efivars_pstore_exit() Geliang Tang
2015-10-23 16:54 ` [PATCH 1/2] pstore: check PSTORE_FLAGS_FRAGILE in pstore_unregister Kees Cook
2015-10-25  2:22   ` Geliang Tang

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).