From patchwork Sun Dec 26 22:20:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 529285 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B778C433F5 for ; Sun, 26 Dec 2021 22:20:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234716AbhLZWUQ (ORCPT ); Sun, 26 Dec 2021 17:20:16 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:52130 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234705AbhLZWUQ (ORCPT ); Sun, 26 Dec 2021 17:20:16 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id F241AB80DE2; Sun, 26 Dec 2021 22:20:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3098C36AE8; Sun, 26 Dec 2021 22:20:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1640557213; bh=wAro1RTIpVx3ZtlJEAmaOTx+QMCzboCfkAntAiFvs/g=; h=Date:From:To:Subject:From; b=nd81tpK7uKNdgtx0eDICplABBG3GxhuxuRLB2aWOZKvhFlN3ndsjmEvhTCfQiK/Qs +d3kGwVtxDqwUb4z91RpejVH/h1Vy4qlyKbY4XKrPHHzUrBLrmXYMpwAcuzSnRncts DPtGSBcLTiyP4lMrxxZbr9AIkanNVvrNDQLjWXLM= Date: Sun, 26 Dec 2021 14:20:13 -0800 From: akpm@linux-foundation.org To: mm-commits@vger.kernel.org, sangwoob@amazon.com, sj@kernel.org, stable@vger.kernel.org Subject: [merged] mm-damon-dbgfs-protect-targets-destructions-with-kdamond_lock.patch removed from -mm tree Message-ID: <20211226222013.04LcQPcL1%akpm@linux-foundation.org> User-Agent: s-nail v14.8.16 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The patch titled Subject: mm/damon/dbgfs: protect targets destructions with kdamond_lock has been removed from the -mm tree. Its filename was mm-damon-dbgfs-protect-targets-destructions-with-kdamond_lock.patch This patch was dropped because it was merged into mainline or a subsystem tree ------------------------------------------------------ From: SeongJae Park Subject: mm/damon/dbgfs: protect targets destructions with kdamond_lock DAMON debugfs interface iterates current monitoring targets in 'dbgfs_target_ids_read()' while holding the corresponding 'kdamond_lock'. However, it also destructs the monitoring targets in 'dbgfs_before_terminate()' without holding the lock. This can result in a use_after_free bug. This commit avoids the race by protecting the destruction with the corresponding 'kdamond_lock'. Link: https://lkml.kernel.org/r/20211221094447.2241-1-sj@kernel.org Reported-by: Sangwoo Bae Fixes: 4bc05954d007 ("mm/damon: implement a debugfs-based user space interface") Signed-off-by: SeongJae Park Cc: [5.15.x] Signed-off-by: Andrew Morton --- mm/damon/dbgfs.c | 2 ++ 1 file changed, 2 insertions(+) --- a/mm/damon/dbgfs.c~mm-damon-dbgfs-protect-targets-destructions-with-kdamond_lock +++ a/mm/damon/dbgfs.c @@ -650,10 +650,12 @@ static void dbgfs_before_terminate(struc if (!targetid_is_pid(ctx)) return; + mutex_lock(&ctx->kdamond_lock); damon_for_each_target_safe(t, next, ctx) { put_pid((struct pid *)t->id); damon_destroy_target(t); } + mutex_unlock(&ctx->kdamond_lock); } static struct damon_ctx *dbgfs_new_ctx(void)