security/apparmor/policy_unpack_test.c:449 policy_unpack_test_unpack_u32_with_null_name() error: uninitialized symbol 'data'.

From: Dan Carpenter
Date: Tue Jul 07 2020 - 09:54:49 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 7cc2a8ea104820dd9e702202621e8fd4d9f6c8cf
commit: 4d944bcd4e731ab7bfe8d01a7041ea0ebdc090f1 apparmor: add AppArmor KUnit tests for policy unpack
date: 6 months ago
config: x86_64-randconfig-m001-20200702 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-14) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

smatch warnings:
security/apparmor/policy_unpack_test.c:449 policy_unpack_test_unpack_u32_with_null_name() error: uninitialized symbol 'data'.
security/apparmor/policy_unpack_test.c:466 policy_unpack_test_unpack_u32_with_name() error: uninitialized symbol 'data'.
security/apparmor/policy_unpack_test.c:499 policy_unpack_test_unpack_u64_with_null_name() error: uninitialized symbol 'data'.
security/apparmor/policy_unpack_test.c:516 policy_unpack_test_unpack_u64_with_name() error: uninitialized symbol 'data'.

# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4d944bcd4e731ab7bfe8d01a7041ea0ebdc090f1
git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git remote update linus
git checkout 4d944bcd4e731ab7bfe8d01a7041ea0ebdc090f1
vim +/data +449 security/apparmor/policy_unpack_test.c

