Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp369467imm; Wed, 29 Aug 2018 02:01:35 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaidLKCLZH6J/1d60LIThQINhlTqB44jsvWg0kd4rM2zAoz83eE12x9P4whHEjAyeytdqvF X-Received: by 2002:a62:49d5:: with SMTP id r82-v6mr5010952pfi.245.1535533295873; Wed, 29 Aug 2018 02:01:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535533295; cv=none; d=google.com; s=arc-20160816; b=HBseqLoy6L/KSlS6PQpNvJpDs6mim0IgFTAN9xgQTxx9x5YOxHMjpkFgvzaUMNNnbz PpaRQ3ZDEr63M2Pjq+tO7/0xIzSw/ElSj2LhMvl8+EAIoFrxhegrxNpaWGIx0m7TXpvp WlDGGvAbMmrfnNs7jl5owbcx4/1V7rUUMdn2JLADliEFq8PYVlTdCDia58qdlpArYjio x95Pj8GKYp35/PqcKNIyoqZ1wY6yRpjHCAW2sg2NKHCp8HIT8uVtfyqygj+2EzqTWNG8 PrEmWX0ouhwZ2Es58Ylbaa44i/b8SKDAjGj0uMJvqRnmf+cPiN/GTnl/U4ZgrSroNfBf b8zg== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=xv2F1KEhBtPl/gThgiFw9sFX398F1L7U7mZd9t/4CxA=; b=aAOFydl88jIMa8/lqmMV3290meSHLIOJHmBCl08ZXvKnqZh2hRtxfnvNheXxEAniDT e1Phm8EWV/qGkEu/IzV6YAh9jbnd+B4AFIMelq+2gSqvi10QM2dQLZA3cEwOb2NvFmAu HGZ7nB4uxI54AzI9xSuBV98gp0jKQ1issO1e+ZKAdQDJHF54vIBioCsjTgoyEYc4rugS Zcv4nQn3FPaQmrASmLQkXUirWXMKm4K3R2OvYIKf2pvb93w53ugA7QbwRnBh/5qqBBqD I0+VWq611Bw+JDAJKOa5lShOYtRRPoY0xIAJLvOlLYl49riRKhXnPl5iy8wt8tGfK5Sz fezg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Ih/1C6/U"; 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 d7-v6si3264636plo.343.2018.08.29.02.01.20; Wed, 29 Aug 2018 02:01:35 -0700 (PDT) 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="Ih/1C6/U"; 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 S1727612AbeH2Mze (ORCPT + 99 others); Wed, 29 Aug 2018 08:55:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:33474 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727133AbeH2Mze (ORCPT ); Wed, 29 Aug 2018 08:55:34 -0400 Received: from devbox (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CE6062084D; Wed, 29 Aug 2018 08:59:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1535533180; bh=/Ujqb5UvMI55/uQfFPKN1VNykja+euGwwFkie+76qag=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Ih/1C6/UlOmuR8CY7SF4J7078K2Cy8LyOTVmbWSuQ2z8DlCJbq1BvBN7wm6P3gKqc /wskV2sahT7xMtyrZtB/mRSbMdO0bThogf00j0HMv9lVKB+XLjlGJ6661FZ54X/7ci glL563Vb1N2dwxxNvujTob9YaNpzAE/uRZzGjzaw= Date: Wed, 29 Aug 2018 17:59:36 +0900 From: Masami Hiramatsu To: Nadav Amit Cc: Thomas Gleixner , , Ingo Molnar , , Arnd Bergmann , , Andy Lutomirski , Masami Hiramatsu , Kees Cook Subject: Re: [RFC PATCH 1/6] x86/alternative: assert text_mutex is taken Message-Id: <20180829175936.fb27b3bf13da819a9a971f07@kernel.org> In-Reply-To: <20180829081147.184610-2-namit@vmware.com> References: <20180829081147.184610-1-namit@vmware.com> <20180829081147.184610-2-namit@vmware.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 29 Aug 2018 01:11:42 -0700 Nadav Amit wrote: > Use lockdep to ensure that text_mutex is taken when text_poke() is > called. > > Actually it is not always taken, specifically when it is called by kgdb, > so take the lock in these cases. Can we really take a mutex in kgdb context? kgdb_arch_remove_breakpoint <- dbg_deactivate_sw_breakpoints <- kgdb_reenter_check <- kgdb_handle_exception <- __kgdb_notify <- kgdb_ll_trap <- do_int3 <- kgdb_notify <- die notifier kgdb_arch_set_breakpoint <- dbg_activate_sw_breakpoints <- kgdb_reenter_check <- kgdb_handle_exception ... Both seems called in exception context, so we can not take a mutex lock. I think kgdb needs a special path. Thanks, > > Cc: Andy Lutomirski > Cc: Masami Hiramatsu > Cc: Kees Cook > Suggested-by: Peter Zijlstra > Signed-off-by: Nadav Amit > --- > arch/x86/kernel/alternative.c | 1 + > arch/x86/kernel/kgdb.c | 9 +++++++++ > 2 files changed, 10 insertions(+) > > diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c > index 014f214da581..916c11b410c4 100644 > --- a/arch/x86/kernel/alternative.c > +++ b/arch/x86/kernel/alternative.c > @@ -699,6 +699,7 @@ void *text_poke(void *addr, const void *opcode, size_t len) > * pages as they are not yet initialized. > */ > BUG_ON(!after_bootmem); > + lockdep_assert_held(&text_mutex); > > if (!core_kernel_text((unsigned long)addr)) { > pages[0] = vmalloc_to_page(addr); > diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c > index 8e36f249646e..60b99c76086c 100644 > --- a/arch/x86/kernel/kgdb.c > +++ b/arch/x86/kernel/kgdb.c > @@ -768,8 +768,12 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt) > */ > if (mutex_is_locked(&text_mutex)) > return -EBUSY; > + > + /* Take the mutex to avoid lockdep assertion failures. */ > + mutex_lock(&text_mutex); > text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr, > BREAK_INSTR_SIZE); > + mutex_unlock(&text_mutex); > err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE); > if (err) > return err; > @@ -793,7 +797,12 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt) > */ > if (mutex_is_locked(&text_mutex)) > goto knl_write; > + > + /* Take the mutex to avoid lockdep assertion failures. */ > + mutex_lock(&text_mutex); > text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE); > + mutex_unlock(&text_mutex); > + > err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE); > if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE)) > goto knl_write; > -- > 2.17.1 > -- Masami Hiramatsu