Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10496594imu; Thu, 6 Dec 2018 02:02:44 -0800 (PST) X-Google-Smtp-Source: AFSGD/XBK61xLT6shXvmM3jzsE7NazgCmiKdJtj/4O3Si7nkZ6agTlm5I3nnPYMzqyAzpWcSMN2M X-Received: by 2002:a63:1412:: with SMTP id u18mr23103945pgl.247.1544090564533; Thu, 06 Dec 2018 02:02:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544090564; cv=none; d=google.com; s=arc-20160816; b=lyQkFWVAiBEVNI+Oog//uOydKmqoxzGeorbTD6h/W5Kh0x1MrVftjsgUHwHYRlgDEE I64PIe6SOuLwUPCxZNa1z/tE+iLVJGJW381DPQQARteNoetLF5MO/TSFijJzityXF1hM DFCOobQ1ijrjqrbmo6xet/a9n+xmNzHGhSpbQHSxrOcOkFbzU2Ny/tobiObPThoHOzl8 7gOBsyQ16tbxfsktNVeGjMFrz6C5uRrKhLVpoZMPbN3ahO1wbvfd62LBADatnF1eWXpQ y19+rEG++431h08+BM4misWRqe1YpvT7eAlEy4e5AuLDlYIdLtevQfJvBQESzDTgdWtx gGeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=afwQ0qh9MbNdNZ2OyRpkWK2h5apCJ6FvFvOC/iuZX2A=; b=LtiJ8OgTTyEJpsTXwJp0VSCQ0ZTzFR1FkLvapbIbVKW3Z/VqKCEEONjSHnYoWZ4oBC FqGcle/CeLI0rn9NvwSF+e/uZb3cjcVGX3KmPhD216nP1RhCQqskkU+v1qGw/t7lgzNM HczuGzYsfnIm0BeI3jJYoHsd9v7IAQS5BiASwzhWEOiR/l8nWsRfz6NQ2IDp1gFi01P5 ufuSY3EvFUqqUPeyxD7CoyCuFoCFJRVJn4XjG6I7GszhXW/7ZCuGTgi7dGagdfI2L0B5 T0fNgtDIw3ub1+g/jtQjYtkYE+baXNrA4lt864Aq8HkCMUya47cF2BgWcjfP66b/mT/U jT9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=WpsOaBir; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e34si20706449pgb.80.2018.12.06.02.02.27; Thu, 06 Dec 2018 02:02:44 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=WpsOaBir; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728939AbeLFKBa (ORCPT + 99 others); Thu, 6 Dec 2018 05:01:30 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:50032 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727763AbeLFKB3 (ORCPT ); Thu, 6 Dec 2018 05:01:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=afwQ0qh9MbNdNZ2OyRpkWK2h5apCJ6FvFvOC/iuZX2A=; b=WpsOaBirBGWPB2HmgU91YFISM +S1TBRy/7Cn7VGJc+J4XtS5s/Xa1TyQVTiIfXWaWDS7PFcQPjgETC8SKznIJtsL3D3GRwAYq4mBxw 7UFPopAQFNfXgOROd+jwN/kyni1gewM6CUPX3+xpnQAUwMl1WJENctSlGblAkL8ZDnDpNvh49/GHW O062VsxYKhZOcB7w8dJ8D4KNfxEPbOSHgqIKGQIxrR/Brz1gY5EWxtz0xH0bNMnMsxJFSUrFAzlYw tRmtDZ4Tl+EJSmeb/eCAk8Mc9MCnQ9raIQFt5rLjclMXgqdHz3gODrnz+GK1/srb3Hhyqv9MHu1xL wY07mfWkw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gUqT4-00072a-2M; Thu, 06 Dec 2018 10:01:14 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 933EB200FBC3D; Thu, 6 Dec 2018 11:01:12 +0100 (CET) Date: Thu, 6 Dec 2018 11:01:12 +0100 From: Peter Zijlstra To: Nadav Amit Cc: Ingo Molnar , linux-kernel@vger.kernel.org, x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Borislav Petkov , Andy Lutomirski , Nadav Amit , Dave Hansen , linux_dti@icloud.com, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org Subject: Re: [PATCH v7 14/14] module: Prevent module removal racing with text_poke() Message-ID: <20181206100112.GE13538@hirez.programming.kicks-ass.net> References: <20181205013408.47725-1-namit@vmware.com> <20181205013408.47725-15-namit@vmware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181205013408.47725-15-namit@vmware.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 04, 2018 at 05:34:08PM -0800, Nadav Amit wrote: > 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. Fun detail, only x86 seems to actually take text_mutex while poking text. > 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 >