Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp250539imu; Fri, 25 Jan 2019 01:31:25 -0800 (PST) X-Google-Smtp-Source: ALg8bN4551MqaUAauKJxsDqxE+vhWBKlJ6z/uJTMl9ot+pUroBe31vhBPflFvoTGSScfT5KALwDR X-Received: by 2002:a63:7a09:: with SMTP id v9mr9362840pgc.112.1548408685763; Fri, 25 Jan 2019 01:31:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548408685; cv=none; d=google.com; s=arc-20160816; b=gjbqKO+GjSIcpWo3n63tNDecr6OXAlLRNeIw9fqJtlHBlBmJiHMv3Alkl0N65NF6Xc zZrZqBoU1u++RPFiX85zmp/exbjFIHKraC6fse0x2E8AIgJGRFkTyIMNlxJIQ4/lxlu0 wvt1mdd5jv8vJaInMMW7CKPlrZjqaRD2JNWPntDS1mM8h1Si/2gcKdzSoCuVHCkSze4m IXgs1jhue6ifg9EFx6pCwdlW13r0k8sHuS89juYnOOckOcWAk2hCZG9KxotvGfjz8JYf 7BjxNkvLxC+k+Ks+mmzEfeIETAH4+e0op5B82JD1QRxBczqoLBt1T+MA1wUs9d609qxA r0gA== 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=l8/CFgutwOvxgqngQLTy4YuEb5ebbbFztEea0Avs9q0=; b=JEmL7at/LIl2oAihiUuZbJz5tFPqCjmJImoN8/v0K4rpM8vknAxLl1XrlerUIkphKV oyZytlu05v0Q/fPfskAKAnn2ObnTuR20Cluu2oco6M/QADE4Nh+AmdNDBRKGTzYgN3Wm XydSHrQ2TWExuMQTIWlinD0qp5loe7PXXNV4Y8KwBMsLbElo+GjyWXa/gUUBeByzEGIB UVE1uqGsQNr62o9x3AaQogRiU6gPTYKHuuD2et4/taEKTHigITkAFntRqzF2wudxVyDj 1mb3BrMCQP7WWe86x3TTP55aIWihmt7nw+T/sFfj7CEDGuv0x/BFDZLYudWqODLzYd8l EnlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=bUbrur6p; 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=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g83si25906484pfb.278.2019.01.25.01.31.10; Fri, 25 Jan 2019 01:31:25 -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=@alien8.de header.s=dkim header.b=bUbrur6p; 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=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728702AbfAYJbA (ORCPT + 99 others); Fri, 25 Jan 2019 04:31:00 -0500 Received: from mail.skyhub.de ([5.9.137.197]:38892 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726520AbfAYJbA (ORCPT ); Fri, 25 Jan 2019 04:31:00 -0500 Received: from zn.tnic (p200300EC2BCAC5008171EC5460E7CDAE.dip0.t-ipconnect.de [IPv6:2003:ec:2bca:c500:8171:ec54:60e7:cdae]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 3D3D11EC0229; Fri, 25 Jan 2019 10:30:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1548408658; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=l8/CFgutwOvxgqngQLTy4YuEb5ebbbFztEea0Avs9q0=; b=bUbrur6puTnchZI+GtOUgt9AOVvc+Ae5pp2AbXn3zl56ko7TQeiAMvMt82l/uiNKrzFkWU xE+Lgre99tNAQPN+kju5rRJhk7+gwDA1BVSo2SOpdZc5BqECsohuDcMTrvfJV+xcR6Z0Dt NtKvCITWDx8Hug0dQ4Tj6P0pQgnMd4Q= Date: Fri, 25 Jan 2019 10:30:52 +0100 From: Borislav Petkov To: Rick Edgecombe Cc: Andy Lutomirski , Ingo Molnar , linux-kernel@vger.kernel.org, x86@kernel.org, hpa@zytor.com, Thomas Gleixner , 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 , Kees Cook , Dave Hansen , Masami Hiramatsu Subject: Re: [PATCH 01/17] Fix "x86/alternatives: Lockdep-enforce text_mutex in text_poke*()" Message-ID: <20190125093052.GA27998@zn.tnic> References: <20190117003259.23141-1-rick.p.edgecombe@intel.com> <20190117003259.23141-2-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190117003259.23141-2-rick.p.edgecombe@intel.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 Wed, Jan 16, 2019 at 04:32:43PM -0800, Rick Edgecombe wrote: > From: Nadav Amit > > text_mutex is currently expected to be held before text_poke() is > called, but we kgdb does not take the mutex, and instead *supposedly* > ensures the lock is not taken and will not be acquired by any other core > while text_poke() is running. > > The reason for the "supposedly" comment is that it is not entirely clear > that this would be the case if gdb_do_roundup is zero. I guess that variable name is "kgdb_do_roundup" ? > This patch creates two wrapper functions, text_poke() and Avoid having "This patch" or "This commit" in the commit message. It is tautologically useless. Also, do $ git grep 'This patch' Documentation/process for more details. > text_poke_kgdb() which do or do not run the lockdep assertion > respectively. > > While we are at it, change the return code of text_poke() to something > meaningful. One day, callers might actually respect it and the existing > BUG_ON() when patching fails could be removed. For kgdb, the return > value can actually be used. > > Cc: Andy Lutomirski > Cc: Kees Cook > Cc: Dave Hansen > Cc: Masami Hiramatsu > Fixes: 9222f606506c ("x86/alternatives: Lockdep-enforce text_mutex in text_poke*()") > Suggested-by: Peter Zijlstra > Acked-by: Jiri Kosina > Signed-off-by: Nadav Amit > Signed-off-by: Rick Edgecombe > --- > arch/x86/include/asm/text-patching.h | 1 + > arch/x86/kernel/alternative.c | 52 ++++++++++++++++++++-------- > arch/x86/kernel/kgdb.c | 11 +++--- > 3 files changed, 45 insertions(+), 19 deletions(-) ... > +/** > + * text_poke_kgdb - Update instructions on a live kernel by kgdb > + * @addr: address to modify > + * @opcode: source of the copy > + * @len: length to copy > + * > + * Only atomic text poke/set should be allowed when not doing early patching. > + * It means the size must be writable atomically and the address must be aligned > + * in a way that permits an atomic write. It also makes sure we fit on a single > + * page. > + * > + * Context: should only be used by kgdb, which ensures no other core is running, > + * despite the fact it does not hold the text_mutex. > + */ > +void *text_poke_kgdb(void *addr, const void *opcode, size_t len) text_poke_unlocked() I guess. I don't think kgdb is that special that it needs its own function flavor. -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.