Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp222613rwb; Mon, 26 Sep 2022 11:24:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7omM796/HO7xLqVamF779GIoHWijXQkhhy15rLBlA1MqqjMavck664qInK+lw1GOdRHf9E X-Received: by 2002:a17:907:6087:b0:77a:51e9:8e86 with SMTP id ht7-20020a170907608700b0077a51e98e86mr19789195ejc.31.1664216647058; Mon, 26 Sep 2022 11:24:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664216647; cv=none; d=google.com; s=arc-20160816; b=sDNPCsQytfdTHW7Hg2MER1bUpigtk5ryX1vHPjUI7g8HCEh+WY0RfYRww2GuxQZGVx 5jl/qEBCFhe+MWOXt6x5KFiWZQCmYFsGYhwh78jrgQdHmXoy48bebj4mad1uRSM3inVt VgFpySGaBLhksorROxv81GdwnTCey/dsvqXJdLJuSypylnbhsjFhxCWnuNw8MqbtsW6D MHPy2GvvhMGXolXg/UJytgDv7ERVqV6fRLrVDcZzmtuXx/pu4ftFA/uSHjwwPbD2ksYZ Ah75fPrHy2AdU+erokn2PoHSyG5gW9m3DUO64PCiUEdXqrUpHnlTkuMttKDHqUn/IBtX jtHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=sMxovil3pwTpAtVBl8hoFUbB5bP5MdyUMFTu+GujlK0=; b=cRiEZaw7I+ZQYSuGQUUo8AaGzx49IYZ9xF9/TH3VAbFDJsIVmRiKoPGXc5YlI/lI+4 TnaX6QNq/FkqxpVuzG2yErYzP1QzAlnoiCt9b3jZbVvkjtkaOaEuJEfoX9wEURYgi8OS FXx1+16oqPg0kodDmaTIfZ6jBbQJ3okP8l/3oIYgl0LSVJ8STzOhQdOlaVMLvRHYiORw 1VoGq5LXeWvvY6cjeA6dde5MviGGJO/xM2oMy/OKF8t/SB5AWOkO9P4zBkcH0QdrLug8 zPp4AoLNGu+hhmWuqUqGcwFb2jbqJCiKYB5+BkjMrLO5ut0H9H61bTKWBKVReBS0HcJI ToUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="s/IlLIcB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jz22-20020a170906bb1600b0072b7fac8a7asi373293ejb.926.2022.09.26.11.23.20; Mon, 26 Sep 2022 11:24:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="s/IlLIcB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229801AbiIZREP (ORCPT + 99 others); Mon, 26 Sep 2022 13:04:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229704AbiIZRDw (ORCPT ); Mon, 26 Sep 2022 13:03:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3876D97B36; Mon, 26 Sep 2022 09:06:24 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 24F0C60F79; Mon, 26 Sep 2022 16:06:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04571C433D6; Mon, 26 Sep 2022 16:06:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664208383; bh=Gd8nmWWpHS7qrcrAlAsgmMmvuXxIQOEs22IHlMZZio0=; h=From:To:Cc:Subject:Date:From; b=s/IlLIcBHSG0s6pt6JTYAGSMUnpI7AP5PfNCVMo0WEdxGZ4u35p00DaHZODGbg+bn IXZllruYUf8YTOOriAdfbGEMs7hWDUB+uV7XZskgpEHw9Q48qy/yaCEGt8+D3g4dxo vthD80bb/I74L2pCC+yIUFxw9eWYi9CSwiJs1hf+28mAg6vjX40GwPf936XBrLOY6D QDrkWqGKDokWzWZ0E/k94jM9rHWP0fpb951+UMjm4F7yRZH+mw7ZAJ55RMDWypSM3A m2vDCgy2YCtVat3QouKxo4rq4eEzAROnzJXyZqA+aetpgDZy5Md2g4YvsQOpFIH8EE 5OXs0bc48M5ug== From: SeongJae Park To: akpm@linux-foundation.org Cc: ppbuk5246@gmail.com, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, SeongJae Park Subject: [PATCH v4] damon/sysfs: Fix possible memleak on damon_sysfs_add_target. Date: Mon, 26 Sep 2022 16:06:11 +0000 Message-Id: <20220926160611.48536-1-sj@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Levi Yun When damon_sysfs_add_target couldn't find proper task, New allocated damon_target structure isn't registered yet, So, it's impossible to free new allocated one by damon_sysfs_destroy_targets. By calling daemon_add_target as soon as allocating new target, Fix this possible memory leak. Fixes: a61ea561c871 ("mm/damon/sysfs: link DAMON for virtual address spaces monitoring") Cc: # 5.17.x Signed-off-by: Levi Yun Reviewed-by: SeongJae Park Signed-off-by: SeongJae Park --- Changes from v3 (https://lore.kernel.org/damon/20220925234327.26345-1-ppbuk5246@gmail.com/) - Fix Fixes: tag - Add patch changelog Changes from v2 (https://lore.kernel.org/damon/20220925234053.26090-1-ppbuk5246@gmail.com/) - Add Fixes: and Cc: stable Changes from v1 (https://lore.kernel.org/damon/20220925140257.23431-1-ppbuk5246@gmail.com/) - Do damon_add_target() earlier instead of explicitly freeing the object mm/damon/sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 455215a5c059..9f1219a67e3f 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -2172,12 +2172,12 @@ static int damon_sysfs_add_target(struct damon_sysfs_target *sys_target, if (!t) return -ENOMEM; + damon_add_target(ctx, t); if (damon_target_has_pid(ctx)) { t->pid = find_get_pid(sys_target->pid); if (!t->pid) goto destroy_targets_out; } - damon_add_target(ctx, t); err = damon_sysfs_set_regions(t, sys_target->regions); if (err) goto destroy_targets_out; -- 2.25.1