Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1693018imu; Thu, 17 Jan 2019 01:32:41 -0800 (PST) X-Google-Smtp-Source: ALg8bN4VyY7HfCZQaliLN2uAIiIcec6OnoXaizQRYB9D/7uAZ3ji41hg9WDKnuNNuGWGTKgqbeLS X-Received: by 2002:a62:e30d:: with SMTP id g13mr14080050pfh.151.1547717561429; Thu, 17 Jan 2019 01:32:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547717561; cv=none; d=google.com; s=arc-20160816; b=xwdYMNiAUp4j7vNs5lchCyYrU69CBoZaFipZmEzycwEX3IWr+VhUSJuD+yO8foMUlV D5ugJ4F7VhDRu8oVpF9hEm5dJZP2RTij95UFp3nD9gyFpvZvbTw8TzNE3GwCM5iyCiq6 y06SZjtjPhnqdXgi9a35GLhGkBGe4d2zXvN2COYl/grE2EQCZmZIYgZ/tY5Mk/WrH5NU fWSI5Tauxhl+oaDiP7ulbl4nKAcK0uQE4EJbsvxFu9jyZT2pZFy3wABrP0unQ7Hzjt/a TtuCUSbLkLcn9hkNXXfknv/NMyPh1PxRqx/7UyfWs7tAgj1TcRXIJOz93QgdkHEWVwl/ zylw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=l4RCjo6sa1i172rcFCuu+OVdhxoIohutG1S4t7rI17Q=; b=0tXCGOVpR7YLKaeUAmquHFbH5F9GGjgFc2QCR/cW7ZXfqr+9MtCRUOih7VRUhRVHIC zmr+kuR3brbuJIfaDDC/lKHtg27/nRG5i70ffsoZwskRjMSzfLKD5DYG7ne/JJJDYOuJ d+0eFhVj1EIOq5SpbXtYdAhsgArXchUXN5vyqa10Og2Sz8jJTw3bHiwlrqIusM6lDBZx iJI5E3EZa55/76iaQO3G3tXWXpgz6ihuVlsT3dUpg5GKLI8fP0cHvSSowINeINvGcjGy UCQJwobvziEjpEo0mY0zOcCWRIUVQRPn3j6r7IkoQXaP7KNoMaYgbHXidUh0J1x6HZdD PALQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JXwnKx5Q; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p26si1193567pfj.244.2019.01.17.01.32.25; Thu, 17 Jan 2019 01:32:41 -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; dkim=pass header.i=@kernel.org header.s=default header.b=JXwnKx5Q; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728039AbfAQHy2 (ORCPT + 99 others); Thu, 17 Jan 2019 02:54:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:59278 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727910AbfAQHy2 (ORCPT ); Thu, 17 Jan 2019 02:54:28 -0500 Received: from devbox (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (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 50D1420851; Thu, 17 Jan 2019 07:54:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547711667; bh=cLP9keXKzq/STJJ9tRlQcp79axKCXQ+ZALqsEKW8f/s=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=JXwnKx5QBw8EpzdBL49P38f8BWGU3Wf5+pKVZ/yfrILgpobZtHIUuPodUl9Pfjxpu C1Y2/iRtNlPDcSm6flBGNvYOyhVPaPtV3gbcXv7KcJJI4opgn1r3Ty3Y57Vxut/Q4n 6eGzscFlphc0FInZg2RxLKwpltZxF6TGXjv2pKVY= Date: Thu, 17 Jan 2019 16:54:22 +0900 From: Masami Hiramatsu To: Rick Edgecombe Cc: Andy Lutomirski , Ingo Molnar , 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 Subject: Re: [PATCH 17/17] module: Prevent module removal racing with text_poke() Message-Id: <20190117165422.d33d1af83db8716e24960a3c@kernel.org> In-Reply-To: <20190117003259.23141-18-rick.p.edgecombe@intel.com> References: <20190117003259.23141-1-rick.p.edgecombe@intel.com> <20190117003259.23141-18-rick.p.edgecombe@intel.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 16 Jan 2019 16:32:59 -0800 Rick Edgecombe wrote: > 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. At that point, since the module itself is removed from module list, it seems no actual harm. Or would you have any concern? Thank you, > > 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 > -- Masami Hiramatsu