From patchwork Tue Jan 7 20:54:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 234278 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F01C4C33C9B for ; Tue, 7 Jan 2020 21:23:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BB3FA206F0 for ; Tue, 7 Jan 2020 21:23:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578432197; bh=pyPPGbPS6/EVbtjWM4DRd9D9gio7DbqyD2xvnAM4syU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=oAbJtlCi9cT/HosVc7LfHs7LbVY1Plo1FOufhM7dswx5QeFpOPAeI1AAA0s978YE2 jKePBMmR3O55R76jZ5rK7RfB7zKuyescEjRjCLH0aeEM7Yvtxa8gknJedfARPtSvDh m0wY1WaCHjzSppGtTWdrE8csnZJgOc7LawlpP3R0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728799AbgAGVXC (ORCPT ); Tue, 7 Jan 2020 16:23:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:39112 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728599AbgAGVBe (ORCPT ); Tue, 7 Jan 2020 16:01:34 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 B41CD20678; Tue, 7 Jan 2020 21:01:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578430894; bh=pyPPGbPS6/EVbtjWM4DRd9D9gio7DbqyD2xvnAM4syU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O0I4+JKrgn74KkaF2vc6tmQ6LH6hCuik3iHw4WJLN0w+n6Q7+xzdJyFHMhGL4gWdx 0JcwGtgnwc83Rvp9N+TsOhN9BSbwArtB7kqVr914cCeqNjKACmS04C2cp5HXep+5cQ u968fWH3EdvKABhFPaQYVbxpa5zvUafIn/JPEcgw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Prarit Bhargava , Konstantin Khorenko , Jessica Yu Subject: [PATCH 5.4 141/191] kernel/module.c: wakeup processes in module_wq on module unload Date: Tue, 7 Jan 2020 21:54:21 +0100 Message-Id: <20200107205340.524070101@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200107205332.984228665@linuxfoundation.org> References: <20200107205332.984228665@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Konstantin Khorenko commit 5d603311615f612320bb77bd2a82553ef1ced5b7 upstream. Fix the race between load and unload a kernel module. sys_delete_module() try_stop_module() mod->state = _GOING add_unformed_module() old = find_module_all() (old->state == _GOING => wait_event_interruptible()) During pre-condition finished_loading() rets 0 schedule() (never gets waken up later) free_module() mod->state = _UNFORMED list_del_rcu(&mod->list) (dels mod from "modules" list) return The race above leads to modprobe hanging forever on loading a module. Error paths on loading module call wake_up_all(&module_wq) after freeing module, so let's do the same on straight module unload. Fixes: 6e6de3dee51a ("kernel/module.c: Only return -EEXIST for modules that have finished loading") Reviewed-by: Prarit Bhargava Signed-off-by: Konstantin Khorenko Signed-off-by: Jessica Yu Signed-off-by: Greg Kroah-Hartman --- kernel/module.c | 2 ++ 1 file changed, 2 insertions(+) --- a/kernel/module.c +++ b/kernel/module.c @@ -1033,6 +1033,8 @@ SYSCALL_DEFINE2(delete_module, const cha strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)); free_module(mod); + /* someone could wait for the module in add_unformed_module() */ + wake_up_all(&module_wq); return 0; out: mutex_unlock(&module_mutex);