From patchwork Fri Sep 24 22:43:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12516957 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D970C433F5 for ; Fri, 24 Sep 2021 22:43:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DD76161250 for ; Fri, 24 Sep 2021 22:43:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DD76161250 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 7EBC96B0074; Fri, 24 Sep 2021 18:43:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 776716B0075; Fri, 24 Sep 2021 18:43:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 689A7900002; Fri, 24 Sep 2021 18:43:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0084.hostedemail.com [216.40.44.84]) by kanga.kvack.org (Postfix) with ESMTP id 599776B0074 for ; Fri, 24 Sep 2021 18:43:28 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 139433A2D7 for ; Fri, 24 Sep 2021 22:43:28 +0000 (UTC) X-FDA: 78623944896.13.BD04A25 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf10.hostedemail.com (Postfix) with ESMTP id C50EA600198B for ; Fri, 24 Sep 2021 22:43:27 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id CEC44610F7; Fri, 24 Sep 2021 22:43:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1632523407; bh=uWwxeLdlOGjaTzqH97Y4wiX9ndCY9tuHs3E3OZZlPkg=; h=Date:From:To:Subject:In-Reply-To:From; b=iHNHVFG5aL3D8oguHZ8B1fUBb79iBGsZr3+BjfiMYx9nGNMANynZeUFjU27jQzwD7 dxInDa3XNdpuzczMnUCcujhOHbuzWHBYU2gxhVGJ3t8yUd6zAmMsQQdeDZnutRX6zF rywYJKdF+wDy+gRe8BTmZTnVZI+ojb9ttQIpuGb8= Date: Fri, 24 Sep 2021 15:43:26 -0700 From: Andrew Morton To: akpm@linux-foundation.org, kilobyte@angband.pl, linux-mm@kvack.org, mm-commits@vger.kernel.org, sj38.park@gmail.com, torvalds@linux-foundation.org Subject: [patch 03/16] mm/damon: don't use strnlen() with known-bogus source length Message-ID: <20210924224326.LWI0zk_0G%akpm@linux-foundation.org> In-Reply-To: <20210924154257.1dbf6699ab8d88c0460f924f@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: C50EA600198B X-Stat-Signature: ta4adiqbtqwxjmkm3ubxf6ijawimxpyk Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=iHNHVFG5; spf=pass (imf10.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-HE-Tag: 1632523407-744354 X-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: From: Adam Borowski Subject: mm/damon: don't use strnlen() with known-bogus source length gcc knows the true length too, and rightfully complains. Link: https://lkml.kernel.org/r/20210912204447.10427-1-kilobyte@angband.pl Signed-off-by: Adam Borowski Cc: SeongJae Park Signed-off-by: Andrew Morton --- mm/damon/dbgfs-test.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) --- a/mm/damon/dbgfs-test.h~mm-damon-dont-use-strnlen-with-known-bogus-source-length +++ a/mm/damon/dbgfs-test.h @@ -20,27 +20,27 @@ static void damon_dbgfs_test_str_to_targ ssize_t nr_integers = 0, i; question = "123"; - answers = str_to_target_ids(question, strnlen(question, 128), + answers = str_to_target_ids(question, strlen(question), &nr_integers); KUNIT_EXPECT_EQ(test, (ssize_t)1, nr_integers); KUNIT_EXPECT_EQ(test, 123ul, answers[0]); kfree(answers); question = "123abc"; - answers = str_to_target_ids(question, strnlen(question, 128), + answers = str_to_target_ids(question, strlen(question), &nr_integers); KUNIT_EXPECT_EQ(test, (ssize_t)1, nr_integers); KUNIT_EXPECT_EQ(test, 123ul, answers[0]); kfree(answers); question = "a123"; - answers = str_to_target_ids(question, strnlen(question, 128), + answers = str_to_target_ids(question, strlen(question), &nr_integers); KUNIT_EXPECT_EQ(test, (ssize_t)0, nr_integers); kfree(answers); question = "12 35"; - answers = str_to_target_ids(question, strnlen(question, 128), + answers = str_to_target_ids(question, strlen(question), &nr_integers); KUNIT_EXPECT_EQ(test, (ssize_t)2, nr_integers); for (i = 0; i < nr_integers; i++) @@ -48,7 +48,7 @@ static void damon_dbgfs_test_str_to_targ kfree(answers); question = "12 35 46"; - answers = str_to_target_ids(question, strnlen(question, 128), + answers = str_to_target_ids(question, strlen(question), &nr_integers); KUNIT_EXPECT_EQ(test, (ssize_t)3, nr_integers); for (i = 0; i < nr_integers; i++) @@ -56,7 +56,7 @@ static void damon_dbgfs_test_str_to_targ kfree(answers); question = "12 35 abc 46"; - answers = str_to_target_ids(question, strnlen(question, 128), + answers = str_to_target_ids(question, strlen(question), &nr_integers); KUNIT_EXPECT_EQ(test, (ssize_t)2, nr_integers); for (i = 0; i < 2; i++) @@ -64,13 +64,13 @@ static void damon_dbgfs_test_str_to_targ kfree(answers); question = ""; - answers = str_to_target_ids(question, strnlen(question, 128), + answers = str_to_target_ids(question, strlen(question), &nr_integers); KUNIT_EXPECT_EQ(test, (ssize_t)0, nr_integers); kfree(answers); question = "\n"; - answers = str_to_target_ids(question, strnlen(question, 128), + answers = str_to_target_ids(question, strlen(question), &nr_integers); KUNIT_EXPECT_EQ(test, (ssize_t)0, nr_integers); kfree(answers);