From patchwork Sat Jul 29 20:37:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 128175 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp1212708vqg; Sat, 29 Jul 2023 14:09:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlHfz8kZh+X9dt4lLEdZZx2BdHXfaxbw70vDBZ3JP5e/OegpXfTTFeu0mvpnGXY3kd4XsIGL X-Received: by 2002:a05:6a20:3c8a:b0:135:110c:c6c0 with SMTP id b10-20020a056a203c8a00b00135110cc6c0mr7248753pzj.51.1690664984385; Sat, 29 Jul 2023 14:09:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690664984; cv=none; d=google.com; s=arc-20160816; b=rHva5D7ouy0grRheOUAyBMCF0maR8896EHhXTKFH7Lm9Le9LGFCDX9IFAIMtkoo/jN xLiqLyGVU22skMThrZEX+GH9LcAUFIceblJpv52ZrfDy2dhFRMTiD2+xgsEUMy21/D31 sznClDTuAaK0vwi2SMTzupnfpMj2vADmBPzfFkSmad/fnh4BWagZZMn2+qvgTDU0NQF1 cR57Wi2aQaCe2y7myoS7D+EYkSS5cM4i0KlrCbKurILTc9uBfjm32AioteyybylSB8Te oq9OSbylpp1MlRQ5mFGqVfbdjpw1mlzEjK6Uni10xFg+dVLCOZRwjplDHxrZO1V434C5 B7ZQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=m/Jq4om9ap8xtHkkQPITf3+6Fw+6C2VJ4TYwZxcfP3g=; fh=F1ufHVvjlz/m0p/dUna/lpyohajJgTo1g7WvhXO0dp8=; b=L65IiCTJCv9UhT+KTLLn3On/ZOkHcyq6QJ06q7yv+IoD60lBzw2TaXmbO5mOoxwdQh k1PdmQH+nvdIyapFCN4qJcpX4tnTBd0fR2xad0sRmkbfPOLhz2464VE4tMZyw7QnmSLT II8Da8YthHAFeZzQexI1Pi3PJyBZNRmlbuO5Ee/0TA/CVbnE6ODGQ2pTMalpyzLq2ZyM H58iuICt/hTIT6sK8tr9Osw9Ucc/BzTcDZKOdDngQjGFHQzXv6UOvT1Py/tFT6/WwkKN WH60dsoVRlF03hj+zfXRJzdmD3gLXCGswnMkK4EkotZacmvohNzoHDNSgCyzEy/7wN/V cT9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sdAWiTrM; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x185-20020a6386c2000000b005573ea250f0si1607662pgd.116.2023.07.29.14.09.21; Sat, 29 Jul 2023 14:09:44 -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=sdAWiTrM; 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 S229493AbjG2Uhm (ORCPT + 99 others); Sat, 29 Jul 2023 16:37:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjG2Uhk (ORCPT ); Sat, 29 Jul 2023 16:37:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 512B918B; Sat, 29 Jul 2023 13:37:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CF9A260765; Sat, 29 Jul 2023 20:37:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBF87C433CA; Sat, 29 Jul 2023 20:37:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690663058; bh=obtSlnvy07n5RqMkT9ft+YWwsEmXSmZYdkX6jt7/ZH0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sdAWiTrM5jLNvyEBr96k2bMsZpKhmFnONlHBuxh9ggS6iOcSUvJwgxLYzbHzBg9wS Ru1MQ8gRyCCNabq0iEEj553U3cF/LPfy0Z0RP1lLlqIranr3CxrK7kwMlydMcHIEt2 mSWUspQMNOceTsGydjYASOP5JF4GQDXRDt5LbRC1/bnb+Qf5GF270paW1Empm5JTfE pms39T+3hsMPHK1s1xJXi3Qz6XelHOE+8iQjtuS/sHfhyIDLjibfxH9NuWXDhb97Ui CwFQtevzKuW9qy+wLJDw5htGv071KBVoNdVp8kywCJ2s4wKeX4TOrviMNnxZTvwnyQ 9TIBw3B3hZQIQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, stable@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] mm/damon/core: initialize damo_filter->list from damos_new_filter() Date: Sat, 29 Jul 2023 20:37:32 +0000 Message-Id: <20230729203733.38949-2-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230729203733.38949-1-sj@kernel.org> References: <20230729203733.38949-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772790726460070838 X-GMAIL-MSGID: 1772790726460070838 damos_new_filter() is not initializing the list field of newly allocated filter object. However, DAMON sysfs interface and DAMON_RECLAIM are not initializing it after calling damos_new_filter(). As a result, accessing uninitialized memory is possible. Actually, adding multiple DAMOS filters via DAMON sysfs interface caused NULL pointer dereferencing. Initialize the field just after the allocation from damos_new_filter(). Fixes: 98def236f63c ("mm/damon/core: implement damos filter") Cc: stable@vger.kernel.org # 6.3.x- Signed-off-by: SeongJae Park --- mm/damon/core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/damon/core.c b/mm/damon/core.c index 91cff7f2997e..eb9580942a5c 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -273,6 +273,7 @@ struct damos_filter *damos_new_filter(enum damos_filter_type type, return NULL; filter->type = type; filter->matching = matching; + INIT_LIST_HEAD(&filter->list); return filter; } From patchwork Sat Jul 29 20:37:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 128177 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp1245347vqg; Sat, 29 Jul 2023 16:09:04 -0700 (PDT) X-Google-Smtp-Source: APBJJlF9sr1SaJ0JSkqJRsoxxXm4WxqjRnKsW4uoQODEoQbIR+qfnFwqRbHco21g1Pi+n7nkIYsw X-Received: by 2002:a05:6a21:3806:b0:13d:315f:26b7 with SMTP id yi6-20020a056a21380600b0013d315f26b7mr2108076pzb.1.1690672144397; Sat, 29 Jul 2023 16:09:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690672144; cv=none; d=google.com; s=arc-20160816; b=oQyLlFGSFp6VRqIOsoybhR5kVI+OxKLBVrlP/ia0Ns3RJ0nvzmqZUmZUvZO9PVs926 B7vxCHqzDEAhuspToDTIToH7OO4Y/uWwbD7mQY+XH3E3ClEfLFRBwTKMmjc+U2nGvAOT G3Nozectn/lJJ2Q/TD+6qGcrAhDcoZsTQ/Wxs9+mbdLvxdCwbJzdLTZ3bfaKwGfs9BAG b3ntWavFAEON5OD3dnKFBmLWaSL1A65YLZmR5L3DB2au3IlTeT0oPHmgbfSMITZ5Sph8 34MYhEcBQl67/b2nTVPvXXG9tcM9GCdytbwil7AsaDxl5YsETXxJdXS7PErO7Z9eJ4/e CUhQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LNXZOYVbCHsualccFqzRqzpRLiqhfT1W4JZoiRNqVK8=; fh=0gqAt1aL4tMWE9LT2ysuiUaU99Ov/zltMhb1IZiOX6M=; b=W5UoH/cbv0P1GWGCtOZKFfcpWZGSCjB6g0JFXsHSktu0+XChCDU6nv5kxFTp8EQg1j 6yxBJikMrKVQ4hHYqbSPzZn6OFF+Z5WfdKj+v2VcvRp1DniyI/KbPt9/mduMfq1IPIa0 f81L/a6YqnX8+fuZ8UkTzUh32OTSsg8v6zJ2gADJOUnkN/S3MBeoVYT9Nvo2r/2Fjyf0 Ho9p8eTuVvnura2W4iU28dOTbr0V+aJ/7iDtCYuajTwy5+NM/18xB6vQ1LAoue3l77bZ D5q+qu4QYgUr57smU7HtXlSQRVTJa6xoUg0KUYf0jf2TQcfowE1BOIZ5PzforQ/GgB0t mqjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UyYSf2rL; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t63-20020a638142000000b00563489de9e3si1378660pgd.505.2023.07.29.16.08.51; Sat, 29 Jul 2023 16:09:04 -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=UyYSf2rL; 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 S229577AbjG2Uhs (ORCPT + 99 others); Sat, 29 Jul 2023 16:37:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbjG2Uhl (ORCPT ); Sat, 29 Jul 2023 16:37:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F8F41709; Sat, 29 Jul 2023 13:37:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B206660AF3; Sat, 29 Jul 2023 20:37:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76B03C433C8; Sat, 29 Jul 2023 20:37:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690663059; bh=YPgSpddY9t4io6ikXCAUlDHPpj8ulBukto96IBJDPnc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UyYSf2rL2uLdPSrcPn4/N9GQkTxV2zBIT8nd/j+Pzf7IOWlL0PseartNH8Cn0JhVZ COd+atrvWOy+pR5Xj10r0PicBAH309HUuAWue8TI+VqsKvXlV/1j5hjW/IJwfzhjsJ wV/VG0X1OD3dUfsEC1DHpVRHoKSAsqBmBBZUq2c6b55yGCMYY7xgXL8VF9fvAcRam+ RdZEJzlrf/XHTZGqM8gvZZPBzuogVfCrwuWJPElLFGLb5X+WwtAd2KwiZfAL/lRcp3 f1eCVHWjTgJVP6BQ/P/aJT8bfaoszMfOqWxMO0UQDiVLvKEaeMfWs9vucDczB2xF5O wJb9IiQv4jIZQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Brendan Higgins , damon@lists.linux.dev, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, stable@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] mm/damon/core-test: add a test for damos_new_filter() Date: Sat, 29 Jul 2023 20:37:33 +0000 Message-Id: <20230729203733.38949-3-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230729203733.38949-1-sj@kernel.org> References: <20230729203733.38949-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772798234337152430 X-GMAIL-MSGID: 1772798234337152430 damos_new_filter() was having a bug that not initializing ->list field of the returning damos_filter struct, which results in access to uninitialized memory. Add a unit test for the function. Cc: stable@vger.kernel.org # 6.3.x- Signed-off-by: SeongJae Park --- mm/damon/core-test.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h index bb07721909e1..4bddbfe243c3 100644 --- a/mm/damon/core-test.h +++ b/mm/damon/core-test.h @@ -341,6 +341,18 @@ static void damon_test_set_attrs(struct kunit *test) KUNIT_EXPECT_EQ(test, damon_set_attrs(c, &invalid_attrs), -EINVAL); } +static void damos_test_new_filter(struct kunit *test) +{ + struct damos_filter *filter; + + filter = damos_new_filter(DAMOS_FILTER_TYPE_ANON, true); + KUNIT_EXPECT_EQ(test, filter->type, DAMOS_FILTER_TYPE_ANON); + KUNIT_EXPECT_EQ(test, filter->matching, true); + KUNIT_EXPECT_PTR_EQ(test, filter->list.prev, &filter->list); + KUNIT_EXPECT_PTR_EQ(test, filter->list.next, &filter->list); + damos_destroy_filter(filter); +} + static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_target), KUNIT_CASE(damon_test_regions), @@ -353,6 +365,7 @@ static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_set_regions), KUNIT_CASE(damon_test_update_monitoring_result), KUNIT_CASE(damon_test_set_attrs), + KUNIT_CASE(damos_test_new_filter), {}, };