Skip to content

Commit 0882db3

Browse files
authored
Merge pull request #3455 from cenewcombe/develop
Fix unsafe read during final iteration of zsymv_L_sse2.S
2 parents 454edd7 + feeb828 commit 0882db3

File tree

2 files changed

+99
-2
lines changed

2 files changed

+99
-2
lines changed

kernel/x86_64/zsymv_L_sse2.S

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,6 @@
451451
#endif
452452

453453
MOVDDUP(4 * SIZE, A1, a1)
454-
MOVDDUP(6 * SIZE, A2, a2)
455454

456455
movsd 0 * SIZE(YY), yy1
457456
movhpd 1 * SIZE(YY), yy1
@@ -471,7 +470,9 @@
471470
subq IS, I
472471
subq $2, I
473472
sarq $2, I
474-
jle .L15
473+
jle .L14
474+
475+
MOVDDUP(6 * SIZE - (4 * SIZE), A2, a2)
475476
ALIGN_3
476477

477478
.L12:
@@ -632,13 +633,24 @@
632633
jg .L12
633634
ALIGN_3
634635

636+
.L14:
637+
movq M, I
638+
subq IS, I
639+
subq $2, I
640+
testq $2, I
641+
jle .L16
642+
643+
MOVDDUP(6 * SIZE - (4 * SIZE), A2, a2)
644+
jmp .L15_pastcheck
645+
635646
.L15:
636647
movq M, I
637648
subq IS, I
638649
subq $2, I
639650
testq $2, I
640651
jle .L16
641652

653+
.L15_pastcheck:
642654
movapd xtemp1, xt1
643655
mulpd a1, xt1
644656
mulpd atemp1, a1

test_zhemv.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// reproduce segfault in zhemv() from zsymv_L_sse2.S
2+
//
3+
4+
#include <stdlib.h>
5+
#include <stdio.h>
6+
#include <math.h>
7+
#include <string.h>
8+
#include <complex.h>
9+
#include <sys/mman.h>
10+
11+
#define CALL_ZHEMV zhemv_
12+
13+
void zhemv_(char *UPLO, int *N, double *alpha, double *A, int *LDA,
14+
double *X, int *INCX, double *beta, double *Y, int *INCY);
15+
16+
int main () {
17+
18+
// zhemv parameters
19+
char uplo = 'L';
20+
int n = 14;
21+
int lda = 16;
22+
int incx = 1;
23+
int incy = 1;
24+
double *A, *X, *Y;
25+
double alpha[] = {1, 0};
26+
double beta[] = {0, 0};
27+
28+
// other parameters
29+
int i, j;
30+
double *data, *data_end, *no_access;
31+
double real, imag;
32+
int size;
33+
size_t len;
34+
int A_offset;
35+
36+
size = sizeof(complex double);
37+
len = lda * lda * size;
38+
39+
// allocate memory for data
40+
// use mmap address hints to set up inaccessible memory section following data
41+
no_access = mmap(NULL, len, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
42+
data = mmap(no_access, len, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
43+
data_end = data + (lda * lda * 2);
44+
printf("data start/end: %p/%p. Blocked region starts at %p.\n", data, data_end, no_access);
45+
46+
// set up pointer offsets into data
47+
A_offset = (lda + 1) * 2;
48+
A = data + A_offset * 2; // A starts in the third column of data matrix
49+
X = data + A_offset + 2; // X is the second column of data matrix
50+
Y = (double *)malloc(n * incy * size); // Y is stored elsewhere
51+
printf("Address of data: %p; A: %p; X: %p; Y: %p.\n", data, A, X, Y);
52+
53+
54+
// hermitian matrix
55+
srand(lda);
56+
for (j=0; j<lda; j++) {
57+
real = (double) rand() / RAND_MAX;
58+
imag = 0;
59+
data[(j*lda + j) * 2] = real;
60+
data[(j*lda + j) * 2 + 1] = imag;
61+
for (i=j+1; i<lda; i++) {
62+
real = (double) rand() / RAND_MAX;
63+
imag = (double) rand() / RAND_MAX;
64+
data[(j*lda + i) * 2] = real;
65+
data[(j*lda + i) * 2 + 1] = imag;
66+
data[(i*lda + j) * 2] = real;
67+
data[(i*lda + j) * 2 + 1] = -imag;
68+
}
69+
}
70+
71+
for (int i=0; i<incy*n*2; i++) {
72+
Y[i] = 0;
73+
}
74+
75+
CALL_ZHEMV(&uplo, &n, alpha, A, &lda, X, &incx, beta, Y, &incy);
76+
77+
printf("Finished call to zhemv.\n");
78+
79+
munmap(no_access, len);
80+
munmap(data, len);
81+
82+
}
83+
84+
85+

0 commit comments

Comments
 (0)