Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1632415imu; Thu, 17 Jan 2019 00:21:17 -0800 (PST) X-Google-Smtp-Source: ALg8bN6QgDkCrKUHTfaOXWnp04wpzb4NaCQhUllb++/quvjK0d97i+ZJEu0OW1vTRHIFQvPcgnrJ X-Received: by 2002:a17:902:724a:: with SMTP id c10mr14231365pll.51.1547713277928; Thu, 17 Jan 2019 00:21:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547713277; cv=none; d=google.com; s=arc-20160816; b=QT+FCHjHeqM3i6mFMsuiqRTJn+hkl9Rp44Xi584uYdK6aCDnt8WwIYJfC/BfRzM8uV 64ygI9e3RRqd0gzr+OvjY17MHVNdGQlPQPs1rh5pJTnWoGTEaJ6U5JA/5sjHAiUjUT+u xkwAAdzS94j4jVPlZ6mXJkGCwNqj2p2LOuVfcK4xqRr8pWn6Mbqkl98lYFnz3KbH0s80 cY85Ez1fQPbQ5MGK5E62+L3040ytuOhHuzIAn5GTqv8RttEjrMurBS2YhajPERAKPcmx PELijGAVVQNKweVG7PWJg0nBHAXcdwk6/JBDecLfJM4aCeA0INJ7/O45ke7BxWfkFwYO Aipw== 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=Dpr92+KbHY9cTHM1Ui4q2NtOJyMHY6aShd4aXoAfyzo=; b=LSuQy+AyQgakUG+x2efBR4/wdLCfZ4suwRLmNxxGZuuNiKHbE6EkRJy4Xm6wthpF3x LIo1+aepZngGIYJYXw7vajrbLa/FH4zSyqrS/31YcKqqTTtNAuWJIpu2oevtFs4N3m7f Czv978P9t77h3BS/VTRMtVntrxxsgQxXDp5QeMqymfDR3tTplboXqvOJRYoBL/32Gt67 CTXpMYr56l70vXJMO/PB7TJVwRQSGc8cj/Q4rCukVVHE7TijQXDY8d7cZR0v/uShiYqy ppE4wvsIM8RXyej/zVtKDwETOEppM143Nj4Kouttc4uiT5/jBlBQYpUh83WtkTTQ1kmV dj9w== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b89si1064284pfj.207.2019.01.17.00.21.02; Thu, 17 Jan 2019 00:21: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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730545AbfAQAeG (ORCPT + 99 others); Wed, 16 Jan 2019 19:34:06 -0500 Received: from mga11.intel.com ([192.55.52.93]:47095 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730163AbfAQAdp (ORCPT ); Wed, 16 Jan 2019 19:33:45 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jan 2019 16:33:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,488,1539673200"; d="scan'208";a="292166062" Received: from rpedgeco-desk5.jf.intel.com ([10.54.75.79]) by orsmga005.jf.intel.com with ESMTP; 16 Jan 2019 16:33:36 -0800 From: Rick Edgecombe To: Andy Lutomirski , Ingo Molnar Cc: linux-kernel@vger.kernel.org, x86@kernel.org, hpa@zytor.com, Thomas Gleixner , Borislav Petkov , Nadav Amit , Dave Hansen , Peter Zijlstra , linux_dti@icloud.com, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, akpm@linux-foundation.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, will.deacon@arm.com, ard.biesheuvel@linaro.org, kristen@linux.intel.com, deneen.t.dock@intel.com, Nadav Amit , Rick Edgecombe Subject: [PATCH 17/17] module: Prevent module removal racing with text_poke() Date: Wed, 16 Jan 2019 16:32:59 -0800 Message-Id: <20190117003259.23141-18-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190117003259.23141-1-rick.p.edgecombe@intel.com> References: <20190117003259.23141-1-rick.p.edgecombe@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nadav Amit 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 Signed-off-by: Rick Edgecombe --- kernel/module.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/module.c b/kernel/module.c index 1af5c8e19086..90cfc4988d98 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -64,6 +64,7 @@ #include #include #include +#include #include #include "module-internal.h" @@ -2157,6 +2158,9 @@ static void free_module(struct module *mod) synchronize_rcu(); 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_arch_freeing_init(mod); module_memfree(mod->init_layout.base); @@ -2168,6 +2172,7 @@ static void free_module(struct module *mod) /* Finally, free the core (containing the module structure) */ module_memfree(mod->core_layout.base); + mutex_unlock(&text_mutex); } void *__symbol_get(const char *symbol) -- 2.17.1