opnsense-src/sys/geom
Mark Johnston f6e755d1b2 geom: Handle partial I/O in g_{read,write,delete}_data()
These routines are used internally by GEOM to dispatch I/O requests to a
provider, typically for tasting or for updating GEOM class metadata
blocks.

These routines assumed that partial I/O did not occur without setting
BIO_ERROR, but this is possible in at least two cases:
- Some or all of the I/O range is beyond the provider's mediasize.
  In this scenario g_io_check() truncates the bounds of the request
  before it is handed to the target provider.
- A read from vnode-backed md(4) device returns EOF (the backing vnode
  is allowed to be smaller than the device itself) or partial vnode I/O
  occurs.
In these scenarios g_read_data() could return a partially uninitialized
buffer.  Many consumers are not affected by the first case, since the
offsets used for provider metadata or tasting are relative to the
provider's mediasize, but in some cases metadata is read at fixed
offsets, such as when searching for a UFS superblock using the offsets
defined by SBLOCKSEARCH.

Thus, modify the routines to explicitly check for a non-zero residual
and return EIO in that case.  Remove a related check from the
DIOCGDELETE ioctl handler, it is handled within g_delete_data() now.

Reviewed by:	mav, imp, kib
Reported by:	KMSAN
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit d91d2b513e)
2022-02-03 09:34:27 -05:00
..
bde gbde: replace malloc_last_fail with a kludge 2020-11-12 20:20:57 +00:00
cache geom(4): Mark all sysctls as CTLFLAG_MPSAFE. 2021-08-24 21:53:17 -04:00
concat Make g_attach() return ENXIO for orphaned providers; update various 2020-10-18 16:24:08 +00:00
eli eli: Zero pad bytes that arise when certain auth algorithms are used 2021-07-29 08:12:22 -04:00
gate geom: clean up empty lines in .c and .h files 2020-09-01 22:14:09 +00:00
journal gjournal(8): Fix a typo in a source code comment 2021-11-06 08:51:45 +01:00
label geom label msdosfs: sanity check BPB before using it for io request 2022-01-14 20:11:01 +02:00
linux_lvm Make g_attach() return ENXIO for orphaned providers; update various 2020-10-18 16:24:08 +00:00
mirror gmirror: Zero the metadata block before writing 2021-07-26 21:47:45 -04:00
mountver Make g_attach() return ENXIO for orphaned providers; update various 2020-10-18 16:24:08 +00:00
multipath gmultipath: make physpath distinct from the underlying providers' 2021-06-17 12:39:14 -06:00
nop Make MAXPHYS tunable. Bump MAXPHYS to 1M. 2020-11-28 12:12:51 +00:00
part Make MAXPHYS tunable. Bump MAXPHYS to 1M. 2020-11-28 12:12:51 +00:00
raid graid: Avoid tasting devices with small sector sizes 2021-09-07 09:36:18 -04:00
raid3 graid3: Zero the metadata block before writing 2021-07-26 21:47:12 -04:00
shsec Make MAXPHYS tunable. Bump MAXPHYS to 1M. 2020-11-28 12:12:51 +00:00
stripe geom(4): Mark all sysctls as CTLFLAG_MPSAFE. 2021-08-24 21:53:17 -04:00
uzip Make MAXPHYS tunable. Bump MAXPHYS to 1M. 2020-11-28 12:12:51 +00:00
vinum Make MAXPHYS tunable. Bump MAXPHYS to 1M. 2020-11-28 12:12:51 +00:00
virstor Make MAXPHYS tunable. Bump MAXPHYS to 1M. 2020-11-28 12:12:51 +00:00
zero geom(4): Mark all sysctls as CTLFLAG_MPSAFE. 2021-08-24 21:53:17 -04:00
geom.h GEOM: Minor polishing in geom_event. 2022-01-10 21:45:30 -05:00
geom_bsd_enc.c sys/geom: adoption of SPDX licensing ID tags. 2017-11-27 15:17:37 +00:00
geom_ccd.c geom: clean up empty lines in .c and .h files 2020-09-01 22:14:09 +00:00
geom_ctl.c geom_ctl.c: remove stale header files 2020-10-20 20:59:13 +00:00
geom_ctl.h Define a constant for the maximum number of GEOM_CTL arguments. 2019-02-20 17:07:08 +00:00
geom_dbg.h GEOM: Reduce unnecessary log interleaving with sbufs 2019-08-07 19:28:35 +00:00
geom_dev.c geom: Handle partial I/O in g_{read,write,delete}_data() 2022-02-03 09:34:27 -05:00
geom_disk.c geom_disk: use a preallocated geom_event for disk destruction. 2021-09-12 09:56:14 -06:00
geom_disk.h geom_disk: use a preallocated geom_event for disk destruction. 2021-09-12 09:56:14 -06:00
geom_dump.c geom: clean up empty lines in .c and .h files 2020-09-01 22:14:09 +00:00
geom_event.c GEOM: Minor polishing in geom_event. 2022-01-10 21:45:30 -05:00
geom_flashmap.c Remove NAND and NANDFS support 2019-06-25 04:50:09 +00:00
geom_flashmap.h geom: clean up empty lines in .c and .h files 2020-09-01 22:14:09 +00:00
geom_int.h Remove duplicate g_debugflags declaration. 2019-12-05 15:07:32 +00:00
geom_io.c geom: Handle partial I/O in g_{read,write,delete}_data() 2022-02-03 09:34:27 -05:00
geom_kern.c geom(4): Mark all sysctls as CTLFLAG_MPSAFE. 2021-08-24 21:53:17 -04:00
geom_map.c geom: clean up empty lines in .c and .h files 2020-09-01 22:14:09 +00:00
geom_redboot.c geom_map and geom_redboot: Remove unused ctlreq handler. 2020-07-26 22:30:01 +00:00
geom_slice.c Pass BIO_SPEEDUP through all the geom layers 2020-01-17 01:15:55 +00:00
geom_slice.h sys/geom: adoption of SPDX licensing ID tags. 2017-11-27 15:17:37 +00:00
geom_subr.c geom(4): make g_newprovider_event() return if G_P_WITHER is set 2020-12-29 14:29:59 +00:00
geom_vfs.c g_vfs_close(): vp is unused 2021-11-19 06:25:29 +02:00
geom_vfs.h sys/geom: adoption of SPDX licensing ID tags. 2017-11-27 15:17:37 +00:00
notes