4d944bcd4e731a Mike Salvatore 2019-11-05 438 static void policy_unpack_test_unpack_u32_with_null_name(struct kunit *test)
4d944bcd4e731a Mike Salvatore 2019-11-05 439 {
4d944bcd4e731a Mike Salvatore 2019-11-05 440 struct policy_unpack_fixture *puf = test->priv;
4d944bcd4e731a Mike Salvatore 2019-11-05 441 bool success;
4d944bcd4e731a Mike Salvatore 2019-11-05 442 u32 data;
4d944bcd4e731a Mike Salvatore 2019-11-05 443
4d944bcd4e731a Mike Salvatore 2019-11-05 444 puf->e->pos += TEST_U32_BUF_OFFSET;
4d944bcd4e731a Mike Salvatore 2019-11-05 445
4d944bcd4e731a Mike Salvatore 2019-11-05 446 success = unpack_u32(puf->e, &data, NULL);
^^^^^
Presumably not initialized on failure.

4d944bcd4e731a Mike Salvatore 2019-11-05 447
4d944bcd4e731a Mike Salvatore 2019-11-05 448 KUNIT_EXPECT_TRUE(test, success);
4d944bcd4e731a Mike Salvatore 2019-11-05 @449 KUNIT_EXPECT_EQ(test, data, TEST_U32_DATA);
4d944bcd4e731a Mike Salvatore 2019-11-05 450 KUNIT_EXPECT_PTR_EQ(test, puf->e->pos,
4d944bcd4e731a Mike Salvatore 2019-11-05 451 puf->e->start + TEST_U32_BUF_OFFSET + sizeof(u32) + 1);
4d944bcd4e731a Mike Salvatore 2019-11-05 452 }
4d944bcd4e731a Mike Salvatore 2019-11-05 453
4d944bcd4e731a Mike Salvatore 2019-11-05 454 static void policy_unpack_test_unpack_u32_with_name(struct kunit *test)
4d944bcd4e731a Mike Salvatore 2019-11-05 455 {
4d944bcd4e731a Mike Salvatore 2019-11-05 456 struct policy_unpack_fixture *puf = test->priv;
4d944bcd4e731a Mike Salvatore 2019-11-05 457 const char name[] = TEST_U32_NAME;
4d944bcd4e731a Mike Salvatore 2019-11-05 458 bool success;
4d944bcd4e731a Mike Salvatore 2019-11-05 459 u32 data;
4d944bcd4e731a Mike Salvatore 2019-11-05 460
4d944bcd4e731a Mike Salvatore 2019-11-05 461 puf->e->pos += TEST_NAMED_U32_BUF_OFFSET;
4d944bcd4e731a Mike Salvatore 2019-11-05 462
4d944bcd4e731a Mike Salvatore 2019-11-05 463 success = unpack_u32(puf->e, &data, name);
4d944bcd4e731a Mike Salvatore 2019-11-05 464
4d944bcd4e731a Mike Salvatore 2019-11-05 465 KUNIT_EXPECT_TRUE(test, success);
4d944bcd4e731a Mike Salvatore 2019-11-05 @466 KUNIT_EXPECT_EQ(test, data, TEST_U32_DATA);
4d944bcd4e731a Mike Salvatore 2019-11-05 467 KUNIT_EXPECT_PTR_EQ(test, puf->e->pos,
4d944bcd4e731a Mike Salvatore 2019-11-05 468 puf->e->start + TEST_U32_BUF_OFFSET + sizeof(u32) + 1);
4d944bcd4e731a Mike Salvatore 2019-11-05 469 }
4d944bcd4e731a Mike Salvatore 2019-11-05 470
4d944bcd4e731a Mike Salvatore 2019-11-05 471 static void policy_unpack_test_unpack_u32_out_of_bounds(struct kunit *test)
4d944bcd4e731a Mike Salvatore 2019-11-05 472 {
4d944bcd4e731a Mike Salvatore 2019-11-05 473 struct policy_unpack_fixture *puf = test->priv;
4d944bcd4e731a Mike Salvatore 2019-11-05 474 const char name[] = TEST_U32_NAME;
4d944bcd4e731a Mike Salvatore 2019-11-05 475 bool success;
4d944bcd4e731a Mike Salvatore 2019-11-05 476 u32 data;
4d944bcd4e731a Mike Salvatore 2019-11-05 477
4d944bcd4e731a Mike Salvatore 2019-11-05 478 puf->e->pos += TEST_NAMED_U32_BUF_OFFSET;
4d944bcd4e731a Mike Salvatore 2019-11-05 479 puf->e->end = puf->e->start + TEST_U32_BUF_OFFSET + sizeof(u32);
4d944bcd4e731a Mike Salvatore 2019-11-05 480
4d944bcd4e731a Mike Salvatore 2019-11-05 481 success = unpack_u32(puf->e, &data, name);
4d944bcd4e731a Mike Salvatore 2019-11-05 482
4d944bcd4e731a Mike Salvatore 2019-11-05 483 KUNIT_EXPECT_FALSE(test, success);
4d944bcd4e731a Mike Salvatore 2019-11-05 484 KUNIT_EXPECT_PTR_EQ(test, puf->e->pos,
4d944bcd4e731a Mike Salvatore 2019-11-05 485 puf->e->start + TEST_NAMED_U32_BUF_OFFSET);
4d944bcd4e731a Mike Salvatore 2019-11-05 486 }
4d944bcd4e731a Mike Salvatore 2019-11-05 487
4d944bcd4e731a Mike Salvatore 2019-11-05 488 static void policy_unpack_test_unpack_u64_with_null_name(struct kunit *test)
4d944bcd4e731a Mike Salvatore 2019-11-05 489 {
4d944bcd4e731a Mike Salvatore 2019-11-05 490 struct policy_unpack_fixture *puf = test->priv;
4d944bcd4e731a Mike Salvatore 2019-11-05 491 bool success;
4d944bcd4e731a Mike Salvatore 2019-11-05 492 u64 data;
4d944bcd4e731a Mike Salvatore 2019-11-05 493
4d944bcd4e731a Mike Salvatore 2019-11-05 494 puf->e->pos += TEST_U64_BUF_OFFSET;
4d944bcd4e731a Mike Salvatore 2019-11-05 495
4d944bcd4e731a Mike Salvatore 2019-11-05 496 success = unpack_u64(puf->e, &data, NULL);
4d944bcd4e731a Mike Salvatore 2019-11-05 497
4d944bcd4e731a Mike Salvatore 2019-11-05 498 KUNIT_EXPECT_TRUE(test, success);
4d944bcd4e731a Mike Salvatore 2019-11-05 @499 KUNIT_EXPECT_EQ(test, data, TEST_U64_DATA);
4d944bcd4e731a Mike Salvatore 2019-11-05 500 KUNIT_EXPECT_PTR_EQ(test, puf->e->pos,
4d944bcd4e731a Mike Salvatore 2019-11-05 501 puf->e->start + TEST_U64_BUF_OFFSET + sizeof(u64) + 1);
4d944bcd4e731a Mike Salvatore 2019-11-05 502 }
4d944bcd4e731a Mike Salvatore 2019-11-05 503
4d944bcd4e731a Mike Salvatore 2019-11-05 504 static void policy_unpack_test_unpack_u64_with_name(struct kunit *test)
4d944bcd4e731a Mike Salvatore 2019-11-05 505 {
4d944bcd4e731a Mike Salvatore 2019-11-05 506 struct policy_unpack_fixture *puf = test->priv;
4d944bcd4e731a Mike Salvatore 2019-11-05 507 const char name[] = TEST_U64_NAME;
4d944bcd4e731a Mike Salvatore 2019-11-05 508 bool success;
4d944bcd4e731a Mike Salvatore 2019-11-05 509 u64 data;
4d944bcd4e731a Mike Salvatore 2019-11-05 510
4d944bcd4e731a Mike Salvatore 2019-11-05 511 puf->e->pos += TEST_NAMED_U64_BUF_OFFSET;
4d944bcd4e731a Mike Salvatore 2019-11-05 512
4d944bcd4e731a Mike Salvatore 2019-11-05 513 success = unpack_u64(puf->e, &data, name);
4d944bcd4e731a Mike Salvatore 2019-11-05 514
4d944bcd4e731a Mike Salvatore 2019-11-05 515 KUNIT_EXPECT_TRUE(test, success);
4d944bcd4e731a Mike Salvatore 2019-11-05 @516 KUNIT_EXPECT_EQ(test, data, TEST_U64_DATA);
4d944bcd4e731a Mike Salvatore 2019-11-05 517 KUNIT_EXPECT_PTR_EQ(test, puf->e->pos,
4d944bcd4e731a Mike Salvatore 2019-11-05 518 puf->e->start + TEST_U64_BUF_OFFSET + sizeof(u64) + 1);
4d944bcd4e731a Mike Salvatore 2019-11-05 519 }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx

Attachment: .config.gz
Description: application/gzip