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)
Mon, Apr 29, 11:18 PM
Unknown Object (File)
Mon, Apr 22, 1:21 PM
Unknown Object (File)
Mar 7 2024, 10:39 AM
Unknown Object (File)
Feb 11 2024, 5:35 PM
Unknown Object (File)
Feb 11 2024, 5:09 PM
Unknown Object (File)
Dec 20 2023, 6:12 AM
Unknown Object (File)
Nov 30 2023, 5:03 AM
Unknown Object (File)
Oct 24 2023, 11:46 AM
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.