Page MenuHomeFreeBSD

file: Make fget*() and getvnode*() consistent about initializing *fpp
ClosedPublic

Authored by markj on Feb 7 2022, 3:19 PM.
Tags
None
Referenced Files
Unknown Object (File)
Oct 1 2024, 1:15 PM
Unknown Object (File)
Sep 30 2024, 4:40 PM
Unknown Object (File)
Sep 28 2024, 10:23 AM
Unknown Object (File)
Sep 27 2024, 1:14 PM
Unknown Object (File)
Sep 21 2024, 5:03 AM
Unknown Object (File)
Sep 10 2024, 9:25 AM
Unknown Object (File)
Sep 4 2024, 10:54 AM
Unknown Object (File)
Sep 2 2024, 1:58 PM
Subscribers

Details

Summary

Most fget*() functions initialize the output parameter to NULL. Make them
all behave consistently. This fixes at least one bug in a consumer,
_filemon_wrapper_openat().

Reported by: syzbot+01c0459408f896a5933a@syzkaller.appspotmail.com

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

markj requested review of this revision.Feb 7 2022, 3:19 PM
sys/kern/vfs_syscalls.c
4322

Should this return handled?

sys/kern/vfs_syscalls.c
4322

fget_unlocked() modifies *fpp only when it returns success. I think it's ok to rely on that here. This diff is just extending that semantic to getvnode()/getvnode_path().

kib added inline comments.
sys/kern/vfs_syscalls.c
4322

My reaction is to the fact that 'modifying only on success' != 'setting to NULL on failure'. It is somewhat confusing for getvnode() now.

This revision is now accepted and ready to land.Feb 7 2022, 3:39 PM
sys/kern/vfs_syscalls.c
4322

Hmm. fget() explicitly initializes *fpp = NULL, but fget_unlocked() does not. This results in inconsistencies: fget_cap() may or may not initialize *fpp = NULL in the error case depending on whether CAPABILITIES is defined.

IMO fget_unlocked() should change as well.

  • Make fget_unlocked_seq() private to kern_descrip.c
  • Make fget* consistent about initializing the output pointer. Some routines were doing it, some not, but it seems preferable to provide some guarantees there to help ensure that buggy callers fail closed.
This revision now requires review to proceed.Feb 7 2022, 5:43 PM
markj retitled this revision from file: Make getvnode*() set the returned file handle to NULL upon error to file: Make fget*() and getvnode*() consistent about initializing *fpp.Feb 7 2022, 5:44 PM
markj edited the summary of this revision. (Show Details)
markj added a reviewer: mjg.
This revision is now accepted and ready to land.Feb 7 2022, 7:06 PM

I see I'm late. Just a remark that this nullifying is pretty weird and thing to do instead is to set the pointer to a poisoned value when running with invariants, while patching all the consumers to not look at it if an error was returned. Maybe I'll get around to it.