Skip to contentSkip to conversation

jfs: possible uninitialized-variable access in xtSplitUp()

BUG Li Tuo 2 participants 3 messages Jul 31, 2021 – Aug 3, 2021

lore
Share & tools
lore

Li Tuo

author
#0 lore raw

Hello,

Our static analysis tool finds a possible uninitialized-variable access in the jfs driver in Linux 5.14.0-rc3:

At the beginning of the function xtSplitUp(), the variable rbn is not initialized.
If sp->header.flag & BT_ROOT is true,
780:    rc = (sp->header.flag & BT_ROOT) ? xtSplitRoot(tid, ip, split, &rmp) : xtSplitPage(tid, ip, split, &rmp, &rbn);

the varialbe rbn will remain uninitialized.
However, it is accessed through:
814:    rcbn = rbn;

I am not quite sure whether this possible uninitialized-variable access is real and how to fix it if it is real. Any feedback would be appreciated, thanks!

Best wishes,
Tuo Li

#1 lore raw
Quoted 8 lines · Li Tuo

Hello,

Our static analysis tool finds a possible uninitialized-variable access in the jfs driver in Linux 5.14.0-rc3:

At the beginning of the function xtSplitUp(), the variable rbn is not initialized.
If sp->header.flag & BT_ROOT is true,
780:    rc = (sp->header.flag & BT_ROOT) ? xtSplitRoot(tid, ip, split, &rmp) : xtSplitPage(tid, ip, split, &rmp, &rbn);

Quoted 6 lines

the varialbe rbn will remain uninitialized.
However, it is accessed through:
814:    rcbn = rbn;

I am not quite sure whether this possible uninitialized-variable access is real and how to fix it if it is real. Any feedback would be appreciated, thanks!

I think the logic that protects us is that in the case where rbn is uninitialized, sp->header.flag & BT_ROOT, which means it SHOULD BE the last entry in btstack, so we shouldn't enter the loop:

	while ((parent = BT_POP(btstack)) != NULL) {

It does seem that some type of sanity check is warranted. I'll take a closer look and see if I can add some kind of error path if things are out of sync.

Quoted 5 lines

Best wishes,
Tuo Li

author
#2 lore raw

Thanks for your feedback, and any feedback about the further check would be appreciated!

Best wishes,
Tuo Li

Quoted 26 lines · Dave Kleikamp
Quoted 8 lines · Li Tuo

Hello,

Our static analysis tool finds a possible uninitialized-variable access in the jfs driver in Linux 5.14.0-rc3:

At the beginning of the function xtSplitUp(), the variable rbn is not initialized.
If sp->header.flag & BT_ROOT is true,
780:    rc = (sp->header.flag & BT_ROOT) ? xtSplitRoot(tid, ip, split, &rmp) : xtSplitPage(tid, ip, split, &rmp, &rbn);

Quoted 6 lines

the varialbe rbn will remain uninitialized.
However, it is accessed through:
814:    rcbn = rbn;

I am not quite sure whether this possible uninitialized-variable access is real and how to fix it if it is real. Any feedback would be appreciated, thanks!

I think the logic that protects us is that in the case where rbn is uninitialized, sp->header.flag & BT_ROOT, which means it SHOULD BE the last entry in btstack, so we shouldn't enter the loop:
    while ((parent = BT_POP(btstack)) != NULL) {

It does seem that some type of sanity check is warranted. I'll take a closer look and see if I can add some kind of error path if things are out of sync.

Quoted 5 lines

Best wishes,
Tuo Li