From: Herbert Xu Date: Thu, 21 May 2015 07:11:12 +0000 (+0800) Subject: crypto: scatterwalk - Check for same address in map_and_copy X-Git-Tag: v4.1.12-92~3^2~250 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=2352ca7ffcb67c6403a064f17195995d7d5b87f0;p=users%2Fjedix%2Flinux-maple.git crypto: scatterwalk - Check for same address in map_and_copy Orabug: 25243093 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 (cherry picked from commit 74412fd5d71b6eda0beb302aa467da000f0d530c) Signed-off-by: Ethan Zhao --- diff --git a/crypto/scatterwalk.c b/crypto/scatterwalk.c index bd0c8c065b85d..9c5de17d64275 100644 --- a/crypto/scatterwalk.c +++ b/crypto/scatterwalk.c @@ -97,22 +97,18 @@ void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg, unsigned int start, unsigned int nbytes, int out) { struct scatter_walk walk; - unsigned int offset = 0; + struct scatterlist tmp[2]; if (!nbytes) return; - for (;;) { - scatterwalk_start(&walk, sg); - - if (start < offset + sg->length) - break; + sg = scatterwalk_ffwd(tmp, sg, start); - offset += sg->length; - sg = sg_next(sg); - } + if (sg_page(sg) == virt_to_page(buf) && + sg->offset == offset_in_page(buf)) + return; - scatterwalk_advance(&walk, start - offset); + scatterwalk_start(&walk, sg); scatterwalk_copychunks(buf, &walk, nbytes, out); scatterwalk_done(&walk, out, 0); }