]> git.baikalelectronics.ru Git - kernel.git/commit
scsi: sg: Allow waiting for commands to complete on removed device
authorTony Battersby <tonyb@cybernetics.com>
Mon, 11 Jul 2022 14:51:32 +0000 (10:51 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Aug 2022 09:18:17 +0000 (11:18 +0200)
commitd4e17d49046cdc3d810d080eddcb0323a363d1ed
tree51c4e0945b0fe852f96686943cb5a576e2db6e98
parentacd886ac588a62356e6c92d9f8cedef42c50c883
scsi: sg: Allow waiting for commands to complete on removed device

commit 53db118bb8a09b0b4f6f8fb68817927d5b606c03 upstream.

When a SCSI device is removed while in active use, currently sg will
immediately return -ENODEV on any attempt to wait for active commands that
were sent before the removal.  This is problematic for commands that use
SG_FLAG_DIRECT_IO since the data buffer may still be in use by the kernel
when userspace frees or reuses it after getting ENODEV, leading to
corrupted userspace memory (in the case of READ-type commands) or corrupted
data being sent to the device (in the case of WRITE-type commands).  This
has been seen in practice when logging out of a iscsi_tcp session, where
the iSCSI driver may still be processing commands after the device has been
marked for removal.

Change the policy to allow userspace to wait for active sg commands even
when the device is being removed.  Return -ENODEV only when there are no
more responses to read.

Link: https://lore.kernel.org/r/5ebea46f-fe83-2d0b-233d-d0dcb362dd0a@cybernetics.com
Cc: <stable@vger.kernel.org>
Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: Tony Battersby <tonyb@cybernetics.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/scsi/sg.c