]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Fix multiple Coverity Out-of-bounds access false postive issues in CAM
authortruckman <truckman@FreeBSD.org>
Tue, 24 May 2016 00:57:11 +0000 (00:57 +0000)
committertruckman <truckman@FreeBSD.org>
Tue, 24 May 2016 00:57:11 +0000 (00:57 +0000)
commita4774d8f19b89abf2a239ea88471c6a6fbdfff9b
tree46aa22f07e1f507182e38a44b6dd148c8cda0479
parent9ae9e7f9e06dc896592419dd2eb12935a3422395
Fix multiple Coverity Out-of-bounds access false postive issues in CAM

The currently used idiom for clearing the part of a ccb after its
header generates one or two Coverity errors for each time it is
used.  All instances generate an Out-of-bounds access (ARRAY_VS_SINGLETON)
error because of the treatment of the header as a two element array,
with a pointer to the non-existent second element being passed as
the starting address to bzero().  Some instances also alsp generate
Out-of-bounds access (OVERRUN) errors, probably because the space
being cleared is larger than the sizeofstruct ccb_hdr).

In addition, this idiom is difficult for humans to understand and
it is error prone.  The user has to chose the proper struct ccb_*
type (which does not appear in the surrounding code) for the sizeof()
in the length calculation.  I found several instances where the
length was incorrect, which could cause either an actual out of
bounds write, or incompletely clear the ccb.

A better way is to write the code to clear the ccb itself starting
at sizeof(ccb_hdr) bytes from the start of the ccb, and calculate
the length based on the specific type of struct ccb_* being cleared
as specified by the union ccb member being used.  The latter can
normally be seen in the nearby code.  This is friendlier for Coverity
and other static analysis tools because they will see that the
intent is to clear the trailing part of the ccb.

Wrap all of the boilerplate code in a convenient macro that only
requires a pointer to the desired union ccb member (or a pointer
to the union ccb itself) as an argument.

Reported by: Coverity
CID: 100757810086841009724100977310113041011306
CID: 101130710113081011309101131010113111011312
CID: 101131310113141011315101131610113171011318
CID: 101131910113201011321101132210113241011325
CID: 101132610113271011328101132910113301011374
CID: 101139010113911011392101139310113941011395
CID: 101139610113971011398101139910114001011401
CID: 101140210114031011404101140510114061011408
CID: 101140910114101011411101141210114131011414
CID: 101746110183871086860108687411942571229897
CID: 122996813062291306234133128213312831331294
CID: 133129513315351331536133153913315401341623
CID: 13416241341637134163813552641355324
Reviewed by: scottl, ken, delphij, imp
MFH: 1 month
Differential Revision: https://reviews.freebsd.org/D6496
lib/libcam/camlib.c
sbin/camcontrol/attrib.c
sbin/camcontrol/camcontrol.c
sbin/camcontrol/fwdownload.c
sbin/camcontrol/persist.c
sbin/iscontrol/fsm.c
sys/cam/cam_ccb.h
usr.sbin/camdd/camdd.c
usr.sbin/mptutil/mpt_cam.c