scsi: sg: recheck MMAP_IO request length with lock held
authorTodd Poynor <toddpoynor@google.com>
Wed, 16 Aug 2017 04:48:43 +0000 (21:48 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 9 Sep 2017 15:39:42 +0000 (17:39 +0200)
commit7791b59153cb2adfe2fa4273b2f9c8925c3238ed
treef676f35a5945c50d36723fe6dccb772292df8de4
parentb06e1abf1ff26046f0f3369b7abe8a221dadf26b
scsi: sg: recheck MMAP_IO request length with lock held

commit 8d26f491116feaa0b16de370b6a7ba40a40fa0b4 upstream.

Commit 1bc0eb044615 ("scsi: sg: protect accesses to 'reserved' page
array") adds needed concurrency protection for the "reserve" buffer.
Some checks that are initially made outside the lock are replicated once
the lock is taken to ensure the checks and resulting decisions are made
using consistent state.

The check that a request with flag SG_FLAG_MMAP_IO set fits in the
reserve buffer also needs to be performed again under the lock to ensure
the reserve buffer length compared against matches the value in effect
when the request is linked to the reserve buffer.  An -ENOMEM should be
returned in this case, instead of switching over to an indirect buffer
as for non-MMAP_IO requests.

Signed-off-by: Todd Poynor <toddpoynor@google.com>
Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/scsi/sg.c