Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp848835yba; Wed, 24 Apr 2019 10:34:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqw/V290X8FIzv0smiWgMLG/8k5v1ep8rXiAQ0pBrAs96678AZDnPCFoo++cjngp5t8hsLDh X-Received: by 2002:a62:7d57:: with SMTP id y84mr9527548pfc.52.1556127274158; Wed, 24 Apr 2019 10:34:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556127274; cv=none; d=google.com; s=arc-20160816; b=gQ93qauQGQj+b0c6sCrzEEJRsXYi0oX1jgn7oW4CSbvPKm5IYwn439T9FSx4N6Cx4f hrKTTkgshDlHR8UxwF8uNt7FKj3Kp0EeTZJ/876t248RtVgBtWHy6x9x4zLxZwrEUFhs AjXTXYMZJvtiKDweke4l70NPigWnBaxnw8QAUiJk6nKr0t510q1eCU/IT0MKX0bfUiF8 ytxnCXW81S2uhFowgmnbRy3ENur9qzrtZPKueQH2hKLwsdsubcyZs08aiQdoNjx2JTRD u8eM0JZgG4iSYWEjrQuOCsEtE7Etz+ugdERK6z3H44H7vd9FethNXI8pFM0lPpN3MvQq vUfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2w8c2Ygp1+ADloIxhEhHu7MvLQ/WFcajnJbaujoY8mQ=; b=Lct655/fnYqPvPGZmOmQJLA7403nnfLxd012URR24lkjhi7wi7ulwjfULoAqYEvc9/ 6kwoazlVG6VHrJuicOPoJmUAAbwdpzyQBaEi6Mt9SbCz4nA2bx/2ANIMqmweOvY1tMo+ OKnmtYNFYSt/3ja2dcPPkW/NabbfGmrQyuvRCm0/tjnbTnsTLZ39y4bl2ePgexFr5IH1 tb6h85TcYfBzKzLcP00II2WOujgijBFzsRKSQTHaYS/d9+WyJmKa1HRToNZ2dOYWX6lZ THuwTO4UM8I2A2hqVrBI7ZtPY1k/TXjnLLnnV0TojLMUvpC5P5/Nk4dLhwhy7mmd2qvm d7Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=k8xLQcR6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f11si19177997plo.169.2019.04.24.10.34.18; Wed, 24 Apr 2019 10:34:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=k8xLQcR6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391395AbfDXRcm (ORCPT + 99 others); Wed, 24 Apr 2019 13:32:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:58186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391141AbfDXRbj (ORCPT ); Wed, 24 Apr 2019 13:31:39 -0400 Received: from localhost (62-193-50-229.as16211.net [62.193.50.229]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DCE9820811; Wed, 24 Apr 2019 17:31:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556127098; bh=0yyABwQY7RvUTcNbSEh55P51GhJ/mIjPQrvSnas60C4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k8xLQcR6uJg+CaLExbaJONSzrV2YTdbnqd69HDt5JiYJDszeD/IA1DYEYv0QMPBBb 22olNTge7rUUmbucKGzOaZgbjBmr8c/QlrupMWHHWu0jG/5KYkDD035AIoba59RlJX 3tdeqFvFE1R9nxHto+HFNAwiLens9iVkO2o2Dutg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Konstantin Khlebnikov , Corey Minyard , Yang Yingliang Subject: [PATCH 4.19 62/96] ipmi: fix sleep-in-atomic in free_user at cleanup SRCU user->release_barrier Date: Wed, 24 Apr 2019 19:10:07 +0200 Message-Id: <20190424170923.909387037@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190424170919.829037226@linuxfoundation.org> References: <20190424170919.829037226@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Corey Minyard commit 3b9a907223d7f6b9d1dadea29436842ae9bcd76d upstream. 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: 77f8269606bf ("ipmi: fix use-after-free of user->release_barrier.rda") Reported-by: Konstantin Khlebnikov Signed-off-by: Corey Minyard Cc: stable@vger.kernel.org # 5.0 Cc: Yang Yingliang Signed-off-by: Greg Kroah-Hartman --- drivers/char/ipmi/ipmi_msghandler.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) --- a/drivers/char/ipmi/ipmi_msghandler.c +++ b/drivers/char/ipmi/ipmi_msghandler.c @@ -213,6 +213,9 @@ struct ipmi_user { /* Does this interface receive IPMI events? */ bool gets_events; + + /* Free must run in process context for RCU cleanup. */ + struct work_struct remove_work; }; static struct ipmi_user *acquire_ipmi_user(struct ipmi_user *user, int *index) @@ -1078,6 +1081,15 @@ static int intf_err_seq(struct ipmi_smi } +static void free_user_work(struct work_struct *work) +{ + struct ipmi_user *user = container_of(work, struct ipmi_user, + remove_work); + + cleanup_srcu_struct(&user->release_barrier); + kfree(user); +} + int ipmi_create_user(unsigned int if_num, const struct ipmi_user_hndl *handler, void *handler_data, @@ -1121,6 +1133,8 @@ int ipmi_create_user(unsigned int goto out_kfree; found: + INIT_WORK(&new_user->remove_work, free_user_work); + rv = init_srcu_struct(&new_user->release_barrier); if (rv) goto out_kfree; @@ -1183,8 +1197,9 @@ 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); - kfree(user); + + /* SRCU cleanup must happen in task context. */ + schedule_work(&user->remove_work); } static void _ipmi_destroy_user(struct ipmi_user *user)