From patchwork Thu Jan 17 00:32:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 10767241 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 341F514E5 for ; Thu, 17 Jan 2019 00:33:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A5AA2DDF1 for ; Thu, 17 Jan 2019 00:33:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D4722DFD8; Thu, 17 Jan 2019 00:33:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD0BF2DDF1 for ; Thu, 17 Jan 2019 00:33:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DD528E000C; Wed, 16 Jan 2019 19:33:40 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 418328E000A; Wed, 16 Jan 2019 19:33:40 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E28108E0006; Wed, 16 Jan 2019 19:33:39 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id 91A338E0006 for ; Wed, 16 Jan 2019 19:33:39 -0500 (EST) Received: by mail-pf1-f197.google.com with SMTP id 68so6023689pfr.6 for ; Wed, 16 Jan 2019 16:33:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=Dpr92+KbHY9cTHM1Ui4q2NtOJyMHY6aShd4aXoAfyzo=; b=k8BtYelLB3+4FYbABOlpFg6jkLKcFoopafO2m+58jIirmKrTCXwJeYT/V8X9buV6I8 xLr1WB8pEI6QPO3tbzMxGhf4trPM6W9rtlLt4OWKJWTjekpf3EtCEV4872UldH7W1jYb bR6szyh/71nsaslAPCfjAE1M6+97gBpAfVEpt5FvJoUTHJsqUyWkqgNvA7o7u8kiWzen TOUgn0Qpya9UgZalpmxbecACRY8iu/c7sE7vLiA3WEr71w6RXZleFcQj6K8ZOICwsRVZ MkRHuprfvQiNj1g0Hs8YBUic5Z7HVdBhg6ZzuK33QcmrhBjoJhoXdu7o/Ciunmc1CXeC 0PrA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AJcUukfDQjmP/OIWUmopqX7aQmejzWNXRDtNS/CB6Z7Azd26qP06R/2W w7NLSGknyu3Ms+ZllABF4J833dfmqtR7obVF4AC5VgDhvLnMYeL9iLDtQyE8IXPFRWebgoAQ8b8 CTcJIdL0vRy9P0+9Lcnk5IiojDu65QCV54xG7Rrm7ZeBn6CltLVl/XdW5lpL3Qe0CDw== X-Received: by 2002:a63:77ce:: with SMTP id s197mr11374241pgc.89.1547685219228; Wed, 16 Jan 2019 16:33:39 -0800 (PST) X-Google-Smtp-Source: ALg8bN6nnawnKgpMWamhf71b73pzBgdP3JqdKu6AO4s88QvIonDfrtnz9vC9E2d7+bXsSlOINpso X-Received: by 2002:a63:77ce:: with SMTP id s197mr11374173pgc.89.1547685218327; Wed, 16 Jan 2019 16:33:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547685218; cv=none; d=google.com; s=arc-20160816; b=ADodZWoIJFRAVd/gtPWLQWE40BlYla7m1gPgu+PF/WWXiVuEgkjnHpnqxq5HbvB1uo N3RXe3acRM9DlbT5r1S4SkfxVVfxkzr3IAeUDgmk6eDWgmjuZI4fYCCYrtS18KotE1ov oar/YRq7TxD4KUaLi5wgfeI8kDRMDzmosX9M7sO7nwCm1sKtBg4SRAs9v6c+cUZFuks3 Ic6Ax54WDox6EmTAG3oj3whtECMoe34mWZq4ODZGjL9UkF8XWLrJF+tD1IxUrKx7mtyV 1x5cscgOqJnY5SWyF5/txwUVABUKmuGaqYUeL0uK+HqwxrKR8LE4wR9Z/asbLGjKAuGr hd+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=Dpr92+KbHY9cTHM1Ui4q2NtOJyMHY6aShd4aXoAfyzo=; b=07qZmHPHkSTiXlkMNkDP3a98U3TsGaVRTkwur82/75iJDYVXwenAU1lIb3lqOgaj0j e2wzIAzT+39iX/cJRr62+dA/kOZK8j2wIhsVyrXpqjLvUVOy5X/1TMsfV7clgAbAsPll FkeySiQfpPtJ5aPSFaM2I+JbPSo9ew++QGhKRpldTRdUdmOH4mvr3vHrkvDf+m2vMlZi dPfoHVQdakO5OKvaeV5xGJiMYYBUfDTzO9CiUFMdEcZVXF9lVJBfOad7ekxKvze+36zT L3BpEyRR/ro1KibhgJLmYbGj8NVpvVYaZoekHXvCxdrmRGbCAuWLWq5BOxS6U/dZdEVU mM1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga05.intel.com (mga05.intel.com. [192.55.52.43]) by mx.google.com with ESMTPS id m3si7883258pld.331.2019.01.16.16.33.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Jan 2019 16:33:38 -0800 (PST) Received-SPF: pass (google.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.43 as permitted sender) client-ip=192.55.52.43; Authentication-Results: mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.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> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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)