scsi: sg: protect against races between mmap() and SG_SET_RESERVED_SIZE
authorTodd Poynor <toddpoynor@google.com>
Wed, 16 Aug 2017 05:41:08 +0000 (22:41 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 9 Sep 2017 15:39:42 +0000 (17:39 +0200)
commitb06e1abf1ff26046f0f3369b7abe8a221dadf26b
tree4c55d8badb58e8c1f649f4c4129a87a0c869cdfa
parent5b9c6a54c629e38271acf833f75154f2f8333365
scsi: sg: protect against races between mmap() and SG_SET_RESERVED_SIZE

commit 6a8dadcca81fceff9976e8828cceb072873b7bd5 upstream.

Take f_mutex around mmap() processing to protect against races with the
SG_SET_RESERVED_SIZE ioctl.  Ensure the reserve buffer length remains
consistent during the mapping operation, and set the "mmap called" flag
to prevent further changes to the reserved buffer size as an atomic
operation with the mapping.

[mkp: fixed whitespace]

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