scsi: target: tcmu: Fix crash on ARM during cmd completion
Subsystems (3)
PATCH 1/1 scsi: target: tcmu: Fix crash on ARM during cmd completion
If tcmu_handle_completions() has to process a padding shorter than sizeof(struct tcmu_cmd_entry), the current call to tcmu_flush_dcache_range() with sizeof(struct tcmu_cmd_entry) as length param is wrong and causes crashes on e.g. ARM, because tcmu_flush_dcache_range() in this case calls
flush_dcache_page(vmalloc_to_page(start));
with start being an invalid address above the end of the vmalloc'ed area.
The fix is to use the maximum of remaining ring space and sizeof(struct tcmu_cmd_entry) as the length param.
The patch was tested on kernel 4.19.118.
See https://bugzilla.kernel.org/show_bug.cgi?id 8045#c10
--- drivers/target/target_core_user.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/target/target_core_user.c +8 -1
@@ -1221,7 +1221,14 @@ static unsigned int tcmu_handle_completions(struct tcmu_dev *udev)struct tcmu_cmd_entry *entry = (void *) mb +CMDR_OFF + udev->cmdr_last_cleaned; -tcmu_flush_dcache_range (entry,sizeof (*entry)); +/* +* Flush max. up to end of cmd ring, since current entry might +* be a padding that is shorter than sizeof(*entry) +*/ +size_t ring_left =head_to_end (udev->cmdr_last_cleaned, + udev->cmdr_size); +tcmu_flush_dcache_range (entry, ring_left <sizeof (*entry) ? + ring_left :sizeof (*entry));if (tcmu_hdr_get_op (entry->hdr.len_op) =TCMU_OP_PAD ) { UPDATE_HEAD(udev->cmdr_last_cleaned,
Signature · 1 line
2.12.3
Quoted 33 lines · Bodo Stroesser
If
tcmu_handle_completions()has to process a padding shorter thansizeof(struct tcmu_cmd_entry), the current call totcmu_flush_dcache_range()withsizeof(struct tcmu_cmd_entry)as length param is wrong and causes crashes on e.g. ARM, becausetcmu_flush_dcache_range()in this case callsflush_dcache_page(vmalloc_to_page(start));with start being an invalid address above the end of the vmalloc'ed area.
The fix is to use the maximum of remaining ring space and
sizeof(struct tcmu_cmd_entry)as the length param.The patch was tested on kernel 4.19.118.
See https://urldefense.com/v3/__https://bugzilla.kernel.org/show_bug.cgi?id 8045*c10__;Iw!!GqivPVa7Brio!Kxr99oE0H1b9Ily4SE23nDN7ElSf8Tclo1RILfNSXb6iPh6DA5cSgtBQQsLMBKdrLsmT$
Signed-off-by Bodo Stroesser <[email protected]>Tested-by JiangYu <[email protected]>--- drivers/target/target_core_user.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)drivers/target/target_core_user.c +1
-1@@ -1221,7 +1221,14 @@ static unsigned int tcmu_handle_completions(struct tcmu_dev *udev)struct tcmu_cmd_entry *entry = (void *) mb +CMDR_OFF + udev->cmdr_last_cleaned; -tcmu_flush_dcache_range (entry,sizeof (*entry)); +/*
drivers/target/target_core_user.c static unsigned int tcmu_handle_completions(struct tcmu_dev *udev) · line 1234
Quoted 10 lines
drivers/target/target_core_user.c +7
-0+* Flush max. up to end of cmd ring, since current entry might +* be a padding that is shorter than sizeof(*entry) +*/ +size_t ring_left =head_to_end (udev->cmdr_last_cleaned, + udev->cmdr_size); +tcmu_flush_dcache_range (entry, ring_left <sizeof (*entry) ? + ring_left :sizeof (*entry));if (tcmu_hdr_get_op (entry->hdr.len_op) =TCMU_OP_PAD ) { UPDATE_HEAD(udev->cmdr_last_cleaned,
Thanks again.
Quoted 3 lines · Bodo Stroesser
The fix is to use the maximum of remaining ring space and
sizeof(struct tcmu_cmd_entry)as the length param.
[ ... ]
drivers/target/target_core_user.c static unsigned int tcmu_handle_completions(struct tcmu_dev *udev) · line 1234
Quoted 11 lines
drivers/target/target_core_user.c +8
-0+/* +* Flush max. up to end of cmd ring, since current entry might +* be a padding that is shorter than sizeof(*entry) +*/ +size_t ring_left =head_to_end (udev->cmdr_last_cleaned, + udev->cmdr_size); +tcmu_flush_dcache_range (entry, ring_left <sizeof (*entry) ? + ring_left :sizeof (*entry));if (tcmu_hdr_get_op (entry->hdr.len_op) =TCMU_OP_PAD ) { UPDATE_HEAD(udev->cmdr_last_cleaned,
The patch description says "maximum" but the above formula calculates the minimum of "ring_left" and sizeof(*entry). Did I perhaps misread this patch?
Thanks,
Bart.
Quoted 20 lines · Bart Van Assche
Quoted 3 lines · Bodo Stroesser
The fix is to use the maximum of remaining ring space and
sizeof(struct tcmu_cmd_entry)as the length param.[ ... ]
Quoted 9 lines
drivers/target/target_core_user.c +8
-0+/* +* Flush max. up to end of cmd ring, since current entry might +* be a padding that is shorter than sizeof(*entry) +*/ +size_t ring_left =head_to_end (udev->cmdr_last_cleaned, + udev->cmdr_size); +tcmu_flush_dcache_range (entry, ring_left <sizeof (*entry) ? + ring_left :sizeof (*entry));
Quoted 5 lines
Quoted 2 lines
if (tcmu_hdr_get_op(entry->hdr.len_op) == TCMU_OP_PAD) { UPDATE_HEAD(udev->cmdr_last_cleaned,The patch description says "maximum" but the above formula calculates the minimum of "
ring_left" andsizeof(*entry). Did I perhaps misread this patch?
Ah yeah, Bodo probably meant to write what they wrote for the comment above about the max up to the end of the ring and not max of space left and entry size.
Quoted 20 lines · Michael Christie
Quoted 20 lines · Bart Van Assche
Quoted 3 lines · Bodo Stroesser
The fix is to use the maximum of remaining ring space and
sizeof(struct tcmu_cmd_entry)as the length param.[ ... ]
Quoted 9 lines
drivers/target/target_core_user.c +8
-0+/* +* Flush max. up to end of cmd ring, since current entry might +* be a padding that is shorter than sizeof(*entry) +*/ +size_t ring_left =head_to_end (udev->cmdr_last_cleaned, + udev->cmdr_size); +tcmu_flush_dcache_range (entry, ring_left <sizeof (*entry) ? + ring_left :sizeof (*entry));
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
if (tcmu_hdr_get_op(entry->hdr.len_op) = TCMU_OP_PAD) { UPDATE_HEAD(udev->cmdr_last_cleaned,The patch description says "maximum" but the above formula calculates the minimum of "
ring_left" andsizeof(*entry). Did I perhaps misread this patch?Ah yeah, Bodo probably meant to write what they wrote for the comment above about the max up to the end of the ring and not max of space left and entry size.
Thank you, you both are right.
While the code and the comment in the code are fine, patch description is misleading or even wrong.
So I'm going to re-send the patch with fixed description and Mike's Acked-by.
BR, Bodo