Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1080787rdb; Mon, 19 Feb 2024 03:50:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW8wVbm9KtOmeylNUMnljuMoZxVRftHvOGpIdmEnmlfiYB1eaPmGfoMFCR7FuPfJSNfD0IPB6lWzkMfHkrc3hirSAWGYYJgGf+aI+Zafw== X-Google-Smtp-Source: AGHT+IEcEvOYbaRSzpT+q9UzpzSoL6TzXccq9SChhfmCvQo4F7jymb90F1xRuv0xGA7VB+HWzkRe X-Received: by 2002:a05:622a:2698:b0:42d:d502:5ad3 with SMTP id kd24-20020a05622a269800b0042dd5025ad3mr10362306qtb.1.1708343430891; Mon, 19 Feb 2024 03:50:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708343430; cv=pass; d=google.com; s=arc-20160816; b=CCDexMg/ZfIm5VVpq74m0kjc3g6BR2ShTWsfTMD+JfTCPxfMYNymSzYh0sLJcU9z3T 2hIPAcFBt/nsRqDYeHeu140MQ7hy1XrKIOVIcgWRhq29u5EMlE5gkXbOme/rrK/lrpzQ Webu8xO9KnT4c/CbHoRVKXXg+Lic/fgsSrcVT4jVBj5qS28o2g3223w3+ZLNWDx/k8m+ 7Gww07c6S3KAT7YTEHtVZZHFOFt+LPKzf9x0jO5tTDErkm8dsZPr2NXebvPPltsTArO3 JBE3eoQ8KpNLzBpnVv+lyi8Sk8HDbmhl2QaTC3LtebolFaaic2x7DW7KctjswGVHeFT1 504A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=EOXq1paE9iZRK0ts2Cgn0ZXHYV4V6B8aMK7EA9BDAG0=; fh=KZCVH6TQcgL4C14/DYuwdXC+/eKTbq8udbautTvQ0SA=; b=Q6DTlIz+8nHteYHSuRRbfIv9FVPg2L+u7j1n76y6okAwaxRO0lvPAzl+2IKLxB0sxJ 32rYdDiDbmhbkwmn18ddzOQEstJI4OfrFVonA+rAL0XBGhgshzHpCOYlpUkDyYFmFZKy RoirhAaI5cqWX7yaiCKhCwMuECkZYsjlebREWRnQJHt+pMCIMJaUYYwSc5LICa4+Dj2H ev764tx4jyig+1XuqjsMAxwUwtCOVh9ELASqZcVI52aL4kC173lbEBvwF62W5mBVegQ0 0N+oxCWr/VVkeqt66tD4Vi7YYpWWhOYX6ecjDObahj5aaJ23SXpPF/6KFcbhCu3ilOZU Vetw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-71247-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71247-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id b11-20020ac844cb000000b0042da78e93d2si5801211qto.176.2024.02.19.03.50.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 03:50:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71247-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-71247-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71247-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C92FD1C23063 for ; Mon, 19 Feb 2024 11:50:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C0F042D04B; Mon, 19 Feb 2024 11:48:53 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46A4D34CFF; Mon, 19 Feb 2024 11:48:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708343333; cv=none; b=plIHavBpDfdUik3Y5VIXI1RL1zjVQDlUFC0bUEPVptMRSnUp0v2/+TdEjaJiESCFHJ1QK/TpHboaR/OX28U2prneF1yf9yiBtWtecehkM2BALNFlzZeaQoE7fvwP252QTeWv11blvOUhicdCj9bW8rSA5/4yWLXtboKVePIJNu8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708343333; c=relaxed/simple; bh=8vfBdAUdcC5/jUyUyf3YuQWzc34sXBUJ6eDjZ3kQmws=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=auyxFxjl+cumNiLRCisM8cTxPMnR4TGnLYZQL/c/VOsyoAFO9n8WZfsmaLVTpEgkxSZtLHQshEaUt8wtlgbvZfQGEQnCj0Az5sABe5EtryzPNNQ+L/NCtTaqsj+RydR3NNwZxqoHt+JgDMXspQA9OHVLiaPTc958bcDairlX4vk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7EACBC433C7; Mon, 19 Feb 2024 11:48:51 +0000 (UTC) Date: Mon, 19 Feb 2024 11:48:48 +0000 From: Catalin Marinas To: Steven Rostedt Cc: LKML , Linux Trace Kernel , Masami Hiramatsu , Mathieu Desnoyers , Kalle Valo Subject: Re: [PATCH] tracing: Inform kmemleak of saved_cmdlines allocation Message-ID: References: <20240214102614.1a1405be@gandalf.local.home> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240214102614.1a1405be@gandalf.local.home> On Wed, Feb 14, 2024 at 10:26:14AM -0500, Steven Rostedt wrote: > From: "Steven Rostedt (Google)" > > The allocation of the struct saved_cmdlines_buffer structure changed from: > > s = kmalloc(sizeof(*s), GFP_KERNEL); > s->saved_cmdlines = kmalloc_array(TASK_COMM_LEN, val, GFP_KERNEL); > > to: > > orig_size = sizeof(*s) + val * TASK_COMM_LEN; > order = get_order(orig_size); > size = 1 << (order + PAGE_SHIFT); > page = alloc_pages(GFP_KERNEL, order); > if (!page) > return NULL; > > s = page_address(page); > memset(s, 0, sizeof(*s)); > > s->saved_cmdlines = kmalloc_array(TASK_COMM_LEN, val, GFP_KERNEL); > > Where that s->saved_cmdlines allocation looks to be a dangling allocation > to kmemleak. That's because kmemleak only keeps track of kmalloc() > allocations. For allocations that use page_alloc() directly, the kmemleak > needs to be explicitly informed about it. > > Add kmemleak_alloc() and kmemleak_free() around the page allocation so > that it doesn't give the following false positive: > > unreferenced object 0xffff8881010c8000 (size 32760): > comm "swapper", pid 0, jiffies 4294667296 > hex dump (first 32 bytes): > ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ > ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ > backtrace (crc ae6ec1b9): > [] kmemleak_alloc+0x45/0x80 > [] __kmalloc_large_node+0x10d/0x190 > [] __kmalloc+0x3b1/0x4c0 > [] allocate_cmdlines_buffer+0x113/0x230 > [] tracer_alloc_buffers.isra.0+0x124/0x460 > [] early_trace_init+0x14/0xa0 > [] start_kernel+0x12e/0x3c0 > [] x86_64_start_reservations+0x18/0x30 > [] x86_64_start_kernel+0x7b/0x80 > [] secondary_startup_64_no_verify+0x15e/0x16b > > Link: https://lore.kernel.org/linux-trace-kernel/87r0hfnr9r.fsf@kernel.org/ > > Fixes: 44dc5c41b5b1 ("tracing: Fix wasted memory in saved_cmdlines logic") > Reported-by: Kalle Valo > Signed-off-by: Steven Rostedt (Google) Reviewed-by: Catalin Marinas