target: Fix possible integer underflow in UNMAP emulation
authorRoland Dreier <roland@purestorage.com>
Mon, 16 Jul 2012 22:34:24 +0000 (15:34 -0700)
committerBen Hutchings <ben@decadent.org.uk>
Thu, 2 Aug 2012 13:37:50 +0000 (14:37 +0100)
commit76191bb22af0d68261d5d9a9b6294d68133813e0
tree19c46796f183260c19937c7615c4864a8d182397
parentb67183922769604a26c7a5ed1560fb71fd805635
target: Fix possible integer underflow in UNMAP emulation

commit b7fc7f3777582dea85156a821d78a522a0c083aa upstream.

It's possible for an initiator to send us an UNMAP command with a
descriptor that is less than 8 bytes; in that case it's really bad for
us to set an unsigned int to that value, subtract 8 from it, and then
use that as a limit for our loop (since the value will wrap around to
a huge positive value).

Fix this by making size be signed and only looping if size >= 16 (ie
if we have at least a full descriptor available).

Also remove offset as an obfuscated name for the constant 8.

Signed-off-by: Roland Dreier <roland@purestorage.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
[bwh: Backported to 3.2: adjust filename, context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/target/target_core_cdb.c