[linux-next:master 11333/13846] lib/crypto/tests/aes_ccm_kunit.c:317 test_aes_ccm_data_len_too_large() warn: always true condition '(max_data_len + 1 <= (~0)) => (0-u64max <= u64max)'

kernel test robot <[email protected]>
Newsgroups dev.linux.lists.oe-kbuild-all
Message-ID <[email protected]>
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   6b8c8af514d739d0335f5579b585e02babe8a727
commit: 78c1bc21eb055681672da1de139d27865b67d1b2 [11333/13846] lib/crypto: tests: Add KUnit test suite for AES-CCM
config: s390-randconfig-r072-20260807 (https://download.01.org/0day-ci/archive/20260808/[email protected]/config)
compiler: s390-linux-gcc (GCC) 8.5.0
smatch: v0.5.0-9187-g5189e3fb

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

smatch warnings:
lib/crypto/tests/aes_ccm_kunit.c:317 test_aes_ccm_data_len_too_large() warn: always true condition '(max_data_len + 1 <= (~0)) => (0-u64max <= u64max)'

vim +317 lib/crypto/tests/aes_ccm_kunit.c

   261	
   262	/*
   263	 * Test that for each AES-CCM nonce length, the message length is validated
   264	 * against the correct corresponding maximum message length.
   265	 */
   266	static void test_aes_ccm_data_len_too_large(struct kunit *test)
   267	{
   268		static const struct {
   269			size_t nonce_len;
   270			u64 max_data_len;
   271		} lens[] = {
   272			/* clang-format off */
   273			{ 7, 0xffffffffffffffff }, /* U64_MAX */
   274			{ 8, 0xffffffffffffff },
   275			{ 9, 0xffffffffffff },
   276			{ 10, 0xffffffffff },
   277			{ 11, 0xffffffff },
   278			{ 12, 0xffffff },
   279			{ 13, 0xffff },
   280			/* clang-format on */
   281		};
   282		u8 nonce[13] = {};
   283		u8 raw_key[AES_KEYSIZE_256] = {};
   284		int err;
   285		struct aes_ccm_key *key = alloc_buf(test, sizeof(*key));
   286		struct aes_ccm_ctx ctx;
   287	
   288		err = aes_ccm_preparekey(key, raw_key, sizeof(raw_key), 16);
   289		KUNIT_ASSERT_EQ(test, 0, err);
   290	
   291		for (size_t i = 0; i < ARRAY_SIZE(lens); i++) {
   292			size_t nonce_len = lens[i].nonce_len;
   293			u64 max_data_len = lens[i].max_data_len;
   294	
   295			/* data_len <= max_data_len should be accepted. */
   296			err = aes_ccm_init(&ctx, 0, 0, nonce, nonce_len, key);
   297			KUNIT_ASSERT_EQ_MSG(
   298				test, 0, err,
   299				"data_len=0 wasn't accepted with nonce_len=%zu",
   300				nonce_len);
   301			err = aes_ccm_init(&ctx, max_data_len, 0, nonce, nonce_len,
   302					   key);
   303			KUNIT_ASSERT_EQ_MSG(
   304				test, 0, err,
   305				"data_len=%llu wasn't accepted with nonce_len=%zu",
   306				max_data_len, nonce_len);
   307	
   308			/* data_len > max_data_len should be rejected. */
   309			if (max_data_len == U64_MAX)
   310				continue;
   311			err = aes_ccm_init(&ctx, max_data_len + 1, 0, nonce, nonce_len,
   312					   key);
   313			KUNIT_ASSERT_EQ_MSG(
   314				test, -EOVERFLOW, err,
   315				"data_len=%llu wasn't rejected with -EOVERFLOW with nonce_len=%zu (aes_ccm_init)",
   316				max_data_len + 1, nonce_len);
 > 317			if (max_data_len + 1 <= SIZE_MAX) {
   318				err = aes_ccm_encrypt(NULL, NULL, max_data_len + 1,
   319						      NULL, NULL, 0, nonce, nonce_len,
   320						      key);
   321				KUNIT_ASSERT_EQ_MSG(
   322					test, -EOVERFLOW, err,
   323					"data_len=%llu wasn't rejected with -EOVERFLOW with nonce_len=%zu (aes_ccm_encrypt)",
   324					max_data_len + 1, nonce_len);
   325				err = aes_ccm_decrypt(NULL, NULL, max_data_len + 1,
   326						      NULL, NULL, 0, nonce, nonce_len,
   327						      key);
   328				KUNIT_ASSERT_EQ_MSG(
   329					test, -EOVERFLOW, err,
   330					"data_len=%llu wasn't rejected with -EOVERFLOW with nonce_len=%zu (aes_ccm_decrypt)",
   331					max_data_len + 1, nonce_len);
   332			}
   333			err = aes_ccm_init(&ctx, U64_MAX, 0, nonce, nonce_len, key);
   334			KUNIT_ASSERT_EQ_MSG(
   335				test, -EOVERFLOW, err,
   336				"data_len=U64_MAX wasn't rejected with -EOVERFLOW with nonce_len=%zu (aes_ccm_init)",
   337				nonce_len);
   338		}
   339	}
   340	

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.