From nobody Wed Jun 17 02:50:49 2026 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DE6337DE84 for ; Tue, 21 Apr 2026 20:21:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776802875; cv=none; b=m0LxcamGwjX9SPPWfD0SBxTktiI6Ws7xUaMdiMnU5pOoDXp1FVd7vE5fQiIKvHN9Y0RapqUoiN/R56kcLMJhRw3ULPPMH3aiZHirBauMN8q5m8FcUHyBLqkIgBMieE+CMxR5xBdU51DrjjSN07KT+JzQ27XfcRyTjKpc7K2eID0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776802875; c=relaxed/simple; bh=FrzKb4y7YlHGJ2vtwJTQmyz/+8z4+4LU13jOEu0AUzY=; h=From:Date:Message-ID:Subject:To:Cc; b=p5+fWz9pm8nfEGAxp6Ps/0ioLCruoQahF0bKlkwu9R0WA+HT567lvuZAUPSsvK0p9oEsp4RJHhMq5g+XXufTeot8F7EKex2EBHn34xAtHQ/sojNPLToaxZZFLmS2MG2Ls7IboyIJufDcAP3qe+pMK044Wr3RTYQVddyzPgu8ipc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IuIKlA6T; arc=none smtp.client-ip=209.85.215.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IuIKlA6T" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-c70ea5e9e9dso1933947a12.1 for ; Tue, 21 Apr 2026 13:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776802874; x=1777407674; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:from:to:cc:subject:date :message-id:reply-to; bh=vnNcXGDfADai12uq75QgwEjPYzbA2COi4ToRCDNpa2g=; b=IuIKlA6TZqi/5DrpucisWcQAejwsgzb+v/k3UT1qd41D+3rxu73W/ivC65iW7Lpomn X5Hqst2nulgZw+fC77k7MHD5bj+Khub+YxsMYsN5GI3h2lUgJbJaUt4uba3+Hu4+PRZm sUNw6Coi22KPymNLCdOcmzrdm8ur7Lhty1me5MZnJHF6GnMJ23JhugdTBAA3kRMZOUZB NdyxhGuA943BhuUJ5kZd8j6IpDCAk7ZT3PQ9PEl31zNssgG1azQI8EJfhKcCtIJFgSTe JZjz7dvFrW2mhXo6Gg88qsts2zj4gKhRklK8GHBnIGiD+5opjkUAP7p9zyjaEIxqRpYg JfPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776802874; x=1777407674; h=cc:to:subject:message-id:date:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=vnNcXGDfADai12uq75QgwEjPYzbA2COi4ToRCDNpa2g=; b=ZWI3V24sRimqK22WcCq+xURlU1tOv4+21uTbWY4XcVJ2xFsGg9Qcbj5JieE6fZRLdQ 4I7kbntSSybRpLU/CiVs7D3mU524QsUioZUtsRGOGO1KLEvxPDiWgPyaZKFg/tEkW3M3 B29K7Dz7la48/KvWvdYjHkqm9GuvEi05bcqJULolNFjn4wJMM1XeF5nIY5SIIkgcJY3Y rYdSPzevBsdICDnf1UKJZTOXgHWgUU8Tkk0hMVxTx/TtJlGOFJq6xxRMutRQH8TfnIO8 pWr097yPf8aaGZqbmHIVF1kKoizdPCK80M4zqazt1LK8Tduy+b3dp7LyZXJX3pE3f1Bg lGhQ== X-Forwarded-Encrypted: i=1; AFNElJ/W0gbWXItUIBSvjsGMtnEI2iLr/wgfaCikSz/n8IVgzTvFD6+mWpri5d2lRAXOy3ElpZKTVqUy0V7Zo3A=@vger.kernel.org X-Gm-Message-State: AOJu0YwAd95tdgrjuC23zxoWTtmrkp1OvBMNiKD1JFNQvolUEKPa41yp nozBA68r+0AYArMzUpg2wjwwtfcOX9zpxsTQYmBuaSj4LfpjhN6L6O75 X-Gm-Gg: AeBDieuPLqqulgTt7LE0h9Sn8ZRErkQr36+AlHhviLCMJH4oBnEHtMyck/HLmkUu8Bd TShDuey5MPJ8ms64mAvSfz8tCD5RKh8KeCIzLArOSDXIwVUgEBqTzpenVLq5Oou8c9e4c1LAOX1 JnUjyEwU3ufs8t0C3Ovqr3ElxoGINzQA2rGOx8f7OdStQgWQoc6BBlqJFxKRm6Kw5D9f+uoIqqt 2gvyEMQWliSfOiyGJN457uDnNMJLawPXVCerKaPx7thO8YU+uIsP8MhSOkUbynAvyu6ggzOOjIz Re+n7HBMZP+fWB30IFXzxZPceWc4cxIQqLJ9nUVadnTibUK28xB/iL2HD9VMyUYXoUI+JJermgq Z/oMFik7HnOOpTu/r6wRLSAYxZqfT4iFTUhcvhbLzDp+lYu+ZOdNCIIkP5tr4uiZ0Vj4ANhEqut yZfvTObxk1374KJKhIsYOZ6/fPCt31hK43+3aj8jo9Wf1djr+OcW7eNvCuRBM+2Es+SzXYn1ZbF j+3O0vN4TdNq1Q4jCoKT9itUpatRHc7UaZRaIf4bA7vskpivOJTMiRuydNl6Qt7kX8JInWm7aO9 OuWMELJoN0c4ioa6JxU= X-Received: by 2002:a17:902:8e85:b0:2b4:6d92:b002 with SMTP id d9443c01a7336-2b5fa030fa5mr128011345ad.37.1776802873498; Tue, 21 Apr 2026 13:21:13 -0700 (PDT) Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa ([103.129.135.36]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b5fab0cddfsm206356875ad.49.2026.04.21.13.21.10 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Apr 2026 13:21:13 -0700 (PDT) From: Shuvam Pandey Date: Wed, 22 Apr 2026 02:04:06 +0545 Message-ID: <177680283372.84187.11707577520741615468@gmail.com> Subject: [PATCH] lib/tests: add string_get_size() boundary tests To: Kees Cook , Andy Shevchenko Cc: James Bottomley , Andrew Morton , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" string_get_size() has several non-obvious outputs around decimal and binary unit boundaries because the unit is chosen before the final rounding step. Decimal values just below 1 MB can print as "1000 kB"; binary values below 1 KiB stay in bytes; and rounded binary values can print as "1000 KiB" or "1024 KiB" before the input reaches the next binary unit. Add KUnit coverage for these current outputs and nearby threshold values so the existing behavior is explicit. Link: https://lore.kernel.org/r/CAHp75VfB0Y7K=3Dchk5wpKtZcgVfCN5X7zhNEq6QSr= irdgHs5_bQ@mail.gmail.com Link: https://lore.kernel.org/r/696d25567aadbb8ba324d4a980c15eb5cf4ccef6.ca= mel@HansenPartnership.com Signed-off-by: Shuvam Pandey Reviewed-by: Andy Shevchenko Reviewed-by: Josh Law Tested-by: Josh Law --- lib/tests/string_helpers_kunit.c | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/tests/string_helpers_kunit.c b/lib/tests/string_helpers_ku= nit.c index c853046183d24..92454837f3ddd 100644 --- a/lib/tests/string_helpers_kunit.c +++ b/lib/tests/string_helpers_kunit.c @@ -558,6 +558,39 @@ static void test_get_size(struct kunit *test) /* weird block sizes */ test_string_get_size_one(3000, 1900, "5.70 MB", "5.44 MiB"); =20 + /* decimal boundary around 1 MB */ + test_string_get_size_one(999499, 1, "999 kB", "976 KiB"); + test_string_get_size_one(999500, 1, "1000 kB", "976 KiB"); + test_string_get_size_one(999999, 1, "1000 kB", "977 KiB"); + test_string_get_size_one(1000000, 1, "1.00 MB", "977 KiB"); + test_string_get_size_one(1000001, 1, "1.00 MB", "977 KiB"); + + /* binary values stay in bytes until the 1 KiB boundary */ + test_string_get_size_one(1000, 1, "1.00 kB", "1000 B"); + test_string_get_size_one(1018, 1, "1.02 kB", "1018 B"); + test_string_get_size_one(1023, 1, "1.02 kB", "1023 B"); + test_string_get_size_one(1024, 1, "1.02 kB", "1.00 KiB"); + test_string_get_size_one(1025, 1, "1.03 kB", "1.00 KiB"); + + /* binary rounding around 1000 KiB */ + test_string_get_size_one(1023487, 1, "1.02 MB", "999 KiB"); + test_string_get_size_one(1023488, 1, "1.02 MB", "1000 KiB"); + test_string_get_size_one(1024000, 1, "1.02 MB", "1000 KiB"); + test_string_get_size_one(1024511, 1, "1.02 MB", "1000 KiB"); + test_string_get_size_one(1024512, 1, "1.02 MB", "1001 KiB"); + + /* binary boundary around 1 MiB */ + test_string_get_size_one(1048063, 1, "1.05 MB", "1023 KiB"); + test_string_get_size_one(1048064, 1, "1.05 MB", "1024 KiB"); + test_string_get_size_one(1048575, 1, "1.05 MB", "1024 KiB"); + test_string_get_size_one(1048576, 1, "1.05 MB", "1.00 MiB"); + test_string_get_size_one(1048577, 1, "1.05 MB", "1.00 MiB"); + + /* binary boundary around 2 MiB */ + test_string_get_size_one(2097151, 1, "2.10 MB", "2.00 MiB"); + test_string_get_size_one(2097152, 1, "2.10 MB", "2.00 MiB"); + test_string_get_size_one(2097153, 1, "2.10 MB", "2.00 MiB"); + /* huge values */ test_string_get_size_one(U64_MAX, 4096, "75.6 ZB", "64.0 ZiB"); test_string_get_size_one(4096, U64_MAX, "75.6 ZB", "64.0 ZiB"); --=20 2.50.1 (Apple Git-155)