Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2517482imu; Thu, 17 Jan 2019 16:05:12 -0800 (PST) X-Google-Smtp-Source: ALg8bN6/oBj7ldVjjJjtAbH/++Z/XlVyveKxNBuyvwQUS7zLW4qMraeESYuMtZUGVOfUv8u2UkgQ X-Received: by 2002:a63:24c2:: with SMTP id k185mr15059061pgk.406.1547769912304; Thu, 17 Jan 2019 16:05:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547769912; cv=none; d=google.com; s=arc-20160816; b=N53xJmMzFIGr6JK92t7J7tu7MYcw4OGWNd07Y5yjzcwP0D5r4UC7foPZeD99tepGVY hQFt+ecX4EKUpMkooQf9ml2tv/bqV+SDlMCyijIbQH++VSzC8tmNr7Nfr3p+hqmvvBVJ M4uw+ybrwJkq+kz/SvwK4D1z4/M5+XcwFS4euZxdCwiiCjQsujYXBRs2LQ6tXinoqpOa fzLcXbfjGUoSkb8iOAoL8gGKNnq1Y/RggdyhekT7sMqUXkaAmJBSizGu4+EWo6ZKxJMD 8ZeF+e3roFx7AGH5hpZuK1+8t/JoPJ1XEYyXZ3qpkBuxVErHUDFkQtxxiVQXwG0wWw9Y MVFg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=rR3RDLyHYwnguSXTDDheTpq/ijJg5GujLPGznMcKOIo=; b=gx7+WkAVRFZsR7jFpwZVXqG39fQlqUOYBJ6bwM0euBJUU6435ZIzWoq9OgKiUaXQS3 udxeltUIU6FMCOoKWtP2WB6j2Fhx882DzwC+ChgyI+8N+YfvKoc5+4SgGErlrfra2e7y 7aEo435/aywOEl/otuKsEpIrgySaPHHMogIT+ZqNGR69zZTYwq4qFrK1tjH4enwp9SAQ DPXHWneGW97V8B1ADOJoq3u7y5SmouFXEyMiI/eaNls73wKj3HLrLSIVgYXy2jCUXoG7 HleEirO+mpu4zuwtTi/Su3vfuyIKFsepftw/ZCf7tASJ+bT78/JWT4P1+KnVlVStXFu4 s6cg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c20si2908353plz.391.2019.01.17.16.04.56; Thu, 17 Jan 2019 16:05:12 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727033AbfAQX7H (ORCPT + 99 others); Thu, 17 Jan 2019 18:59:07 -0500 Received: from terminus.zytor.com ([198.137.202.136]:36165 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725967AbfAQX7H (ORCPT ); Thu, 17 Jan 2019 18:59:07 -0500 Received: from hanvin-mobl2.amr.corp.intel.com ([134.134.139.83]) (authenticated bits=0) by mail.zytor.com (8.15.2/8.15.2) with ESMTPSA id x0HNwVxt951657 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Thu, 17 Jan 2019 15:58:32 -0800 Subject: Re: [PATCH 17/17] module: Prevent module removal racing with text_poke() To: Masami Hiramatsu , Rick Edgecombe Cc: Andy Lutomirski , Ingo Molnar , linux-kernel@vger.kernel.org, x86@kernel.org, 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 References: <20190117003259.23141-1-rick.p.edgecombe@intel.com> <20190117003259.23141-18-rick.p.edgecombe@intel.com> <20190117165422.d33d1af83db8716e24960a3c@kernel.org> From: "H. Peter Anvin" Message-ID: Date: Thu, 17 Jan 2019 15:58:31 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190117165422.d33d1af83db8716e24960a3c@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/16/19 11:54 PM, Masami Hiramatsu wrote: > 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? > The issue isn't the module list, but rather when it is safe to free the contents, so we don't clobber anything. We absolutely need to enforce that we can't text_poke() something that might have already been freed. That being said, we *also* really would prefer to enforce that we can't text_poke() memory that doesn't actually contain code; as far as I can tell we don't currently do that check. This, again, is a good use for a separate mm context. We can enforce that that context will only ever contain valid page mappings for actual code pages. (Note: in my proposed algorithm, with a separate mm, replace INVLPG with switching CR3 if we have to do a rollback or roll forward in the breakpoint handler.) -hpa