From patchwork Fri Jun 5 13:21:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 187509 Delivered-To: patches@linaro.org Received: by 2002:a92:cf06:0:0:0:0:0 with SMTP id c6csp2377984ilo; Fri, 5 Jun 2020 06:22:26 -0700 (PDT) X-Received: by 2002:a1c:7717:: with SMTP id t23mr2680092wmi.175.1591363346270; Fri, 05 Jun 2020 06:22:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591363346; cv=none; d=google.com; s=arc-20160816; b=pSIvmBPDm5vW5xT/Pdu81jlf1qXjCW8eg8E3s549xQNOIYs9Cj9fU2ecqanO0kqT9a OZPeqjqZLLeGgRfrQ9ukv+KgOgisP0Xl+O/Nd2yKluPYLYuiWgATpz0tNKQZm6id4BSv ipQJ9sXiatYsK977Bj0lqlIRh+Z9OCdLHGt5AzCUdMz+SD4MXHEgAVW+9QSqcDkLFEfB 2Cj3/6boIKCHu8kWy5paEDVl/fcSqB2h0mNYzijVIJivxZXlpYHGFE0rijmA29IO2R5h JwKFEaVQTUHb5WNjcZY7G7Ko8JRK33gE7O3nuGzA9ZY+6Ghmp/phFMSMq8ji7e487F2Z Pwig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=B90P5vlRjcmc/HwmlTNh5ez1pbs9ga7qbMLqz94WeAc=; b=E3vXJVSWgXezZEfT0JUQ05zH6PmL8nagXNK4/qwVuYqggQU/PvWcXa2HS8IqxC0ffW 5UF9x86C9ih99gez3VVTOeA3z+GmXfQjwxiX7TNSkJb4zC3OMIS7FFehFVOfwcMc9Q+U kR/+7M3c8Jh0MCboYAjoScAlwHgJhKv1vzc7tGYe0ztFkjEkTavtPUcJUytwlusWKZJx QXfX47Ke7l2O2PWJVB95UDB8DxWz1PpXkX2NDGuCNnc/IUClj1tGjId/o3nUCeWCKx7u VKjKSvVOkFYWLwolp0LMx1PpZzkOtq92ChRXSEAQaaCXbX58lzRpp73gAplRQiE8uMhn MIKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YTkZfuza; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id h25sor5436893wml.4.2020.06.05.06.22.26 for (Google Transport Security); Fri, 05 Jun 2020 06:22:26 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YTkZfuza; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=B90P5vlRjcmc/HwmlTNh5ez1pbs9ga7qbMLqz94WeAc=; b=YTkZfuzam21k+uBt0acIuHPSgWol4t9gl77sHHb0fCSWzBFXoGCJliwFNTqsttd+AF qtG/4YyJse4VKAOpBl7G1blPNzVVKsKoDWzWj4UXjvgAdw8JX29fx0ejWQy08+oKs5Dv WprF3Nft8aVQ16a1n1ccsooduEpWognLe1f1P8GiXz3fGs+n1sDxlY2j7pTVqemseUk0 kG/3KCz5+UlMh7EARDuudE7NV3tPDG1JBMqeRXYWUEOL5BhuPEHCfG3rWnS6tzJHeorJ 7I8gAiNYwQcv0fx+jJ28f7Z/rJlJDa7HfKq4aPIFZYnKik7nbdG4smPYqqGN7o3UF27Q jS6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=B90P5vlRjcmc/HwmlTNh5ez1pbs9ga7qbMLqz94WeAc=; b=SKjLHtOiKvi0Rb9FqUrA1s9I06PP8jm5nHtm26qRaGeEPtAiGgjKmbCqHsxcTslTxh 65PhdrzNtsKr5Ko/BLJRv26aF00/sNIyjTv26k+P/VHAcujnINCIvoCcZWuA5YhLILHf 84YoVNJz8eGwCW6zPzOLY1eHs/J6Kb4muk0Hn8Nl60LMSW7lqNcuhIzHA2mgvNi7pegZ CwPETPxpZtewkYdg92rwqGaeQvEiCmkj/ehNeWp+nHAtfQMjPOYbp7TmUre1dCsP893r PfiRxMF0iuAyjfcGnuvyqinWygymfpL7+KTJXJUOTmOgckBFxjLUiKU+vk7tfRHywurD eAmw== X-Gm-Message-State: AOAM53353dFNsX58fP7ZhoSb0l2RKLuXc5oIcQ8PCk15eZhLhN9YJBoY CYcGtF0EPIiraqc9SnHdpiv28dr/ X-Google-Smtp-Source: ABdhPJyIAgP4Nu6MeJ5AZk9gWIJ9ycHXjBABtQl48AzXyVO5HV3VWQMGZqu06mldUl+jLuwYIcLGMg== X-Received: by 2002:a1c:2bc2:: with SMTP id r185mr2853782wmr.49.1591363345886; Fri, 05 Jun 2020 06:22:25 -0700 (PDT) Return-Path: Received: from wychelm.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id 1sm11419211wmz.13.2020.06.05.06.22.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 06:22:25 -0700 (PDT) From: Daniel Thompson To: Jason Wessel , Douglas Anderson Cc: Daniel Thompson , Peter Zijlstra , sumit.garg@linaro.org, pmladek@suse.com, sergey.senozhatsky@gmail.com, will@kernel.org, kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [RFC PATCH 3/4] kgdb: Add NOKPROBE labels on the trap handler functions Date: Fri, 5 Jun 2020 14:21:29 +0100 Message-Id: <20200605132130.1411255-4-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200605132130.1411255-1-daniel.thompson@linaro.org> References: <20200605132130.1411255-1-daniel.thompson@linaro.org> MIME-Version: 1.0 Currently kgdb honours the kprobe blacklist but doesn't place its own trap handling code on the list. Add macros to discourage attempting to use kgdb to debug itself. These changes do not make it impossible to provoke recursive trapping since they do not cover all the calls that can be made on kgdb's entry logic. However going much further whilst we are sharing the kprobe blacklist risks reducing the capabilities of kprobe and this is a bad trade off (especially so given kgdb's users are currently conditioned to avoid recursive traps). Signed-off-by: Daniel Thompson --- kernel/debug/debug_core.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) -- 2.25.4 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c index 4a2df4509fe1..21d1d91da4bb 100644 --- a/kernel/debug/debug_core.c +++ b/kernel/debug/debug_core.c @@ -184,6 +184,7 @@ int __weak kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt) return probe_kernel_write((char *)bpt->bpt_addr, (char *)bpt->saved_instr, BREAK_INSTR_SIZE); } +NOKPROBE_SYMBOL(kgdb_arch_remove_breakpoint); int __weak kgdb_validate_break_address(unsigned long addr) { @@ -321,6 +322,7 @@ static void kgdb_flush_swbreak_addr(unsigned long addr) /* Force flush instruction cache if it was outside the mm */ flush_icache_range(addr, addr + BREAK_INSTR_SIZE); } +NOKPROBE_SYMBOL(kgdb_flush_swbreak_addr); /* * SW breakpoint management: @@ -411,6 +413,7 @@ int dbg_deactivate_sw_breakpoints(void) } return ret; } +NOKPROBE_SYMBOL(dbg_deactivate_sw_breakpoints); int dbg_remove_sw_break(unsigned long addr) { @@ -567,6 +570,7 @@ static int kgdb_reenter_check(struct kgdb_state *ks) return 1; } +NOKPROBE_SYMBOL(kgdb_reenter_check); static void dbg_touch_watchdogs(void) { @@ -801,6 +805,7 @@ static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs, return kgdb_info[cpu].ret_state; } +NOKPROBE_SYMBOL(kgdb_cpu_enter); /* * kgdb_handle_exception() - main entry point from a kernel exception @@ -845,6 +850,7 @@ kgdb_handle_exception(int evector, int signo, int ecode, struct pt_regs *regs) arch_kgdb_ops.enable_nmi(1); return ret; } +NOKPROBE_SYMBOL(kgdb_handle_exception); /* * GDB places a breakpoint at this function to know dynamically loaded objects. @@ -879,6 +885,7 @@ int kgdb_nmicallback(int cpu, void *regs) #endif return 1; } +NOKPROBE_SYMBOL(kgdb_nmicallback); int kgdb_nmicallin(int cpu, int trapnr, void *regs, int err_code, atomic_t *send_ready) @@ -904,6 +911,7 @@ int kgdb_nmicallin(int cpu, int trapnr, void *regs, int err_code, #endif return 1; } +NOKPROBE_SYMBOL(kgdb_nmicallin); static void kgdb_console_write(struct console *co, const char *s, unsigned count) @@ -1204,7 +1212,6 @@ noinline void kgdb_breakpoint(void) atomic_dec(&kgdb_setting_breakpoint); } EXPORT_SYMBOL_GPL(kgdb_breakpoint); -NOKPROBE_SYMBOL(kgdb_breakpoint); static int __init opt_kgdb_wait(char *str) {