Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1622337ybc; Wed, 13 Nov 2019 01:34:22 -0800 (PST) X-Google-Smtp-Source: APXvYqw/vEASza5O2KjDGiwYkzYJM/wcCeKBhc/W19NYmzbLlHqimerBQTI72QGAKtwiKKjMzoLO X-Received: by 2002:aa7:df8c:: with SMTP id b12mr2518147edy.166.1573637662570; Wed, 13 Nov 2019 01:34:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573637662; cv=none; d=google.com; s=arc-20160816; b=1JSxBnBqdFoAaDySBEps9z3RVT2nMhVTIuzd6ROcC0hDES92WBN2CPxIiqGQ66PrGD vLddXu04/70x1GyWV+tKEjG7GUOEEAHrcubzAp6/KtfxXnB+QfcLLx97SoqXHQqFo7gg FkGJT1TMYNOxIJKmMJYtEH6afCROI8B0HK/83/DXY+iT17NmFY7g8/RjBjKFVM7eX0uR q810qKx4dy8aWWJufPVBom57wCtXKxDe5p51h0xCMK5KViULBL5ykPSq10imM/8NFSW3 K6B9SGkTqY5XR8iGwBiPNNeCCHrpRmt6CI9A1VajdL8touIiH6ALizOobax35TyyHSyz HAcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=Uz25A8eC4O2p/eRmvFOn7RIJWrpk1wEvkMjXz5GMp1o=; b=aF9bveyRTy6tuu9Q7CcqP6ifOHI2m4MTwKhwfBbeSRcWo2PJAD7eB4SgjRyUOXUFGB Z0D6TYYGUmDUvJYFKFoxMS4/nhkA0NGyIy0/puauEit3y484iC2H1v1kFPl/wJipZQAh mk5rMj+U74s5fyUn2q6NM5FNILzcjgSJ0pvgtmXIprITN2gEgZE1nUsA8NWUW74uUo44 A5TQm5cxB9GR9aLxSq0Qp18IMVYwp/ul0JLexJ/EYoq21f1KWG6E0bkIdrJkym/qHhGT QsuN7mKPXOjiaiPM7E9WeDyLDqEkGRUxsROizPO4If/wYzddx63cjDtoFEtcFOqa2MxS N0kA== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w17si1047507edc.152.2019.11.13.01.33.57; Wed, 13 Nov 2019 01:34:22 -0800 (PST) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727372AbfKMJaO (ORCPT + 99 others); Wed, 13 Nov 2019 04:30:14 -0500 Received: from relay.sw.ru ([185.231.240.75]:39206 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727074AbfKMJaN (ORCPT ); Wed, 13 Nov 2019 04:30:13 -0500 Received: from finist_cl7.qa.sw.ru ([10.94.4.83] helo=finist-ce7.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iUoyF-00062s-7g; Wed, 13 Nov 2019 12:29:51 +0300 From: Konstantin Khorenko To: Jessica Yu , Prarit Bhargava , Barret Rhoden Cc: Konstantin Khorenko , Andrey Ryabinin , linux-kernel@vger.kernel.org, David Arcari , Heiko Carstens Subject: [PATCH 1/1] kernel/module.c: wakeup processes in module_wq on module unload Date: Wed, 13 Nov 2019 12:29:50 +0300 Message-Id: <20191113092950.15556-2-khorenko@virtuozzo.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20191113092950.15556-1-khorenko@virtuozzo.com> References: <20191113092950.15556-1-khorenko@virtuozzo.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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") Signed-off-by: Konstantin Khorenko --- kernel/module.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/module.c b/kernel/module.c index ff2d7359a418..cb09a5f37a5f 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -1033,6 +1033,8 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user, 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); -- 2.15.1