From patchwork Thu Mar 30 13:38:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 13194188 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 AFD54C6FD1D for ; Thu, 30 Mar 2023 13:38:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E1716B0074; Thu, 30 Mar 2023 09:38:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 391DB6B007D; Thu, 30 Mar 2023 09:38:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 259136B007E; Thu, 30 Mar 2023 09:38:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 11B366B0074 for ; Thu, 30 Mar 2023 09:38:28 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DDA86801BB for ; Thu, 30 Mar 2023 13:38:27 +0000 (UTC) X-FDA: 80625669054.01.35C5E78 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by imf06.hostedemail.com (Postfix) with ESMTP id 4D98D180009 for ; Thu, 30 Mar 2023 13:38:25 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=efficios.com header.s=smtpout1 header.b=P4hVo2EZ; spf=pass (imf06.hostedemail.com: domain of mathieu.desnoyers@efficios.com designates 167.114.26.122 as permitted sender) smtp.mailfrom=mathieu.desnoyers@efficios.com; dmarc=pass (policy=none) header.from=efficios.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680183505; 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=0nUFSWTH+dq2O0oPA4e8gRkiYcTYRopJHWblcq48W2o=; b=zJgKJDxn+/1m9wW1UlZXfs3QOg/g2+nPxDL1BKNjnuIIgpi4N8IXGGJeASpktO9N4Vtn0O si0cqFNnT+5thDnVZZ3xRAVTKFU70BWExhYIjLKvkKinVEbFTAQsgynzEWiUb2+Pwx9OHw gqJdDn1+F1ywm74lu98lJ+hxDAzFOlE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=efficios.com header.s=smtpout1 header.b=P4hVo2EZ; spf=pass (imf06.hostedemail.com: domain of mathieu.desnoyers@efficios.com designates 167.114.26.122 as permitted sender) smtp.mailfrom=mathieu.desnoyers@efficios.com; dmarc=pass (policy=none) header.from=efficios.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680183505; a=rsa-sha256; cv=none; b=4BComTYQ9Foek5/RnZn1pC3gNta0YmPdM4NOIOK/svRmOZM+jfF+GozW/uIHuhobaYerDD ZzPhc37vemc8N2v7Q1uyti7TZ0dp9vGEpRx0odeYB+2qrqmFNWzYibJNIX0OUTqivjzBmy F8CrmSF3//nNklewngMwlkQCr7HsSPs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1680183504; bh=24hs/GAOgBlVSR4B3MD3Qa1OeM+tlMUGandZTll4v9o=; h=From:To:Cc:Subject:Date:From; b=P4hVo2EZZRdByxjRo59jz0QLN9PDmvFRp1opXBJvMaYkvg2EASQ9fPugdPpcXsu2g LOhcUyR2joIXhVYMOdYsHnPIav9cWlqmrlCblMZsHRbJYibESdYmYRvnaRjADKiqm5 j0zdo2Dfqi06FIVg6EH6dYNbEuAj2JMMbpnSVlA+RdMWr8f/BudEMQvMNsMMSwnwZA CPQFJNB/IBo7aYkNiOJskGnM2Vqdqdvd3IjhFyE5TRZ0pKI0KBZhKf2zlNkXwpr/3E UEb7ynurlSL8qN/y3zJcu43QACN215cPl2d/UcsZfRnBrhjoR3E7rV7enw90eVURDy ISZ5k5GBWUw0Q== Received: from localhost.localdomain (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4PnPdD01kRztMX; Thu, 30 Mar 2023 09:38:23 -0400 (EDT) From: Mathieu Desnoyers To: Andrew Morton Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Shakeel Butt , Marek Szyprowski , linux-mm@kvack.org, stable@vger.kernel.org Subject: [PATCH 1/1] mm: Fix memory leak on mm_init error handling Date: Thu, 30 Mar 2023 09:38:22 -0400 Message-Id: <20230330133822.66271-1-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: 4D98D180009 X-Stat-Signature: usx7c4un73ndunukgb8wzyzuawhs6g1u X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1680183505-192290 X-HE-Meta: U2FsdGVkX1+P9Er8+Kq3/A4Iy/XPWh+RdqCnlc8+IKUUNbmzLYrgKLWUo/UZ60Fozysv2qvyvGQu9/BeyJycCaxRcIfUJdEUgq7YezZzVIAe482AQdz/gJ559tMk7S4slnh0Q2GsDoVXwSYlVkZSVlrA0faXdaegJpvyy6ywX6OXcwT/Bok7rZBRuYeHwCIGcecEb/ufTrM3ukM9hRr5OzlWmDV8rPEJJfQgCsUIucuUz2rPdVwEHWlmg4vGbjrs8+eVijbdaG5OruZQXVXDqKjovtXli2rFpOIMPgTr5YbzfNip2oZyea9mOJGdKaYtaAFg2h/sJQKmxgqEnfYpPJ3SGrXwTidI9SlEMs84ulGbOG1d3RPJwskaDuRdHFstljrotxoKWUHKFQPXlkNpJXZGyTenW3mNZjARyZwIdgNEbXuGyIA7M1qTqkRTUICpIW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-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: commit f1a7941243c1 ("mm: convert mm's rss stats into percpu_counter") introduces a memory leak by missing a call to destroy_context() when a percpu_counter fails to allocate. Before introducing the per-cpu counter allocations, init_new_context() was the last call that could fail in mm_init(), and thus there was no need to ever invoke destroy_context() in the error paths. Adding the following percpu counter allocations adds error paths after init_new_context(), which means its associated destroy_context() needs to be called when percpu counters fail to allocate. Signed-off-by: Mathieu Desnoyers Cc: Shakeel Butt Cc: Andrew Morton Cc: Marek Szyprowski Cc: linux-mm@kvack.org Cc: stable@vger.kernel.org # 6.2 Acked-by: Shakeel Butt --- kernel/fork.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/fork.c b/kernel/fork.c index c0257cbee093..c983c4fe3090 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1171,6 +1171,7 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p, fail_pcpu: while (i > 0) percpu_counter_destroy(&mm->rss_stat[--i]); + destroy_context(mm); fail_nocontext: mm_free_pgd(mm); fail_nopgd: