stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ipmi: fix sleep-in-atomic in free_user at cleanup SRCU user->release_barrier
@ 2019-03-11 10:02 Konstantin Khlebnikov
  2019-03-11 12:54 ` Corey Minyard
  0 siblings, 1 reply; 2+ messages in thread
From: Konstantin Khlebnikov @ 2019-03-11 10:02 UTC (permalink / raw)
  To: openipmi-developer, linux-kernel, Corey Minyard, Yang Yingliang; +Cc: stable

free_user() could be called in atomic context.

This patch uses non-sleeping cleanup_srcu_struct_quiesced(). At this stage
atomic refcount is zero, thus all read-sections should have been ended.

Example:

 BUG: sleeping function called from invalid context at kernel/workqueue.c:2856
 in_atomic(): 1, irqs_disabled(): 0, pid: 177, name: ksoftirqd/27
 CPU: 27 PID: 177 Comm: ksoftirqd/27 Not tainted 4.19.25-3 #1
 Hardware name: AIC 1S-HV26-08/MB-DPSB04-06, BIOS IVYBV060 10/21/2015
 Call Trace:
  dump_stack+0x5c/0x7b
  ___might_sleep+0xec/0x110
  __flush_work+0x48/0x1f0
  ? try_to_del_timer_sync+0x4d/0x80
  _cleanup_srcu_struct+0x104/0x140
  free_user+0x18/0x30 [ipmi_msghandler]
  ipmi_free_recv_msg+0x3a/0x50 [ipmi_msghandler]
  deliver_response+0xbd/0xd0 [ipmi_msghandler]
  deliver_local_response+0xe/0x30 [ipmi_msghandler]
  handle_one_recv_msg+0x163/0xc80 [ipmi_msghandler]
  ? dequeue_entity+0xa0/0x960
  handle_new_recv_msgs+0x15c/0x1f0 [ipmi_msghandler]
  tasklet_action_common.isra.22+0x103/0x120
  __do_softirq+0xf8/0x2d7
  run_ksoftirqd+0x26/0x50
  smpboot_thread_fn+0x11d/0x1e0
  kthread+0x103/0x140
  ? sort_range+0x20/0x20
  ? kthread_destroy_worker+0x40/0x40
  ret_from_fork+0x1f/0x40

Fixes: 77f8269606bf ("ipmi: fix use-after-free of user->release_barrier.rda")
Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Cc: stable@vger.kernel.org # 4.18
Cc: Yang Yingliang <yangyingliang@huawei.com>
Cc: Corey Minyard <cminyard@mvista.com>
---
 drivers/char/ipmi/ipmi_msghandler.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index e8ba67834746..c35f2bcbaa23 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -1260,7 +1260,12 @@ EXPORT_SYMBOL(ipmi_get_smi_info);
 static void free_user(struct kref *ref)
 {
 	struct ipmi_user *user = container_of(ref, struct ipmi_user, refcount);
-	cleanup_srcu_struct(&user->release_barrier);
+
+	/*
+	 * Cleanup without waiting. This could be called in atomic context.
+	 * Refcount is zero: all read-sections should have been ended.
+	 */
+	cleanup_srcu_struct_quiesced(&user->release_barrier);
 	kfree(user);
 }
 


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

* Re: [PATCH] ipmi: fix sleep-in-atomic in free_user at cleanup SRCU user->release_barrier
  2019-03-11 10:02 [PATCH] ipmi: fix sleep-in-atomic in free_user at cleanup SRCU user->release_barrier Konstantin Khlebnikov
@ 2019-03-11 12:54 ` Corey Minyard
  0 siblings, 0 replies; 2+ messages in thread
From: Corey Minyard @ 2019-03-11 12:54 UTC (permalink / raw)
  To: Konstantin Khlebnikov
  Cc: openipmi-developer, linux-kernel, Yang Yingliang, stable

On Mon, Mar 11, 2019 at 01:02:29PM +0300, Konstantin Khlebnikov wrote:
> free_user() could be called in atomic context.
> 
> This patch uses non-sleeping cleanup_srcu_struct_quiesced(). At this stage
> atomic refcount is zero, thus all read-sections should have been ended.

Thanks, I have this in my tree.

-corey

> 
> Example:
> 
>  BUG: sleeping function called from invalid context at kernel/workqueue.c:2856
>  in_atomic(): 1, irqs_disabled(): 0, pid: 177, name: ksoftirqd/27
>  CPU: 27 PID: 177 Comm: ksoftirqd/27 Not tainted 4.19.25-3 #1
>  Hardware name: AIC 1S-HV26-08/MB-DPSB04-06, BIOS IVYBV060 10/21/2015
>  Call Trace:
>   dump_stack+0x5c/0x7b
>   ___might_sleep+0xec/0x110
>   __flush_work+0x48/0x1f0
>   ? try_to_del_timer_sync+0x4d/0x80
>   _cleanup_srcu_struct+0x104/0x140
>   free_user+0x18/0x30 [ipmi_msghandler]
>   ipmi_free_recv_msg+0x3a/0x50 [ipmi_msghandler]
>   deliver_response+0xbd/0xd0 [ipmi_msghandler]
>   deliver_local_response+0xe/0x30 [ipmi_msghandler]
>   handle_one_recv_msg+0x163/0xc80 [ipmi_msghandler]
>   ? dequeue_entity+0xa0/0x960
>   handle_new_recv_msgs+0x15c/0x1f0 [ipmi_msghandler]
>   tasklet_action_common.isra.22+0x103/0x120
>   __do_softirq+0xf8/0x2d7
>   run_ksoftirqd+0x26/0x50
>   smpboot_thread_fn+0x11d/0x1e0
>   kthread+0x103/0x140
>   ? sort_range+0x20/0x20
>   ? kthread_destroy_worker+0x40/0x40
>   ret_from_fork+0x1f/0x40
> 
> Fixes: 77f8269606bf ("ipmi: fix use-after-free of user->release_barrier.rda")
> Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
> Cc: stable@vger.kernel.org # 4.18
> Cc: Yang Yingliang <yangyingliang@huawei.com>
> Cc: Corey Minyard <cminyard@mvista.com>
> ---
>  drivers/char/ipmi/ipmi_msghandler.c |    7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
> index e8ba67834746..c35f2bcbaa23 100644
> --- a/drivers/char/ipmi/ipmi_msghandler.c
> +++ b/drivers/char/ipmi/ipmi_msghandler.c
> @@ -1260,7 +1260,12 @@ EXPORT_SYMBOL(ipmi_get_smi_info);
>  static void free_user(struct kref *ref)
>  {
>  	struct ipmi_user *user = container_of(ref, struct ipmi_user, refcount);
> -	cleanup_srcu_struct(&user->release_barrier);
> +
> +	/*
> +	 * Cleanup without waiting. This could be called in atomic context.
> +	 * Refcount is zero: all read-sections should have been ended.
> +	 */
> +	cleanup_srcu_struct_quiesced(&user->release_barrier);
>  	kfree(user);
>  }
>  
> 

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

end of thread, other threads:[~2019-03-11 12:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-11 10:02 [PATCH] ipmi: fix sleep-in-atomic in free_user at cleanup SRCU user->release_barrier Konstantin Khlebnikov
2019-03-11 12:54 ` Corey Minyard

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