Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp344577imm; Wed, 29 Aug 2018 01:15:13 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaXKxm970BgCb1F3TASikDs/hUoq9+AW1+MoK6OParkc51BbDKvHSmH6f+zyMz2Bt7qT8VU X-Received: by 2002:a17:902:3a5:: with SMTP id d34-v6mr4949525pld.98.1535530513117; Wed, 29 Aug 2018 01:15:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535530513; cv=none; d=google.com; s=arc-20160816; b=lyexu/f8zUoLoKxTqXoi+ho/16yDIsAG/aDG/JUj/GdPJi54Fzu/0T9zIHsktUE+L8 2YKrS/MUFG8R06iu3AkLhChaBCe7bZZZnnFUHM3UiFMllUb4AcQ3OZX6kjcw2/fldmWz b1+r9j8TH91BG/XLEyn9rm5utdLiNUhajZuNXagApKs9XC3fG2ZLVNA7NVXy+b3ZejoE Ywi5JmZovUffQUqNJkkltP++xSEgqmjckVGI2cwjWBvSoUzWkgQfdKbSdVepe9zORo7s sHNlI21l3BWi6RQE2kif2+KnPvb4WeB0qHM1VfAw/1dGvbBoHg2lEVib+1fd0s2HA1nO vfHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=Aarmm9Z9qk0BPJ0PUoF/dJMJWf6ULJHBAAcPDHyUDT0=; b=cCwknkFadfVkP6LC+2AEWCfuzbxs0QIoMhxIyPf8/5MsfZiaapJII1cfJEeEUZ1fqT toUwLblgWSYAMGiAqqiLQSGTO1HZXGXs/ekVhFPe4FzjGK1WBfaA3CMadUCeNKs759nu IeQC6j3QB1VL2I0LeCB+pRvJG7Bc33kUUmOmSG5GlPr9RNlRER9E5HpztJknYUe42YhY 8knyVHxXZjlRgE4ZnJk2fhd4ib0m2iTG+iHI2i69LZTy+fTwROJxwYNQwSD4aWMhNfkg tksJstFCDLBk5QTYJfX4Y+PaIddFPsVSJIAy2yKknyFqJr3yd6BCZ5mMNDye9Pd0Hh20 L62w== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c13-v6si3039364pfi.256.2018.08.29.01.14.57; Wed, 29 Aug 2018 01:15:13 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728021AbeH2MJJ (ORCPT + 99 others); Wed, 29 Aug 2018 08:09:09 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:43187 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727477AbeH2MJI (ORCPT ); Wed, 29 Aug 2018 08:09:08 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Wed, 29 Aug 2018 01:13:09 -0700 Received: from sc2-haas01-esx0118.eng.vmware.com (sc2-haas01-esx0118.eng.vmware.com [10.172.44.118]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 28AF740DAF; Wed, 29 Aug 2018 01:13:26 -0700 (PDT) From: Nadav Amit To: Thomas Gleixner CC: , Ingo Molnar , , Arnd Bergmann , , Nadav Amit , Andy Lutomirski , Masami Hiramatsu , Kees Cook Subject: [RFC PATCH 1/6] x86/alternative: assert text_mutex is taken Date: Wed, 29 Aug 2018 01:11:42 -0700 Message-ID: <20180829081147.184610-2-namit@vmware.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180829081147.184610-1-namit@vmware.com> References: <20180829081147.184610-1-namit@vmware.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-001.vmware.com: namit@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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