Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp9226480imu; Wed, 5 Dec 2018 00:53:17 -0800 (PST) X-Google-Smtp-Source: AFSGD/WbRbASSs2uiCg/H4QBEhCbL9I+9bQ+x4WwVgdeK4bjgL1ibCp7wD6Wa6MvuRfEh+b10Hzn X-Received: by 2002:a17:902:f81:: with SMTP id 1mr22589831plz.174.1543999997897; Wed, 05 Dec 2018 00:53:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543999997; cv=none; d=google.com; s=arc-20160816; b=U837HW3ZU4sEBXRuUgi6hQZlKso9oWDoQIN0a4tlVPceWuWQx1MAO+7NZG53dReLhi aEqGLyisbsPOuap1FHWUN4RzqTRUEowLl4D0rIzGp4SDsW2kC+HFL7IaIFN436vBrJPy j1qPAY3oZQ6cHgKz7m/10e8DXlls2pnlThs7yAq1fubmyui9EXGUPY3CI+LZr4mc1qsL TSVqaqdpvyK9w3zDvF5lxFxQR1CWmQWaulgUEvFxe+JdY/6VSpP64n4ebT6E9ATZMN9f yudC5rXo1BejNEfQ4QfOWQnHIOk0S8QU7yytDmNodC07IjonddQq6sgrfUWtr9MRS5B+ EFkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=rU/wKfno6py9kRvwlWgFYHLhj+Nnm0SA3jURC4rtka8=; b=ajApwuUqompBbNoD/URHGrAtha0syueMipeYsX1fmM7fnKM8kl+RzXMVCUAKw8UFeE NqGg+XY8lvBvqgUtxL3jvkJYwHsTadXVxUST7JX1uc977opaEm9lBWVohwnTPMtVCIY5 2gblrkuf38j5Q1dXs50yh0SK6h/qhI+kbZCDSG3cjMfsC9/B0zFfzMyqzKjfPsTZ6Rgx wa4LSscTzGOTf11lYYyXRwvvy41h9/gZXYr5FH6tFJnlN9qsGRNNcBLTqBRCNr5RRflG awf6EGniuMF21vZ+QERC/lgmVrbXVL7l0FJ0jqbf3TUnMo+z3lqVVFxKZOnHSbOmhO4d YMSA== 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=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o28si18266978pgm.238.2018.12.05.00.53.02; Wed, 05 Dec 2018 00:53:17 -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=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727523AbeLEIwS (ORCPT + 99 others); Wed, 5 Dec 2018 03:52:18 -0500 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:46460 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727500AbeLEIwP (ORCPT ); Wed, 5 Dec 2018 03:52:15 -0500 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Wed, 5 Dec 2018 00:52:04 -0800 Received: from sc2-haas01-esx0118.eng.vmware.com (sc2-haas01-esx0118.eng.vmware.com [10.172.44.118]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 45F6D41396; Wed, 5 Dec 2018 00:52:05 -0800 (PST) From: Nadav Amit To: Ingo Molnar CC: , , "H. Peter Anvin" , Thomas Gleixner , Borislav Petkov , Andy Lutomirski , Nadav Amit , Dave Hansen , Peter Zijlstra , , , , Nadav Amit Subject: [PATCH v7 14/14] module: Prevent module removal racing with text_poke() Date: Tue, 4 Dec 2018 17:34:08 -0800 Message-ID: <20181205013408.47725-15-namit@vmware.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181205013408.47725-1-namit@vmware.com> References: <20181205013408.47725-1-namit@vmware.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-002.vmware.com: namit@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It seems dangerous to allow code modifications to take place concurrently with module unloading. So take the text_mutex while the memory of the module is freed. Signed-off-by: Nadav Amit --- kernel/module.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/module.c b/kernel/module.c index 57c5b23746e7..b45754961143 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -64,6 +64,7 @@ #include #include #include +#include #include #include "module-internal.h" @@ -2181,6 +2182,9 @@ static void free_module(struct module *mod) synchronize_sched(); mutex_unlock(&module_mutex); + /* Protect against patching of the module while it is being removed */ + mutex_lock(&text_mutex); + /* This may be empty, but that's OK */ module_restore_mappings(&mod->init_layout); module_arch_freeing_init(mod); @@ -2194,6 +2198,7 @@ static void free_module(struct module *mod) /* Finally, free the core (containing the module structure) */ module_restore_mappings(&mod->core_layout); module_memfree(mod->core_layout.base); + mutex_unlock(&text_mutex); } void *__symbol_get(const char *symbol) -- 2.17.1