Page MenuHomeFreeBSD

Fix use after free in msdosfs_rename()
AbandonedPublic

Authored by trasz on Nov 23 2020, 1:51 PM.
Tags
None
Referenced Files
Unknown Object (File)
Jan 28 2024, 4:55 AM
Unknown Object (File)
Dec 21 2023, 11:25 PM
Unknown Object (File)
Dec 4 2023, 6:09 AM
Unknown Object (File)
Aug 20 2023, 6:16 AM
Unknown Object (File)
Aug 16 2023, 9:47 PM
Unknown Object (File)
Jun 20 2023, 4:53 PM
Unknown Object (File)
Jun 19 2023, 2:31 AM
Unknown Object (File)
Jun 3 2023, 8:21 AM
Subscribers

Details

Reviewers
kib
Summary

Fix use after free in msdosfs_rename().

The ip points to v_data for fvp; however, fvp could have changed
during relookup(). This cannot happen if 'doingdirectory' is true,
and the DE_RENAME flag can only ever be set if 'doingdirectory'
is true, so use that to guard the clearing.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 35343
Build 32271: arc lint + arc unit

Event Timeline

trasz requested review of this revision.Nov 23 2020, 1:51 PM
trasz retitled this revision from Fix use after fr in msdosfs_rename() to Fix use after free in msdosfs_rename().Nov 23 2020, 2:06 PM
trasz edited the summary of this revision. (Show Details)

This is not a proper fix. ip is invalid the very moment fvp is unlocked.

In D27337#610604, @kib wrote:

This is not a proper fix. ip is invalid the very moment fvp is unlocked.

"ip" as the pointer (later used to compare it with "xp"), or vnode data it points to?

In D27337#610604, @kib wrote:

This is not a proper fix. ip is invalid the very moment fvp is unlocked.

"ip" as the pointer (later used to compare it with "xp"), or vnode data it points to?

Well, is a pointer to freed memory valid ? This is somewhat scholastic question, and I believe that our kernel depends on pointer value itself not becoming a poisoned value after free.
But the data it points to is invalid, and your patch still accesses the potentially freed or reused memory.

In D27337#613495, @kib wrote:
In D27337#610604, @kib wrote:

This is not a proper fix. ip is invalid the very moment fvp is unlocked.

"ip" as the pointer (later used to compare it with "xp"), or vnode data it points to?

Well, is a pointer to freed memory valid ? This is somewhat scholastic question, and I believe that our kernel depends on pointer value itself not becoming a poisoned value after free.
But the data it points to is invalid, and your patch still accesses the potentially freed or reused memory.

Can you show me where? From my reading of the code, if doingdirectory != 0, the ip must be valid (equal to xp), due to checks at 1139-1141.

In D27337#613495, @kib wrote:
In D27337#610604, @kib wrote:

This is not a proper fix. ip is invalid the very moment fvp is unlocked.

"ip" as the pointer (later used to compare it with "xp"), or vnode data it points to?

Well, is a pointer to freed memory valid ? This is somewhat scholastic question, and I believe that our kernel depends on pointer value itself not becoming a poisoned value after free.
But the data it points to is invalid, and your patch still accesses the potentially freed or reused memory.

Can you show me where? From my reading of the code, if doingdirectory != 0, the ip must be valid (equal to xp), due to checks at 1139-1141.

It is valid until fvp is unlocked, after which it is invalid.

Make sure the ip is valid.

Ah, right. What do you think about the new patch? I've tried avoiding the relocking, but the code flow there is somewhat complicated and I'd probably introduce more bugs.

I do not think this patch is good either. You should clear DE_RENAME right before unlock.

Which unlock? The gotos at 1048, 1057, 1062, 1076, 1080, 1085, and 1089 all get here without the lock held.

Which unlock? The gotos at 1048, 1057, 1062, 1076, 1080, 1085, and 1089 all get here without the lock held.

Any unlock.

If fact, it is interesting to look at uses of DE_RENAME. Idea is to prevent directory removal and rename going in parallel. But, wouldn't vnode locking have the same effect? Why do we need to prevent this for the renamed vnode?