crc: Fix for small buffer readover in iscsi crc

Change-Id: Ib4d7e2c6838d490a539a0174b8eb128e4fb49bba
Signed-off-by: Greg Tucker <greg.b.tucker@intel.com>
This commit is contained in:
Greg Tucker 2018-08-15 18:19:02 -07:00
parent bad3a0af87
commit 105eeb967c
4 changed files with 35 additions and 23 deletions

View File

@ -39,7 +39,7 @@
#endif
#define MAX_BUF 512
#define TEST_SIZE 20
#define TEST_SIZE 32
typedef uint32_t(*crc32_func_t) (uint32_t, const uint8_t *, uint64_t);
typedef uint32_t(*crc32_func_t_base) (uint32_t, uint8_t *, uint64_t);
@ -248,9 +248,15 @@ int eob_test(func_case_t * test_func)
int i;
unsigned char *buf = NULL;
// Null test
if (0 != test_func->crc32_func_call(0, NULL, 0)) {
fail++;
printf("crc null test fail\n");
}
buf = (unsigned char *)buf_alloc; //reset buf
buf = buf + ((MAX_BUF - 1) * TEST_SIZE); //Line up TEST_SIZE from end
for (i = 0; i < TEST_SIZE; i++) {
for (i = 0; i <= TEST_SIZE; i++) {
crc = test_func->crc32_func_call(TEST_SEED, buf + i, TEST_SIZE - i);
crc_ref = test_func->crc32_ref_call(TEST_SEED, buf + i, TEST_SIZE - i);
if (crc != crc_ref)

View File

@ -194,6 +194,9 @@ crc32_iscsi_00:
mov rax, crc_init ;; rax = crc_init;
cmp len, 8
jb less_than_8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 1) ALIGN: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -203,9 +206,6 @@ crc32_iscsi_00:
;; amount of the address
je proc_block ;; Skip if aligned
cmp len, 8
jb less_than_8
;;;; Calculate CRC of unaligned bytes of the buffer (if any) ;;;;
mov rbx, [bufptmp] ;; load a quadword from the buffer
add bufptmp, bufp ;; align buffer pointer for
@ -312,19 +312,19 @@ do_return:
less_than_8:
test len,4
jz less_than_4
crc32 eax, dword[bufptmp]
add bufptmp,4
crc32 eax, dword[bufp]
add bufp,4
less_than_4:
test len,2
jz less_than_2
crc32 eax, word[bufptmp]
add bufptmp,2
crc32 eax, word[bufp]
add bufp,2
less_than_2:
test len,1
jz do_return
crc32 rax, byte[bufptmp]
crc32 rax, byte[bufp]
pop rbx
pop bufptmp
pop bufp
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -97,6 +97,11 @@ crc32_iscsi_01:
mov crc_init, crc_init_arg
%endif
;; If len is less than 8 we need to jump to special code to avoid
;; reading beyond the end of the buffer
cmp len, 8
jb less_than_8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 1) ALIGN: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -108,11 +113,6 @@ crc32_iscsi_01:
;; the address
je proc_block ;; Skip if aligned
;; If len is less than 8 and we're unaligned, we need to jump
;; to special code to avoid reading beyond the end of the buffer
cmp len, 8
jb less_than_8
;;;; Calculate CRC of unaligned bytes of the buffer (if any) ;;;
mov tmp, [bufptmp] ;; load a quadword from the buffer
add bufptmp, bufp ;; align buffer pointer for quadword
@ -334,17 +334,17 @@ do_16:
less_than_8:
test len,4
jz less_than_4
crc32 crc_init_dw, dword[bufptmp]
add bufptmp,4
crc32 crc_init_dw, dword[bufp]
add bufp,4
less_than_4:
test len,2
jz less_than_2
crc32 crc_init_dw, word[bufptmp]
add bufptmp,2
crc32 crc_init_dw, word[bufp]
add bufp,2
less_than_2:
test len,1
jz do_return
crc32 crc_init_dw, byte[bufptmp]
crc32 crc_init_dw, byte[bufp]
mov rax, crc_init
pop rsi
pop rdi

View File

@ -39,7 +39,7 @@
#endif
#define MAX_BUF 512
#define TEST_SIZE 20
#define TEST_SIZE 32
typedef uint64_t u64;
typedef uint32_t u32;
@ -243,9 +243,15 @@ int eob_test(func_case_t * test_func)
int i;
unsigned char *buf = NULL;
// Null test
if (0 != test_func->crc64_func_call(0, NULL, 0)) {
fail++;
printf("crc null test fail\n");
}
buf = (unsigned char *)buf_alloc; //reset buf
buf = buf + ((MAX_BUF - 1) * TEST_SIZE); //Line up TEST_SIZE from end
for (i = 0; i < TEST_SIZE; i++) {
for (i = 0; i <= TEST_SIZE; i++) {
crc = test_func->crc64_func_call(TEST_SEED, buf + i, TEST_SIZE - i);
crc_ref = test_func->crc64_ref_call(TEST_SEED, buf + i, TEST_SIZE - i);
if (crc != crc_ref)