Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2411581imu; Thu, 17 Jan 2019 13:46:22 -0800 (PST) X-Google-Smtp-Source: ALg8bN7fh6+d8koC3Q6KaFnVml999ywm71n/MvBoGNZHNTI6iMfwbOhARpRMmjH3P4uBE3goWruk X-Received: by 2002:a17:902:583:: with SMTP id f3mr16990491plf.202.1547761582507; Thu, 17 Jan 2019 13:46:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547761582; cv=none; d=google.com; s=arc-20160816; b=NAAbvBR3khoOiRXOC+YKafjglk9QcxqztMY8UUNia1VE0vmPdhRwI94CSycZFBw9ya OQB6p4/FET2J8v0cRjCqJ7hLlASmfwd1vQ8iAvv1N4Y1okR8busaT8EVWv7CShUXEAsJ QHSMooUfzQHKE/YQ3VWHg3oIiMH6WzrdK5FxWk4NUEOZNl3XulM1p2Z9jtVr1Ly7ZdWE Qu72eZvNMm9UMXc+3DcK/WaLPkwkd0BX+BaFtPYQ2otDl9vXNKPXtu3TAjBuersF+9mw Ddk7y343eXtTpwYFcASgx+7Of2THAMwWRFmmCiGfUi9K9sLqqHu8UqiCTDMSD90HNgq7 aRnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Uif7NnSu4vC2FTPS4CEUaEq8UvXBfqUFaj2BoIL8DCM=; b=EtRiOeBlxUv/QWEGH6fadHad6R+9CkwUMCiXwdkkhJqPd+5GJyH95xQBj5/8bHha/S 1jLBiscmeuTqu8ry4bKJczmn0rSyLutE5J++GYr/NB+uNh0b59B1Zr/y0z5fXrotZcqQ uPBUWHIVm7luorCGNfzuQT8YRGZAdG1clvDZyM0Idhn6xTxPBvTvMr/AkinrXA9OO4bq wIjW9RU0kwrxFDkC3YmX8KE90dgKN7T1DLzljJZCSrLhCP1KOh8NoCl+nzjVrDA8ZOaa HbuGzzh2PKPKzHO+/rAY72DDiE2l5TfEoSzMuw261ARUW9JuR87kIUbDfkZGMv8omkZv PwyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RjgICbme; 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 97si2782755ple.389.2019.01.17.13.46.06; Thu, 17 Jan 2019 13:46:22 -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=RjgICbme; 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 S1729272AbfAQU1i (ORCPT + 99 others); Thu, 17 Jan 2019 15:27:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:51736 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729022AbfAQU1i (ORCPT ); Thu, 17 Jan 2019 15:27:38 -0500 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D07132176F for ; Thu, 17 Jan 2019 20:27:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547756857; bh=2LN0b2pEyZcmNHx/q/HSwUHJ+OFapnXo/7ZJjzZgSMI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=RjgICbmexgMdczEI5OACEtqWYrFZScAk3TNsnCWB7HAFfpUE/dnYOD+L8aqyDzp/q pUtFUO04b/Vl2vnMVdXza76G1+kJ3pc0Ew2Rk0mGuspUf65uwViCECbO2YBJaY2cF+ RBjmsnXEXihbcDSpk0FhvmsWkLZrKxigmduW03e4= Received: by mail-wm1-f53.google.com with SMTP id r24so1915762wmh.0 for ; Thu, 17 Jan 2019 12:27:36 -0800 (PST) X-Gm-Message-State: AJcUukcMM5uN14PegCgD+9ntRR3RqpdsU2lKipVUXL0N9ZoW5eWKGx1L scQ3VDwDObVhUE/HPqxJ5qhVnPDsoRjrEqnQvdJUiw== X-Received: by 2002:a7b:c7c7:: with SMTP id z7mr14010272wmk.74.1547756855114; Thu, 17 Jan 2019 12:27:35 -0800 (PST) MIME-Version: 1.0 References: <20190117003259.23141-1-rick.p.edgecombe@intel.com> <20190117003259.23141-7-rick.p.edgecombe@intel.com> In-Reply-To: <20190117003259.23141-7-rick.p.edgecombe@intel.com> From: Andy Lutomirski Date: Thu, 17 Jan 2019 12:27:23 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 06/17] x86/alternative: use temporary mm for text poking To: Rick Edgecombe Cc: Andy Lutomirski , Ingo Molnar , LKML , X86 ML , "H. Peter Anvin" , Thomas Gleixner , Borislav Petkov , Nadav Amit , Dave Hansen , Peter Zijlstra , linux_dti@icloud.com, linux-integrity , LSM List , Andrew Morton , Kernel Hardening , Linux-MM , Will Deacon , Ard Biesheuvel , Kristen Carlson Accardi , "Dock, Deneen T" , Nadav Amit , Kees Cook , Dave Hansen , Masami Hiramatsu Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 16, 2019 at 4:33 PM Rick Edgecombe wrote: > > From: Nadav Amit > > text_poke() can potentially compromise the security as it sets temporary > PTEs in the fixmap. These PTEs might be used to rewrite the kernel code > from other cores accidentally or maliciously, if an attacker gains the > ability to write onto kernel memory. i think this may be sufficient, but barely. > + pte_clear(poking_mm, poking_addr, ptep); > + > + /* > + * __flush_tlb_one_user() performs a redundant TLB flush when PTI is on, > + * as it also flushes the corresponding "user" address spaces, which > + * does not exist. > + * > + * Poking, however, is already very inefficient since it does not try to > + * batch updates, so we ignore this problem for the time being. > + * > + * Since the PTEs do not exist in other kernel address-spaces, we do > + * not use __flush_tlb_one_kernel(), which when PTI is on would cause > + * more unwarranted TLB flushes. > + * > + * There is a slight anomaly here: the PTE is a supervisor-only and > + * (potentially) global and we use __flush_tlb_one_user() but this > + * should be fine. > + */ > + __flush_tlb_one_user(poking_addr); > + if (cross_page_boundary) { > + pte_clear(poking_mm, poking_addr + PAGE_SIZE, ptep + 1); > + __flush_tlb_one_user(poking_addr + PAGE_SIZE); > + } In principle, another CPU could still have the old translation. Your mutex probably makes this impossible, but it makes me nervous. Ideally you'd use flush_tlb_mm_range(), but I guess you can't do that with IRQs off. Hmm. I think you should add an inc_mm_tlb_gen() here. Arguably, if you did that, you could omit the flushes, but maybe that's silly. If we start getting new users of use_temporary_mm(), we should give some serious thought to the SMP semantics. Also, you're using PAGE_KERNEL. Please tell me that the global bit isn't set in there. --Andy