Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1844603imm; Thu, 20 Sep 2018 03:57:24 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdbm9jgW0P35YuWXw0mF+n9K4CiEWevox3D5uWcH/uXqjzoKxAN3P3zcHQnKdhyp477YdKUI X-Received: by 2002:a63:8dc1:: with SMTP id z184-v6mr4140858pgd.328.1537441044463; Thu, 20 Sep 2018 03:57:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537441044; cv=none; d=google.com; s=arc-20160816; b=SHtVEshIqQyYT4RYWRFokqbT8OpFRwRkjZtZFdvvW1Vz/ka4nE1EzyXZ/axPadBtF/ Ft1f+deKt9pUWnKW4vtA+BVVkdQRBqxKAQVynYAXYVjmwxLwYwuYNSxMvFyU9OHYetsM mJxrNhkTpf7GmCkiiKCuFp49JqcebmWQ1Oa+68d65B5N/ZapB1lngDgVvDfghZXi20lU kBBmglyebl/ueXB0UvKSHNByOoVMk5y2S3k5Fj7J/Tg1QlHJqFlyKcOffUKK2mNb4AsJ j0Mqu6Cb4OTICZcePcBrdipdT5cImpWpu7oNPNOa8FeGgci75FzvaoJyDgDOMN+/i6dn JLdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=hYMeEJ1mYS5w9VXVieRfI6JukzrJSr09XclRJKwYHzI=; b=wGDSsIlfx8bqfA0qnvlSs+p5CGJzidRrsov7ei6ITOXr2LSDnuspT/N0P9ejoR1HzF +8kpIgkzHs1qrLmyZ6LkyleGLv/9SUkbcJp7ewAhh/4VyGcEwfV5Tywm28l9z8usPzOY myMwhrw4HN2qOMUtzY44eQdCWT4dwK2SCE9YNYT/od0KGgQ/oUut6LE1U/m9wVD13iKQ VHoDLjG0D4TI+azlXA6JkMcR77Ec0nlM4YODDfXVK0o67436tLJ1vYNjw73bPEpuJHiZ vZ/zgwCMjLFdh+45tGAq8olhzfp5LCEUIvOzSrzefivFtIk2ytTy6hUyWhvhtP5I/z/q Jc6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=AB3oeSuD; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3-v6si24150397pll.509.2018.09.20.03.57.08; Thu, 20 Sep 2018 03:57:24 -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=@rasmusvillemoes.dk header.s=google header.b=AB3oeSuD; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732238AbeITQjy (ORCPT + 99 others); Thu, 20 Sep 2018 12:39:54 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:33829 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726954AbeITQjy (ORCPT ); Thu, 20 Sep 2018 12:39:54 -0400 Received: by mail-lj1-f196.google.com with SMTP id f8-v6so7960433ljk.1 for ; Thu, 20 Sep 2018 03:56:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hYMeEJ1mYS5w9VXVieRfI6JukzrJSr09XclRJKwYHzI=; b=AB3oeSuDtW5PNFd34tPPMvm/x1z4LHIU1y83yZK3cSf+tz4iVY7DhlRDUxDIqeVna+ lUSdnlbnVQ3HYEUwvtIzS5ELQjsUVB/w5b08/kafWz01I5aN1gfSnbNSx/KQPGTj4TJO 0iAgAGThtSWPPbapV0HYs1DMFAbxvyZALtwFA= 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; bh=hYMeEJ1mYS5w9VXVieRfI6JukzrJSr09XclRJKwYHzI=; b=k5N5ttv60wX4BMavxTVE2iFaM0xiSP6xxUuRJf6OYhh4JWPb83EWlynFVdrDRcV0wB wtgnvJ/QLJDnZ/delIZQqEQ+RFZKXMWVVHR9s5DkoLYz9DMyN4R22PLJJPTHKalxIwPU MGRG6rbmdO+LtVXa0ldnCoZJAXcHzxB906f+UqSE4t85aRxc3JeZB6svfw72Gl9XYhpH wAgKIsiACwtMo4xSD0GN+QzNtS8BBU4zbMA4bWWpa//EVMh+Wj3porlnZy66zQDHUwCG PmYaSWE2CF/SyFYK9iiavDZ2o24KZ58J6NwoC2j50bEdlOJ7dVS6T76xTNCZZiO3SIlT WpoA== X-Gm-Message-State: APzg51AwO1JwpjmiLmR0jsl3YLaXS8hFyDvGcP9zQXbS745l/APwkbF5 E2bOtpo9JDG8rHgn0rsCE/CWPhzBpi3MP3PN X-Received: by 2002:a2e:1248:: with SMTP id t69-v6mr24183525lje.129.1537441017913; Thu, 20 Sep 2018 03:56:57 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id o67-v6sm1582025lff.36.2018.09.20.03.56.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Sep 2018 03:56:57 -0700 (PDT) From: Rasmus Villemoes To: Jason Baron , Andrew Morton Cc: linux-kernel@vger.kernel.org, Rasmus Villemoes , x86@kernel.org Subject: [PATCH 23/22] x86: dynamic_debug: protect against dynamic debug identifier reuse Date: Thu, 20 Sep 2018 12:56:53 +0200 Message-Id: <20180920105653.10964-1-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180919220444.23190-23-linux@rasmusvillemoes.dk> References: <20180919220444.23190-23-linux@rasmusvillemoes.dk> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Most invocations of DEFINE_DYNAMIC_DEBUG_METADATA happen through "public" macros such as pr_debug or netdev_dbg, which have been updated to ensure they pass a unique identifier to use as the name for the struct _ddebug instance. But it is still possible that someone invokes DEFINE_DYNAMIC_DEBUG_METADATA directly, or creates a new wrapper macro that does not do the extra-level-of-macros-passing-on-a__UNIQUE_ID dance. On x86-64, all subsequent uses of that same identifier would silently reuse the first instance, which is bad. But we can catch such cases by defining a guard symbol that is unique per expansion of DEFINE_DYNAMIC_DEBUG_METADATA. This still allows gcc to emit multiple copies of some static inline function that has a pr_debug call (because all such copies would pass the same value of %5 to the assembler), but prevents repeated naked DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, "bla") - even with a helpful error message saying that '"descriptor" used as _ddebug identifer more than once'. Cc: x86@kernel.org Signed-off-by: Rasmus Villemoes --- Just in case it wasn't already ugly enough ;) arch/x86/include/asm/dynamic_debug.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/dynamic_debug.h b/arch/x86/include/asm/dynamic_debug.h index 350ef6e2feff..69167f40482c 100644 --- a/arch/x86/include/asm/dynamic_debug.h +++ b/arch/x86/include/asm/dynamic_debug.h @@ -26,10 +26,15 @@ "\t.long 0 \t# \n" \ _DPRINTK_ASM_KEY_INIT \ ".popsection\n" \ + ".set "__stringify(name)".ddebug.once, %c5\n" \ + ".elseif "__stringify(name)".ddebug.once - %c5\n" \ + ".line "__stringify(__LINE__) " - 1\n" \ + ".error \"'"__stringify(name)"' used as _ddebug identifier more than once\"\n" \ ".endif\n" \ : : "i" (KBUILD_MODNAME), "i" (__func__), \ "i" (__FILE__), "i" (fmt), \ - "i" (_DPRINTK_FLAGS_LINENO_INIT)) + "i" (_DPRINTK_FLAGS_LINENO_INIT), \ + "i" (__COUNTER__)) #endif /* _ASM_X86_DYNAMIC_DEBUG_H */ -- 2.16.4