freebsd-dev/sys/cam/ata
Young Xiao 431ddd9436 Fix potential NULL pointer dereference of device physical path
In ata_dev_advinfo() and nvme_dev_advinfo(), if the physical path is
being stored and there is a malloc failure (malloc(9) is called with
M_NOWAIT), we could wind up in a situation where the device's
physpath_len is set to the length the user provided, but the physpath
itself is NULL.

If another context then comes in to fetch the physical path value, we
would wind up trying to memcpy a NULL pointer into the caller's buffer.

So, set the physpath_len to 0 when we free the physpath on entry into
the store case for the physical path.  Reset the length to a non-zero
value only after we've successfully malloced a buffer to hold it.

This code mirrors scsi_xpt.c does already as well.

Signed-off-by:	Young Xiao <92siuyang@gmail.com>
Reviewed by:	imp
PR:		238014
2021-07-13 14:13:21 -06:00
..
ata_all.c Fix sbuf_finish() error code check in user-space. 2020-10-13 23:29:06 +00:00
ata_all.h Replay r349340 by imp accidentally reverted by r349352 2019-06-25 06:14:21 +00:00
ata_da.c cam: enable kern.cam.ada.enable_uma_ccbs by default 2021-07-07 09:40:34 +01:00
ata_pmp.c cam: clean up empty lines in .c and .h files 2020-09-01 22:13:48 +00:00
ata_xpt.c Fix potential NULL pointer dereference of device physical path 2021-07-13 14:13:21 -06:00