freebsd-dev/sys/fs
Rick Macklem 1cedb4ea1a nfscl: Fix a use after free in nfscl_cleanupkext()
ler@, markj@ reported a use after free in nfscl_cleanupkext().
They also provided two possible causes:
- In nfscl_cleanup_common(), "own" is the owner string
  owp->nfsow_owner.  If we free that particular
  owner structure, than in subsequent comparisons
  "own" will point to freed memory.
- nfscl_cleanup_common() can free more than one owner, so the use
  of LIST_FOREACH_SAFE() in nfscl_cleanupkext() is not sufficient.

I also believe there is a 3rd:
- If nfscl_freeopenowner() or nfscl_freelockowner() is called
  without the NFSCLSTATE mutex held, this could race with
  nfscl_cleanupkext().
  This could happen when the exclusive lock is held
  on the client, such as when delegations are being returned
  or when recovering from NFSERR_EXPIRED.

This patch fixes them as follows:
1 - Copy the owner string to a local variable before the
    nfscl_cleanup_common() call.
2 - Modify nfscl_cleanup_common() so that it will never free more
    than the first matching element.  Normally there should only
    be one element in each list with a matching open/lock owner
    anyhow (but there might be a bug that results in a duplicate).
    This should guarantee that the FOREACH_SAFE loops in
    nfscl_cleanupkext() are adequate.
3 - Acquire the NFSCLSTATE mutex in nfscl_freeopenowner()
    and nfscl_freelockowner(), if it is not already held.
    This serializes all of these calls with the ones done in
    nfscl_cleanup_common().

Reported by:	ler
Reviewed by:	markj
Tested by:	cy
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D34334
2022-02-25 07:27:03 -08:00
..
autofs vfs: remove cn_thread 2021-10-11 13:21:47 +00:00
cd9660 Change VOP_READDIR's cookies argument to a **uint64_t 2021-12-15 20:54:57 -07:00
cuse Fix for loading cuse.ko via rc.d . Make sure we declare the cuse(3) 2020-10-23 08:44:53 +00:00
deadfs vn_open(): If the vnode is reclaimed during open(2), do not return error. 2021-02-12 03:02:20 +02:00
devfs fs: fix a few common typos in source code comments 2022-02-06 13:48:31 +01:00
ext2fs fs: fix a few common typos in source code comments 2022-02-06 13:48:31 +01:00
fdescfs insmntque1(): remove useless arguments 2022-01-31 16:49:08 +02:00
fifofs fifos: delegate unhandled kqueue filters to underlying filesystem 2021-10-12 02:43:07 -05:00
fuse fusefs: fix a cached attributes bug during directory rename 2022-02-24 14:07:25 -07:00
mntfs mntfs: lock mntfs pseudo devfs vnode properly 2021-11-13 01:00:41 +02:00
msdosfs msdosfs: Fix mounting when the device sector size is >512B 2022-02-14 10:06:47 -05:00
nfs nfsclient: Delete unused function nfscl_getcookie() 2022-01-27 15:30:26 -08:00
nfsclient nfscl: Fix a use after free in nfscl_cleanupkext() 2022-02-25 07:27:03 -08:00
nfsserver nfsd: Reply NFSERR_SEQMISORDERED for bogus seqid argument 2022-02-09 15:17:50 -08:00
nullfs insmntque1(): remove useless arguments 2022-01-31 16:49:08 +02:00
procfs procfs_doprocfile(): simplify 2021-11-04 06:13:47 +02:00
pseudofs pseudofs: Destroy vncache hashtbl on pseudofs module unload. 2021-12-09 21:41:08 +00:00
smbfs Change VOP_READDIR's cookies argument to a **uint64_t 2021-12-15 20:54:57 -07:00
tmpfs insmntque1(): remove useless arguments 2022-01-31 16:49:08 +02:00
udf Change VOP_READDIR's cookies argument to a **uint64_t 2021-12-15 20:54:57 -07:00
unionfs unionfs: rework unionfs_getwritemount() 2022-02-23 22:10:02 -06:00