Commit 134a24cd authored by Christian Borntraeger's avatar Christian Borntraeger Committed by Martin Schwidefsky

s390/crc32-vx: Fix checksum calculation for small sizes

The current prealign logic will fail for sizes < alignment,
as the new datalen passed to the vector function is smaller
than zero. Being a size_t this gets wrapped to a huge
number causing memory overruns and wrong data.

Let's add an early exit if the size is smaller than the minimal
size with alignment. This will also avoid calling the software
fallback twice for all sizes smaller than the minimum size
(prealign + remaining)
Signed-off-by: default avatarChristian Borntraeger <borntraeger@de.ibm.com>
Fixes: f848dbd3 ("s390/crc32-vx: add crypto API module for optimized CRC-32 algorithms")
Reviewed-by: default avatarHendrik Brueckner <brueckner@linux.vnet.ibm.com>
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
parent bf47dc57
...@@ -51,6 +51,9 @@ u32 crc32c_le_vgfm_16(u32 crc, unsigned char const *buf, size_t size); ...@@ -51,6 +51,9 @@ u32 crc32c_le_vgfm_16(u32 crc, unsigned char const *buf, size_t size);
struct kernel_fpu vxstate; \ struct kernel_fpu vxstate; \
unsigned long prealign, aligned, remaining; \ unsigned long prealign, aligned, remaining; \
\ \
if (datalen < VX_MIN_LEN + VX_ALIGN_MASK) \
return ___crc32_sw(crc, data, datalen); \
\
if ((unsigned long)data & VX_ALIGN_MASK) { \ if ((unsigned long)data & VX_ALIGN_MASK) { \
prealign = VX_ALIGNMENT - \ prealign = VX_ALIGNMENT - \
((unsigned long)data & VX_ALIGN_MASK); \ ((unsigned long)data & VX_ALIGN_MASK); \
...@@ -59,9 +62,6 @@ u32 crc32c_le_vgfm_16(u32 crc, unsigned char const *buf, size_t size); ...@@ -59,9 +62,6 @@ u32 crc32c_le_vgfm_16(u32 crc, unsigned char const *buf, size_t size);
data = (void *)((unsigned long)data + prealign); \ data = (void *)((unsigned long)data + prealign); \
} \ } \
\ \
if (datalen < VX_MIN_LEN) \
return ___crc32_sw(crc, data, datalen); \
\
aligned = datalen & ~VX_ALIGN_MASK; \ aligned = datalen & ~VX_ALIGN_MASK; \
remaining = datalen & VX_ALIGN_MASK; \ remaining = datalen & VX_ALIGN_MASK; \
\ \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment