Skip to content

Commit 74412fd

Browse files
committed
crypto: scatterwalk - Check for same address in map_and_copy
This patch adds a check for in scatterwalk_map_and_copy to avoid copying from the same address to the same address. This is going to be used for IV copying in AEAD IV generators. There is no provision for partial overlaps. This patch also uses the new scatterwalk_ffwd instead of doing it by hand in scatterwalk_map_and_copy. Signed-off-by: Herbert Xu <[email protected]>
1 parent 17db854 commit 74412fd

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

crypto/scatterwalk.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,18 @@ void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg,
104104
unsigned int start, unsigned int nbytes, int out)
105105
{
106106
struct scatter_walk walk;
107-
unsigned int offset = 0;
107+
struct scatterlist tmp[2];
108108

109109
if (!nbytes)
110110
return;
111111

112-
for (;;) {
113-
scatterwalk_start(&walk, sg);
114-
115-
if (start < offset + sg->length)
116-
break;
112+
sg = scatterwalk_ffwd(tmp, sg, start);
117113

118-
offset += sg->length;
119-
sg = sg_next(sg);
120-
}
114+
if (sg_page(sg) == virt_to_page(buf) &&
115+
sg->offset == offset_in_page(buf))
116+
return;
121117

122-
scatterwalk_advance(&walk, start - offset);
118+
scatterwalk_start(&walk, sg);
123119
scatterwalk_copychunks(buf, &walk, nbytes, out);
124120
scatterwalk_done(&walk, out, 0);
125121
}

0 commit comments

Comments
 (0)