HomeFreeBSD

MFC r328436 and r328731:

Description

MFC r328436 and r328731:
Decouple Linux files from the belonging character device right after open
in the LinuxKPI. This is done by calling finit() just before returning a magic
value of ENXIO in the "linux_dev_fdopen" function.

The Linux file structure should mimic the BSD file structure as much as
possible. This patch decouples the Linux file structure from the belonging
character device right after the "linux_dev_fdopen" function has returned.
This fixes an issue which allows a Linux file handle to exist after a
character device has been destroyed and removed from the directory index
of /dev. Only when the reference count of the BSD file handle reaches zero,
the Linux file handle is destroyed. This fixes use-after-free issues related
to accessing the Linux file structure after the character device has been
destroyed.

While at it add a missing NULL check for non-present file operation.
Calling a NULL pointer will result in a segmentation fault.

Fix some recent regressions after r328436 in the LinuxKPI:

  1. The OPW() function macro should have the same return type like the

function it executes.

  1. The DEVFS I/O-limit should be enforced for all character device reads

and writes.

  1. The character device file handle should be passable, same as for

DEVFS based file handles.

Reviewed by: kib @
Reported by: jbeich @
Sponsored by: Mellanox Technologies

Details

Provenance
hselaskyAuthored on
Reviewer
kib
Parents
rS328979: Fix broken SPDX comment in usr.bin/lex/initparse.c
Branches
Unknown
Tags
Unknown