Skip to content

Commit 3b9a907

Browse files
committed
ipmi: fix sleep-in-atomic in free_user at cleanup SRCU user->release_barrier
free_user() could be called in atomic context. This patch pushed the free operation off into a workqueue. 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: 77f8269 ("ipmi: fix use-after-free of user->release_barrier.rda") Reported-by: Konstantin Khlebnikov <[email protected]> Signed-off-by: Corey Minyard <[email protected]> Cc: [email protected] # 5.0 Cc: Yang Yingliang <[email protected]>
1 parent a885bcf commit 3b9a907

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

drivers/char/ipmi/ipmi_msghandler.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ struct ipmi_user {
214214

215215
/* Does this interface receive IPMI events? */
216216
bool gets_events;
217+
218+
/* Free must run in process context for RCU cleanup. */
219+
struct work_struct remove_work;
217220
};
218221

219222
static struct ipmi_user *acquire_ipmi_user(struct ipmi_user *user, int *index)
@@ -1157,6 +1160,15 @@ static int intf_err_seq(struct ipmi_smi *intf,
11571160
return rv;
11581161
}
11591162

1163+
static void free_user_work(struct work_struct *work)
1164+
{
1165+
struct ipmi_user *user = container_of(work, struct ipmi_user,
1166+
remove_work);
1167+
1168+
cleanup_srcu_struct(&user->release_barrier);
1169+
kfree(user);
1170+
}
1171+
11601172
int ipmi_create_user(unsigned int if_num,
11611173
const struct ipmi_user_hndl *handler,
11621174
void *handler_data,
@@ -1200,6 +1212,8 @@ int ipmi_create_user(unsigned int if_num,
12001212
goto out_kfree;
12011213

12021214
found:
1215+
INIT_WORK(&new_user->remove_work, free_user_work);
1216+
12031217
rv = init_srcu_struct(&new_user->release_barrier);
12041218
if (rv)
12051219
goto out_kfree;
@@ -1260,8 +1274,9 @@ EXPORT_SYMBOL(ipmi_get_smi_info);
12601274
static void free_user(struct kref *ref)
12611275
{
12621276
struct ipmi_user *user = container_of(ref, struct ipmi_user, refcount);
1263-
cleanup_srcu_struct(&user->release_barrier);
1264-
kfree(user);
1277+
1278+
/* SRCU cleanup must happen in task context. */
1279+
schedule_work(&user->remove_work);
12651280
}
12661281

12671282
static void _ipmi_destroy_user(struct ipmi_user *user)

0 commit comments

Comments
 (0)