Message ID | 20240202124339.892862-1-arnd@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-49855-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp404944dyc; Fri, 2 Feb 2024 04:55:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHRriSEbx0fmKoMYN4WROcCa+S22Vz75FoPlvVYgspRUqY5IYZUAHPrJSdz5qUTIX+G7Dif X-Received: by 2002:a05:6a20:c20f:b0:19c:b3e7:ed7d with SMTP id bt15-20020a056a20c20f00b0019cb3e7ed7dmr1586793pzb.30.1706878548752; Fri, 02 Feb 2024 04:55:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706878548; cv=pass; d=google.com; s=arc-20160816; b=DbFZrrwMR+OzOUQ/VnNIwKWCiAZgRTJPrTKfYoSIumOH/YO70rhB72vxPjkJPEAuJP aygkzFYueww+PstESAwIyifLfRXSwQOdnpoRuL7WEuCzpIXkgwcWA7rW8pWTxQ6YjLad g7UmojUDQkMTeDIQe7fHeox45dwKJq1MKEit4NiLJGYywysnymXt2B7vvXALodcQuz7d cqxJlKIAqkZxP99e4/f7Q6xHgjywmK651DkPsN78Cicn2DjnbXQlfmI8hpejYropwunY rXyRu224Y5oCJHPYN9yzvuU2NovpyuZ7dY2rBILV7yKVZq9LZLYvjMRY+EmkAHvtbNbY mi1g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=HvkmCF9Ve4y0+vkDjEoodYhQmt4Q/ZwbyEH3V21ss3E=; fh=6lx/I7t+xHwac8AYxV0D/6FzKtGb025piMdeY/nSxtE=; b=D5+1O5x9T4Yq33evcgkgxNsJ5yUCaqlqtR1X4bLIMpa0xYEDpbo2CSX8GfR4Fm11E+ yil/uJeUxmMTtbcBGd9A8upPf+mH1zBfrCqc5Fwb593Mp/QEoAY76F0b0kJ9+elniwGQ MKikbP0M/HRBvXLjtREKv6A6U4iX3N7WPvUKujjV4zhD7yX/4ObKhOKONolKC2iyI7/2 d/6ocVomjxnIGZgvd2w5zEhoDcdWFvpg/eLrJYNFyk/dkQ9Ggus+PO52gz3uf2OcuH04 YwdDEedz5n4R7MHeXpHaAhgVV9jvm3LhEdC2vUdoJuVYdUnmzX9eCYplFQleRtFU1kCs BuDQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jr4npCf1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49855-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49855-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCWp6VD8IfblFrw/JdcwmyxMFZml4USXhyUKcnwfZIHmj4JEedqtuB+L7fY8tEUzZq6MPyYeP+037Lt1Y3hGMXQyXROQYg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id r10-20020a056a00216a00b006d96ab05089si1489112pff.376.2024.02.02.04.55.48 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 04:55:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49855-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jr4npCf1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49855-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49855-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 125B5296D24 for <ouuuleilei@gmail.com>; Fri, 2 Feb 2024 12:44:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B8B863D8F; Fri, 2 Feb 2024 12:43:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jr4npCf1" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7F1F45BF3; Fri, 2 Feb 2024 12:43:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706877825; cv=none; b=E9eBcgmyegkE6C0CqMzTTVgerHsasxRA5RHyQPDwt5FBm9ZUstIp+Lvl9295u+Z9SQP4fAYW7g+lwhXN/fPS+JKp18E2XIy08g0BXKJG1TClNBqy+oapzNLb1g+6gauX1+8m/jDmJ9qGAHH1ZHF3Gpa/qVQhANqlMntI/FkZIsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706877825; c=relaxed/simple; bh=7w9jYsNrgzos+uYg26MrZfbM/Ib33qRnR69U9JTdFys=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=jogWZ2GZivXDp4AIYCGb4q7A3tLjBjv8di5SJ+9NRkW5Wsu21wBcwneURW92yiHhhmOvNpyWqBFbwqkEWj8S4rd05JxykaROzLT0AlGBUpCydCKBAA9LePFkU5wtCT7mSwN9H9mDjMAKG3hVKBZasOOcgzcxDs2zOYdsYqvuibE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jr4npCf1; arc=none smtp.client-ip=10.30.226.201 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 <arnd@kernel.org> To: SeongJae Park <sj@kernel.org>, Andrew Morton <akpm@linux-foundation.org> Cc: Arnd Bergmann <arnd@arndb.de>, 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789791881255222874 X-GMAIL-MSGID: 1789791881255222874 |
Series |
mm/damon/dbgfs: fix bogus string length
|
|
Commit Message
Arnd Bergmann
Feb. 2, 2024, 12:43 p.m. UTC
From: Arnd Bergmann <arnd@arndb.de> 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 <arnd@arndb.de> --- mm/damon/dbgfs.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
Comments
Hi Arnd, On Fri, 2 Feb 2024 13:43:26 +0100 Arnd Bergmann <arnd@kernel.org> wrote: > From: Arnd Bergmann <arnd@arndb.de> > > 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. Thank you for this fix! > > Fixes: adf9047adfff ("mm/damon/dbgfs: implement deprecation notice file") > Signed-off-by: Arnd Bergmann <arnd@arndb.de> Reviewed-by: SeongJae Park <sj@kernel.org> Thanks, SJ [...]
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)); } /*