From patchwork Wed Mar 15 03:44:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 13175263 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03289C61DA4 for ; Wed, 15 Mar 2023 03:45:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 78FBE6B0072; Tue, 14 Mar 2023 23:45:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 740056B0074; Tue, 14 Mar 2023 23:45:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 608F56B0075; Tue, 14 Mar 2023 23:45:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 502286B0072 for ; Tue, 14 Mar 2023 23:45:26 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1A2D240EF2 for ; Wed, 15 Mar 2023 03:45:26 +0000 (UTC) X-FDA: 80569742652.12.1BF12F2 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by imf21.hostedemail.com (Postfix) with ESMTP id 84DC21C000F for ; Wed, 15 Mar 2023 03:45:23 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=dg0Zc85b; spf=pass (imf21.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.45 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678851924; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=ufxsYZFIRnn+ldduLkLg4bGkJpmUn4VR4A6IuCdxW00=; b=bT0NukWnbmU+zD1zaE25gUqY/t0hZwP2MY48GO1KDY0qzez3F0lMxMVVn1eZlM7MHdUo1z xZrQQvNyPxmYxLn9rPHlrfJNPy8aHlKPqsaf9dQ220RreWyIWxCVHKtcolQRkuVeSpyALF StM7hnzneV8QO+3LmoSnpT+ctRkCE68= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=dg0Zc85b; spf=pass (imf21.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.45 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678851924; a=rsa-sha256; cv=none; b=25QaTCIUy5v0UH3YZYtSoxuO8xpHVsEe8EHpOTZUv2EnVi/sVX5UE6Rbt2/Fm71ReNqX28 HE13xKRQvTwdVrs3Cn7fh5CcXsj2V+MZAVxOfM5PYZ0itTm/uXR+IHRUu4wNASKt1inCF6 troeuIO+ueK/7wwJ11dY1XvFnvn44cI= Received: by mail-pj1-f45.google.com with SMTP id u3-20020a17090a450300b00239db6d7d47so528724pjg.4 for ; Tue, 14 Mar 2023 20:45:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1678851922; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ufxsYZFIRnn+ldduLkLg4bGkJpmUn4VR4A6IuCdxW00=; b=dg0Zc85b60uFcQsEyeM2HVp7VR5yCO0uH+/OtvELnMEXmhdyLWg2ruNnFhZFXdae8P ffJj8SmJ1khEYn2U/Y55FPgRSradkCKkRXpgYo+VKEvu+gL+v+Qo+8zex0hIIJmm5JYH 5GVaklNdvGCs3sJU2le+AGtIIRluUZttDQN6cKwf4c5Qong2+OwlYqbDTxv/8hKyo4ox VzbD8KXs4Q0UhAqGhCETsw5e8Xd1Fs/dJ6Re+e64Mn0eS+ZLBfCMZGWtH1WteoSpmA5S mtgehdbtBfqoZ2AQPuES5dqrIB6BYkp0I9wPOVkZkO7zy/0gepYkaBPOOdypQPLldeUo QQOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678851922; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ufxsYZFIRnn+ldduLkLg4bGkJpmUn4VR4A6IuCdxW00=; b=Vd8vsL0FDUENPaVU9zI/aRVzdlSQfe7StR9V4lkZdfP3ApRGuvajSO5ZqfazxvXt4H EEguvebHkAEICBx2InYZDIXe0DSbtyYz7xGip8ZaHiYFtEQc8w9Mlrif6Sp6uPhznCWD i0lP+nF5vmlj5kn0h1P2KsBUOqD37Q4VYEyStefi38Kg8Cy0pLmE2zh4w1/cbayHEtWw Z3eYBdH/GKmd4tQix8KTo1M4BHqrz/xx5Bvm44zyQIibi6z8B7P4wiPCoW3QP5SBW9Y7 tqzPqOTORd1kZyoasBQ4Zooh565lS2l8lBdTYTWMTdA4JkfLSZTOJPgRk14TIunVgXi5 1oJA== X-Gm-Message-State: AO0yUKWmLbE5OskohzA/XumHcJ5iRVCJvQfYDS+/2erP1u33tiviNL+p 1Fohi7k7qWFAqi8WgDiEs6bqqmVVPQ0IbIe7GvXTKA== X-Google-Smtp-Source: AK7set8NPpPy05CtArxi3hzNCU0RjupArdPbdOOSdf5EjczXQxGFxpPVHURTwlD4xAtYVBIjwNxKtg== X-Received: by 2002:a17:903:187:b0:19c:1455:d588 with SMTP id z7-20020a170903018700b0019c1455d588mr1227815plg.0.1678851922251; Tue, 14 Mar 2023 20:45:22 -0700 (PDT) Received: from PXLDJ45XCM.bytedance.net ([139.177.225.245]) by smtp.gmail.com with ESMTPSA id q23-20020a170902789700b0019f0e766809sm2436258pll.306.2023.03.14.20.45.17 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 14 Mar 2023 20:45:21 -0700 (PDT) From: Muchun Song To: glider@google.com, elver@google.com, dvyukov@google.com, akpm@linux-foundation.org, jannh@google.com, sjpark@amazon.de Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, muchun.song@linux.dev, Muchun Song Subject: [PATCH] mm: kfence: fix using kfence_metadata without initialization in show_object() Date: Wed, 15 Mar 2023 11:44:41 +0800 Message-Id: <20230315034441.44321-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 5db8i43wrxxro1e1xkdf9ndxg93ztmuw X-Rspamd-Queue-Id: 84DC21C000F X-HE-Tag: 1678851923-179539 X-HE-Meta: U2FsdGVkX1/3i96U1nd9WzzpzE9k89zRf654cZSpgDDD36d394KBDIwYnyflPBT8CaKbt0YeycyKO/IWwO3Joa8hUxKTxuDE7qMvo42zA+yKapGL1d4FwSG1lRi0y3vbVNznhCdeUtq8ocjiTNQO9mVU390/MoERAlY5fVvu7o4BPwkvnh0NikH0VZ2s4acxHN/F+xOf58iRkzjzHPrJeSFOm5hHopsaz9jBOZ2+YZ/OZIQOHQIJNcrLP3eQF2jrz5YeE6bif6D1RuWP1RtWwznyeJ32sCp448/bzSUMWrACeQyz//OliBEAVDPTb9H3TyaR4/uNZAB6WYggsULE66oxdRqw7mZmCYVX/VAOtcoMmOxJG75CDZJ8NRPnNNd8J/SfWMX+HAEpAIDVHPiLD/7ErfFn1Oz+rpUj5HxmfrPMv8kRwlYY1m4kqlvjTU6ly1sYcmOhxC/kzDacRpbtRzSnLvGe+YsMsI0fZY20MHyNrhRe8AwKiNm7RXVyO6sQDvSl8A7Ol7SXc82kh25AImjyAVv/2GaesPsfhnqee0BpC8+ScpHLtGJpLLVZVIWZAHVV7HelrylOSF++fA8QTcV/lLyPvWitbybwW4BvweTQwWGKZG12izC61V2kiR20kiclLiGy1q5BGF//AN2FHDka+SdLy6yG+/ak2ZX1Wjj2EIgjhonLKS9pzIRZesWGygu9qiH7YY0ymD7WmGFs19ul8n507hubyKPo359N4eLBlMg5Rt/wpHhU10OKYGZ1eYdbIajsiV7Paib3EVqZ5Rcusmy3gabDuZ1nrU1CAyfD4/UqE8Xq8YddwhMtzMYZmW9YKm0bd9Xsu9lwxrLoJFYrghxXz3vqeybFPpXWicSKAIXHo3qMNIege2SatE1V9TNu1ZKDjiMpzKyPA7mQrPDtRCGshFYd3ecaweUq3lw1pMR40z6d7oKi0hJASGwHR9aT8/6E1DLJwt4Xwgm RNt/lZfC 8Bto1ZKu0wvX+P6B9J677tu8CPAPiyDGq3WXNzZiU2jzbXx3zJTQRz3LdJFa2ZuVeQbS2QPuoCn7/qlgOqOt/+NqIDSx7s874HbBVfEXZWvG02Y1aYvIyTXsf9rJMTeA5f+NCAfC0vhR/y13zPP6u+mPHMqWbbaQp8sJ7vTqozdJWQYR0ormYd347P8/NMHmBnG9MqkSEjxvcjNlLm+s1rjk+8rx5l34kdM0C8uCJOjnep3lzDQLUJjAyjaIuhD2vd/U8bSHJVjAQ/XgOT2S0f5Sk+7eBJTTaV73Dh97mTAfjjztRf4qsmXjv7sUDU/opYsD7KD4xmcanTqdkylaVF+SHE8VT0+YHXQihDRWR9rbwWKU61tVFJ/QPfDA4r1yz7KckUo170souAe2T6ayQ8ZRoTZ7ljqiiGK0nXeDpBI58AkDbaeeDyCduiV5udu5Xpxl5K57g2OzbSklS53WmibWb6Q== 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: The variable kfence_metadata is initialized in kfence_init_pool(), then, it is not initialized if kfence is disabled after booting. In this case, kfence_metadata will be used (e.g. ->lock and ->state fields) without initialization when reading /sys/kernel/debug/kfence/objects. There will be a warning if you enable CONFIG_DEBUG_SPINLOCK. Fix it by creating debugfs files when necessary. Fixes: 0ce20dd84089 ("mm: add Kernel Electric-Fence infrastructure") Signed-off-by: Muchun Song Tested-by: Marco Elver Reviewed-by: Marco Elver --- mm/kfence/core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mm/kfence/core.c b/mm/kfence/core.c index 5349c37a5dac..79c94ee55f97 100644 --- a/mm/kfence/core.c +++ b/mm/kfence/core.c @@ -726,10 +726,14 @@ static const struct seq_operations objects_sops = { }; DEFINE_SEQ_ATTRIBUTE(objects); -static int __init kfence_debugfs_init(void) +static int kfence_debugfs_init(void) { - struct dentry *kfence_dir = debugfs_create_dir("kfence", NULL); + struct dentry *kfence_dir; + if (!READ_ONCE(kfence_enabled)) + return 0; + + kfence_dir = debugfs_create_dir("kfence", NULL); debugfs_create_file("stats", 0444, kfence_dir, NULL, &stats_fops); debugfs_create_file("objects", 0400, kfence_dir, NULL, &objects_fops); return 0; @@ -883,6 +887,8 @@ static int kfence_init_late(void) } kfence_init_enable(); + kfence_debugfs_init(); + return 0; }