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:27 +0000 (17:39 +0200)
commit200afc408c2dd87faf477be862854aca71f0b693
tree43f95f0f6a9baff1dcdd9415da0cb9fa48aef3e9
parentba25748e0a742594e264844be64e3c4266e34d0c
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