From patchwork Thu Mar 4 14:40:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12116321 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEBA5C433DB for ; Thu, 4 Mar 2021 14:40:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5370564F5B for ; Thu, 4 Mar 2021 14:40:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5370564F5B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C2D686B0006; Thu, 4 Mar 2021 09:40:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BDD836B0008; Thu, 4 Mar 2021 09:40:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7DDE6B000A; Thu, 4 Mar 2021 09:40:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0134.hostedemail.com [216.40.44.134]) by kanga.kvack.org (Postfix) with ESMTP id 8C6196B0006 for ; Thu, 4 Mar 2021 09:40:05 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 3ECC08249980 for ; Thu, 4 Mar 2021 14:40:05 +0000 (UTC) X-FDA: 77882451570.29.68F4299 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf15.hostedemail.com (Postfix) with ESMTP id BA733A0009FA for ; Thu, 4 Mar 2021 14:40:04 +0000 (UTC) Received: by mail-yb1-f201.google.com with SMTP id g17so30899507ybh.4 for ; Thu, 04 Mar 2021 06:40:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=J0Eb4BeQ/LcK1uQlkM6nbhOgm0bqw0Va6B9G5XeIs/c=; b=D2kCIfqNz4T3Pf5QpozgmfIA0Gn/1MaYiwym/ex4zld+AS0SPu2SjFN3UEP9t8D9s5 USZd9TrrVq2Bid2LbDADm1dDvc2LqE81EZY1Uj5f8L8f5Dum/W7ju1DJY66yhy6KrSPp OJokL+5ZgpBBLa3igAv3TTRQpAErd+FZGKIrD4HiYID02h5xMFIz5IsL2ljaNU7172Q5 goAHFCUM9OYPoxEh0LStPmuetTUedeOqtI1/3gvY/kdQ0+dYwTWLD/nY8qhdWWWoc3uo s1gVuHyeqnpCv0l3zb7yGYff2gyoQwSwbfIcTm2LZv0nACbfqXiMSvBLV4CAD56kXBB9 NyVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=J0Eb4BeQ/LcK1uQlkM6nbhOgm0bqw0Va6B9G5XeIs/c=; b=FbhnTxCR93ZzWqr99Q3QKYBvXjddDwlXFJl1KTnMcip+2hm2UaoZTMQRJaonJNleH6 LOTvt6dhIj6eZ+P5YVvCCt2eFCOf2DeJsm8V4pKZP2p9w1Y7XX2Aumb8V5gxnr8fppyb j9Q9lc3299C+eOfSMP6YCVgiilpj+7CTXY96wGR2dlPPLJe7ImyrUOMGJSxF2cMU2cjr qHCKoqE1hbd22MyQn89eajpful0cBLFG7go2wH7FmVXHL9Sbi7NTCeNP/KR6wnSTUnaj JAkyXoPpAwLDofMtbeo8NdOj1zJnOZsJe9PcL3cdtLvznMuvG7cEjSY2lKbvwHx966yn /ZQw== X-Gm-Message-State: AOAM5333dNv9lsuhHFKaPYM3HOqV9u3YCg6DjNFFGloGu0ffh1G6W20X LQNZlOmufKD6FPyGVYhFJfW4zIcdPg== X-Google-Smtp-Source: ABdhPJxmTkNn8dSf0mXO/8nbaHc1m97dXzGttRhBDBOeceqXXFnnwoaVfWShcAw9s0n6CMOx8pbkfpKh7Q== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:e426:34b7:f237:f8d3]) (user=elver job=sendgmr) by 2002:a25:c586:: with SMTP id v128mr7118421ybe.416.1614868803915; Thu, 04 Mar 2021 06:40:03 -0800 (PST) Date: Thu, 4 Mar 2021 15:40:00 +0100 Message-Id: <20210304144000.1148590-1-elver@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH mm] kfence: fix reports if constant function prefixes exist From: Marco Elver To: elver@google.com, akpm@linux-foundation.org Cc: glider@google.com, dvyukov@google.com, andreyknvl@google.com, jannh@google.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com, Christophe Leroy X-Stat-Signature: wgagqzrswnq6bj9yxn5eacz3ye4aikr5 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: BA733A0009FA Received-SPF: none (flex--elver.bounces.google.com>: No applicable sender policy available) receiver=imf15; identity=mailfrom; envelope-from="<3Q_FAYAUKCDISZjSfUccUZS.QcaZWbil-aaYjOQY.cfU@flex--elver.bounces.google.com>"; helo=mail-yb1-f201.google.com; client-ip=209.85.219.201 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614868804-519783 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Some architectures prefix all functions with a constant string ('.' on ppc64). Add ARCH_FUNC_PREFIX, which may optionally be defined in , so that get_stack_skipnr() can work properly. Link: https://lkml.kernel.org/r/f036c53d-7e81-763c-47f4-6024c6c5f058@csgroup.eu Reported-by: Christophe Leroy Tested-by: Christophe Leroy Signed-off-by: Marco Elver --- mm/kfence/report.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mm/kfence/report.c b/mm/kfence/report.c index 519f037720f5..e3f71451ad9e 100644 --- a/mm/kfence/report.c +++ b/mm/kfence/report.c @@ -20,6 +20,11 @@ #include "kfence.h" +/* May be overridden by . */ +#ifndef ARCH_FUNC_PREFIX +#define ARCH_FUNC_PREFIX "" +#endif + extern bool no_hash_pointers; /* Helper function to either print to a seq_file or to console. */ @@ -67,8 +72,9 @@ static int get_stack_skipnr(const unsigned long stack_entries[], int num_entries for (skipnr = 0; skipnr < num_entries; skipnr++) { int len = scnprintf(buf, sizeof(buf), "%ps", (void *)stack_entries[skipnr]); - if (str_has_prefix(buf, "kfence_") || str_has_prefix(buf, "__kfence_") || - !strncmp(buf, "__slab_free", len)) { + if (str_has_prefix(buf, ARCH_FUNC_PREFIX "kfence_") || + str_has_prefix(buf, ARCH_FUNC_PREFIX "__kfence_") || + !strncmp(buf, ARCH_FUNC_PREFIX "__slab_free", len)) { /* * In case of tail calls from any of the below * to any of the above. @@ -77,10 +83,10 @@ static int get_stack_skipnr(const unsigned long stack_entries[], int num_entries } /* Also the *_bulk() variants by only checking prefixes. */ - if (str_has_prefix(buf, "kfree") || - str_has_prefix(buf, "kmem_cache_free") || - str_has_prefix(buf, "__kmalloc") || - str_has_prefix(buf, "kmem_cache_alloc")) + if (str_has_prefix(buf, ARCH_FUNC_PREFIX "kfree") || + str_has_prefix(buf, ARCH_FUNC_PREFIX "kmem_cache_free") || + str_has_prefix(buf, ARCH_FUNC_PREFIX "__kmalloc") || + str_has_prefix(buf, ARCH_FUNC_PREFIX "kmem_cache_alloc")) goto found; } if (fallback < num_entries)