Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8417648imu; Tue, 4 Dec 2018 08:05:58 -0800 (PST) X-Google-Smtp-Source: AFSGD/XQaKr9Y3fFnw+w6iKxx2El8cL0HfNNAdQHSfWNTiVLyI/xhUZSLxmFVZLoE74uLLB/Qg91 X-Received: by 2002:a17:902:76ca:: with SMTP id j10mr19948823plt.144.1543939558079; Tue, 04 Dec 2018 08:05:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543939558; cv=none; d=google.com; s=arc-20160816; b=dtRwRllKnmNJLc52Dt6k2RI+Oj0/p+hkuxJhfkRvsTmLDP2LmIPZXv9bskVRtg/Nr5 ai8b318Tr+Mm2ZM9SLYuNh8+UzrCaagbDZvNTQZqG4MABLrtm9AN+Te6uw9TB/5VjwdZ r5nWhTn4aICRI5nss8Uqe1iV83TJOquUVC3LAWHlfk0UkEQLkKKdxEV2/Ts92ZfxEvp6 HafCBRUlIkkzv1kx8ikQqdA3gJDvb1lvI3GkYn3O3lxc7svO97Y2gBHn5WfG0UtHeiSb VfphhwgA7XtOVRYsrl7igMDiH9vuwZux8y7APfTb7JPbYomkJCvBVY5UNiEhZo0L9Jx4 4k9Q== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=Puhw8+//ZSYXFm4QctQDOaW8RPcJuFOec70k3mwY23M=; b=IGzbb9JRdEpqSjnbQ1BXcwWrPgem1InX3NP2e31/ynIaUd59c/27YXEZ+2SidttJ7P Noi8Ih13D+ZboG7Pz8Num1u6hH8s/LMDbQQKHoL6yfOcc+izNnCcQvr7o9ARfQsMfXQr ObyA524Jc9tQUBNkH88NCYv/fQqKTpFN4Db/3MYDTuKZYi4zldsYAjBLX560XX511eDM 7EIt3rq7F4eStqb+oK6tHFt4YuyPH6/PAWQ+tBNpCo42RDhzv5rgH9c14HlM3wyU/yNx nErdvJsqT5oW+7+D/G8M4CV5F7Nq6XO6guMz8gBT7z3AeeIRoMsEEY0avZwmnrkqIPLm zTMg== 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 m64si18531897pfb.224.2018.12.04.08.05.36; Tue, 04 Dec 2018 08:05:58 -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 S1726965AbeLDQCp (ORCPT + 99 others); Tue, 4 Dec 2018 11:02:45 -0500 Received: from foss.arm.com ([217.140.101.70]:35814 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726459AbeLDQCo (ORCPT ); Tue, 4 Dec 2018 11:02:44 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 614C5A78; Tue, 4 Dec 2018 08:02:44 -0800 (PST) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2FD2C3F614; Tue, 4 Dec 2018 08:02:44 -0800 (PST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 8C35D1AE0BA0; Tue, 4 Dec 2018 16:03:04 +0000 (GMT) Date: Tue, 4 Dec 2018 16:03:04 +0000 From: Will Deacon To: Nadav Amit Cc: Rick Edgecombe , Andrew Morton , Andy Lutomirski , linux-mm , LKML , Kernel Hardening , naveen.n.rao@linux.vnet.ibm.com, anil.s.keshavamurthy@intel.com, David Miller , Masami Hiramatsu , Steven Rostedt , Ingo Molnar , ast@kernel.org, Daniel Borkmann , jeyu@kernel.org, netdev@vger.kernel.org, Ard Biesheuvel , Jann Horn , kristen@linux.intel.com, Dave Hansen , deneen.t.dock@intel.com, Peter Zijlstra Subject: Re: [PATCH 1/2] vmalloc: New flag for flush before releasing pages Message-ID: <20181204160304.GB7195@arm.com> References: <20181128000754.18056-1-rick.p.edgecombe@intel.com> <20181128000754.18056-2-rick.p.edgecombe@intel.com> <4883FED1-D0EC-41B0-A90F-1A697756D41D@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4883FED1-D0EC-41B0-A90F-1A697756D41D@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 03, 2018 at 05:43:11PM -0800, Nadav Amit wrote: > > On Nov 27, 2018, at 4:07 PM, Rick Edgecombe wrote: > > > > Since vfree will lazily flush the TLB, but not lazily free the underlying pages, > > it often leaves stale TLB entries to freed pages that could get re-used. This is > > undesirable for cases where the memory being freed has special permissions such > > as executable. > > So I am trying to finish my patch-set for preventing transient W+X mappings > from taking space, by handling kprobes & ftrace that I missed (thanks again for > pointing it out). > > But all of the sudden, I don’t understand why we have the problem that this > (your) patch-set deals with at all. We already change the mappings to make > the memory writable before freeing the memory, so why can’t we make it > non-executable at the same time? Actually, why do we make the module memory, > including its data executable before freeing it??? Yeah, this is really confusing, but I have a suspicion it's a combination of the various different configurations and hysterical raisins. We can't rely on module_alloc() allocating from the vmalloc area (see nios2) nor can we rely on disable_ro_nx() being available at build time. If we *could* rely on module allocations always using vmalloc(), then we could pass in Rick's new flag and drop disable_ro_nx() altogether afaict -- who cares about the memory attributes of a mapping that's about to disappear anyway? Is it just nios2 that does something different? Will