Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2570239imu; Thu, 17 Jan 2019 17:16:55 -0800 (PST) X-Google-Smtp-Source: ALg8bN5bHAQ2W19Zcqyl2rfD6r25nrx0lidscvCuPSf/z9/OeNUfbA44WCHWixWWflokp52nmIkY X-Received: by 2002:a17:902:74cc:: with SMTP id f12mr17229953plt.134.1547774215060; Thu, 17 Jan 2019 17:16:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547774215; cv=none; d=google.com; s=arc-20160816; b=RdBmegtVVAXalSLrh/l207vbguv0Url0FGwpBzwCDTmeGmeoVP4kJKAi2IICmcKECt YmTVEGGrjAs1OGYc4V6ZQ+4PRkT1xyEHANC/SX52heNrhAhrxVcDhiyT+/NhQ/lnPalI CikpJXLQ4AncN1j9FtqLNK3CZzUTYKsmj0eg9V3KTdiNlSse07FQdZMLMftTMgd+G+rO o16eTghdijQsIu8gFGXS5MtVruenpQO4RViO29E2HJR9jVtu75cARdtszHOAIdKS01LZ wAdm+dAU7/Da37W5zvGeYKUf0l3aZxqL90UAFkNrhlV7epE7NXriJCdERp37BV7kZQPR 8bEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=nfJ8xS7Q4/2eN93Hqyw2Vxt0we5DRJFkV8HYkEezqLo=; b=JIdz8lffu277wVzRJ8xXmisyKKJBhxFyQT8VJ0fGF4hUF45GLZ9q+/Nix0PkLBLhVV qPI8L0VCV7dL02WJwn6RKB7A6ZJ1bfuV/8+9VlnKzS9iY9Nyo1Ej8L+jmBXNP1xYlG7n sWcIKfPMOLmMKKr7x0p3carBt3Y8v4pHsvuQwlySmkQ5+m55bbsBfHXTpjBUp1Cu/2Wn 5a+K9FlrNLh+s5eHKGoF7RGzwsym1PvgMWu52bco+1BdlyRt/J9elIdBwyC7MuUW4gIG F4lcMobiZh4PvoFlnk4Rf6aI/3AMRJD3ABII88TTpYpdFq7pOdCgP8gzshPXnXQCM8nH QKnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=epnDOoDP; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y123si3248492pfy.18.2019.01.17.17.16.38; Thu, 17 Jan 2019 17:16:55 -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=@gmail.com header.s=20161025 header.b=epnDOoDP; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726875AbfARBPc (ORCPT + 99 others); Thu, 17 Jan 2019 20:15:32 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:41584 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726351AbfARBPc (ORCPT ); Thu, 17 Jan 2019 20:15:32 -0500 Received: by mail-pg1-f194.google.com with SMTP id m1so5228373pgq.8; Thu, 17 Jan 2019 17:15:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=nfJ8xS7Q4/2eN93Hqyw2Vxt0we5DRJFkV8HYkEezqLo=; b=epnDOoDPCYmQOrRqrJQDp6hqSyVOqA0OACC2E+Ypn35v71FNxBed0ZH8UKd8f1psrB kJs41dfmRvph0F9K7JaapS1CHnzIy2vKVy9qkAUllNemr9yxSw8C6DunC3RMPtVKvwlR LOUcswMxytdeBueSBzD9P3zQeg6E9vFeE7IXhdHzF98pMEvyF812GWg0Ji2Qhgu86q3R apfvAxMV3yN41Y8OKaxw2fHOrIZBMQTkEg72xsNxSei7Pjwor+U9qnFFUH5nqhyesWHN kkoMYn3Ji7E8+iDqmxNIFglZ+aX99ecIENnM9cTC8a6aNiLvGg2zZ4Vr4QvgYhw+2hLX /yVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=nfJ8xS7Q4/2eN93Hqyw2Vxt0we5DRJFkV8HYkEezqLo=; b=Kw+Gr65rTOFdDiaTLTXE8HHyaV/ntAtYKEFzuNG0qIAOgbq9RUFLWHfOXpQGyK+3h9 9b0Z1W2CwdwIB3Q32m9ytLMm/r7upYnkqyX8NON6N0m9RCNdetWHueUv9ttXu17Eo33Z jVzOK5Nl2bzDHq8VvzlpmzexlvoxXnpIO6vD7puxFXUNNqpTPI1oviq3N9fC0lzHpnDO 86urxWipYRXvtVSm877kE9NN0+WZuV0QTA03T280fFaLPSU+jGAIRFceyxRgHDzF4Vnt 6Z3gAd8cMRRaT5gOZn3LoGJXd+ih47qyRP6Y1MTGYtV3iE3zoPhWH4VvOFB26stjpUph mkhw== X-Gm-Message-State: AJcUukfQMnvtd5zS7KLn5mI3dI4j32L1SKzjFdBDwihM5w2Fx5dBPAcv 5ycUUBYMCxUFkgtcHR7L5o4= X-Received: by 2002:a63:1204:: with SMTP id h4mr15579607pgl.51.1547774130020; Thu, 17 Jan 2019 17:15:30 -0800 (PST) Received: from [10.33.115.182] ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id r6sm6866962pgk.91.2019.01.17.17.15.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Jan 2019 17:15:29 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Subject: Re: [PATCH 17/17] module: Prevent module removal racing with text_poke() From: Nadav Amit In-Reply-To: Date: Thu, 17 Jan 2019 17:15:27 -0800 Cc: Masami Hiramatsu , Rick Edgecombe , Andy Lutomirski , Ingo Molnar , LKML , X86 ML , Thomas Gleixner , Borislav Petkov , Dave Hansen , Peter Zijlstra , Damian Tometzki , linux-integrity , LSM List , Andrew Morton , Kernel Hardening , Linux-MM , Will Deacon , ard.biesheuvel@linaro.org, kristen@linux.intel.com, deneen.t.dock@intel.com Content-Transfer-Encoding: quoted-printable Message-Id: <69EA2C81-826F-46BA-8D80-241C39B0B70B@gmail.com> References: <20190117003259.23141-1-rick.p.edgecombe@intel.com> <20190117003259.23141-18-rick.p.edgecombe@intel.com> <20190117165422.d33d1af83db8716e24960a3c@kernel.org> To: "H. Peter Anvin" X-Mailer: Apple Mail (2.3445.102.3) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Jan 17, 2019, at 3:58 PM, H. Peter Anvin wrote: >=20 > On 1/16/19 11:54 PM, Masami Hiramatsu wrote: >> On Wed, 16 Jan 2019 16:32:59 -0800 >> Rick Edgecombe wrote: >>=20 >>> From: Nadav Amit >>>=20 >>> 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. >>=20 >> At that point, since the module itself is removed from module list, >> it seems no actual harm. Or would you have any concern? >=20 > 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. >=20 > 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. Yes, that what the mutex was supposed to achieve. It=E2=80=99s not = supposed just to check whether it is a code page, but also that it is the same code page that you wanted to patch.=20 > 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. This will not tell you that you have the *right* code-page. The module notifiers help to do so, since they synchronize the text poking with the module removal. > (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.) I really need to read your patches more carefully to see what you mean. Anyhow, so what do you prefer? I=E2=80=99m ok with either one: 1. Keep this patch 2. Remove this patch and change into a comment on text_poke() 3. Just drop the patch