From patchwork Fri Feb 2 12:43:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 13542893 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 4304AC47DB3 for ; Fri, 2 Feb 2024 12:43:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C6696B0082; Fri, 2 Feb 2024 07:43:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 975D56B0083; Fri, 2 Feb 2024 07:43:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 83C4A6B0085; Fri, 2 Feb 2024 07:43:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 7548A6B0082 for ; Fri, 2 Feb 2024 07:43:48 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4A3C140F0C for ; Fri, 2 Feb 2024 12:43:48 +0000 (UTC) X-FDA: 81746830536.26.320FB78 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf06.hostedemail.com (Postfix) with ESMTP id BB29D18001C for ; Fri, 2 Feb 2024 12:43:46 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jr4npCf1; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf06.hostedemail.com: domain of arnd@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=arnd@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706877826; 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=HvkmCF9Ve4y0+vkDjEoodYhQmt4Q/ZwbyEH3V21ss3E=; b=D0iYA8LgP9Vr9odeDSmAdwIcZewQuqk6ALqvAkpEL/gHSaitSgLy1Loc6+4nan2t+FwyYf hE4r2vElsgWWfDt0QDo3DMlrsCHTeHbaMWtlsC1pb3vqJgXV7+hci/KqZu99rzyWeaqQW3 nZYTfhkfQObJ68CPLbh8uHIy2LWdWi8= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jr4npCf1; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf06.hostedemail.com: domain of arnd@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=arnd@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706877826; a=rsa-sha256; cv=none; b=1UjUPmjOghNNlyHdYQmqNoWcqdvHxuJtsmELEnDtp33Lwa8qGAoaqxRuo2YV37a/4+c4TY tNbSLThLDE/mf8f1N1tg4sY2rxPv+JDah/c1JP5Mwi4JWqthMTHhlYiOqnzHPr5eoNc0Aa Sq5F/js0o7uuqbZvpFr0qpWId79wTRQ= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 9AD9A62587; Fri, 2 Feb 2024 12:43:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5781C433C7; Fri, 2 Feb 2024 12:43:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706877825; bh=7w9jYsNrgzos+uYg26MrZfbM/Ib33qRnR69U9JTdFys=; h=From:To:Cc:Subject:Date:From; b=jr4npCf1yXqSmIqj7xe9gCzNMeVfBYQkr1mG5F4OiRKnJ0q/RXT19NhwuTafC8V06 TIzjMVLfly2Z2XsKL38dwsimVb41gavpiZ2ay3lasXYq+GDzhAkXpzhSklJs1PuU0n v5JANdsDULyayLchy7vWfTRDq12h9FWKHdA+6s8Nvr2CzOBOepDtghhuawgwjrzmpZ vDJoSAgpQ2gcZ5xlruILoo5vjgwHwnrz095Ex7b2f1x2/mHEqLNgVF6tT44s9fyPLb 7lY/wCGAgfauK7hEa0HJCHnCmVWGB3eOhlbYrCYAkTW7iX0hhf8RQIovbAoo/lTp51 60g8FuueDWFYw== From: Arnd Bergmann To: SeongJae Park , Andrew Morton Cc: Arnd Bergmann , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/damon/dbgfs: fix bogus string length Date: Fri, 2 Feb 2024 13:43:26 +0100 Message-Id: <20240202124339.892862-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: BB29D18001C X-Stat-Signature: k8ieuh3rdodfb146jhekd5cnm8ex78qg X-Rspam-User: X-HE-Tag: 1706877826-932136 X-HE-Meta: U2FsdGVkX188KKE2thMOJElwveN3QGRM4CLfOj95Dtc/CE3pTyTroTyi86MpnDAz49mnukQy+PpPy+LkSPO0jpXofTou1MmEKl/QAOul+ypRNVCy9UyMsHVyzQovWDcRO6zs9JmZ5FjTtydlApCkuFSvVObDIia4lVH39W3ube1wBAXogj6kIqc2kiJU2DvC2szT0FuMe+jK0r5gUlyCgqJC3VKCTANg2ZT5sylfP3ESf2RpxgEAHTZx1Z5v2l4l6fy5+ttHGe2e1JKJArsNx/xQgLU+BIA86ra+oTsIyYlIhO94vlGYs/S1lG3JtL2gzNnfwZGiFM0PfWfXh+ToyO1JVkurMlfvLwSmlKUov/ZP5zMh30PSrDRn1aWHHpDF0QR6JyJgV/1ftYE35lNDoVdRDKYHmAga0hiKenuPHS3TLsQyAPdmH13mZR+zAZJtxunpTiJpfwZVM22axy6jgyfma5Q5yTQvM+zaWVmKJX/94l5nYYaaXirxoXz+ipXEzmBRSZ6AfCQBadAGKvVoOGS/YbVLLZ0zY7ZS+ZPxMiBhL6j1WxIX6LAEKDQjJG79gusmchYFxqlLG2S64qp/LSepeULhKjJYUzvmtIECsMSegHGcv0M/R4A96Fitqym57+ByFtKMaKOLUyI1ne2Hf6Yjqc9WW/J8DKvLJ26QlKWLg2V01DyhxuBD9jL4SU76NCgXFPi9RhGECueRvwwNLcLe2MZbPmDc1YzmHZhWtlSuABNbRt3A+FetxSb0uOroX+zGNf/e38RdeKeLiGW1vfA4ynAETV1WrG+ksBnHa2izUMkkr15GY0o0jHy+2gEuzXDcPvMMx79fYp0ZOUDZnFBjgTfoYr+QQfLUfE5aZ7GQ8scclbqY08jCA/EpJaK4CriKoxYdyLVbXdJoRa9mDBiTADfHMDPQAaZJkN3LrtowvTlsjrBUcqfIQPFLR38rRqnVjM5pMh9+VwfojIy QZFC3F4b Lq7oz/8l7TPEReJ2khz1X5p5w1EYslewKN/NR89PyYZ/0+DodSMY1X3N/37Hbi8oQTqYZldN9VX6sRvhDcNnvyfNCwuXyl4fHxP7DkvVH4Zs9FgICsW+DM7Fc8Nq+LUysq8C24geeEcW28shCbnNZ36mSUXLqYqfKM8/txoHISRbMBhA= 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: List-Subscribe: List-Unsubscribe: From: Arnd Bergmann gcc correctly points out that using strnlen() on a fixed size array is nonsense with an overlong limit: mm/damon/dbgfs.c: In function 'damon_dbgfs_deprecated_read': mm/damon/dbgfs.c:814:19: error: 'strnlen' specified bound 1024 exceeds source size 512 [-Werror=stringop-overread] 814 | int len = strnlen(kbuf, 1024); | ^~~~~~~~~~~~~~~~~~~ mm/damon/dbgfs.c:813:14: note: source object allocated here 813 | char kbuf[512] = DAMON_DBGFS_DEPRECATION_NOTICE; | ^~~~ In fact, neither of the arbitrary limits are needed here: The first one can just be a static const string and avoid wasting any more space then necessary, and the strnlen() can be either strlen() or sizeof(kbuf)-1, both of which the compiler turns into the same constant here. Fixes: adf9047adfff ("mm/damon/dbgfs: implement deprecation notice file") Signed-off-by: Arnd Bergmann Reviewed-by: SeongJae Park --- mm/damon/dbgfs.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c index f7abbc0633aa..4a189eb65d14 100644 --- a/mm/damon/dbgfs.c +++ b/mm/damon/dbgfs.c @@ -810,10 +810,9 @@ static void dbgfs_destroy_ctx(struct damon_ctx *ctx) static ssize_t damon_dbgfs_deprecated_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { - char kbuf[512] = DAMON_DBGFS_DEPRECATION_NOTICE; - int len = strnlen(kbuf, 1024); + static const char kbuf[] = DAMON_DBGFS_DEPRECATION_NOTICE; - return simple_read_from_buffer(buf, count, ppos, kbuf, len); + return simple_read_from_buffer(buf, count, ppos, kbuf, strlen(kbuf)); } /*