Skip to content

Commit 002ba34

Browse files
committed
crypto: scomp - Fix off-by-one bug when calculating last page
Fix off-by-one bug in the last page calculation for src and dst. Reported-by: Nhat Pham <[email protected]> Fixes: 2d3553e ("crypto: scomp - Remove support for some non-trivial SG lists") Signed-off-by: Herbert Xu <[email protected]>
1 parent aece1cf commit 002ba34

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

crypto/scompress.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
215215
spage = nth_page(spage, soff / PAGE_SIZE);
216216
soff = offset_in_page(soff);
217217

218-
n = slen / PAGE_SIZE;
219-
n += (offset_in_page(slen) + soff - 1) / PAGE_SIZE;
218+
n = (slen - 1) / PAGE_SIZE;
219+
n += (offset_in_page(slen - 1) + soff) / PAGE_SIZE;
220220
if (PageHighMem(nth_page(spage, n)) &&
221221
size_add(soff, slen) > PAGE_SIZE)
222222
break;
@@ -243,9 +243,9 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
243243
dpage = nth_page(dpage, doff / PAGE_SIZE);
244244
doff = offset_in_page(doff);
245245

246-
n = dlen / PAGE_SIZE;
247-
n += (offset_in_page(dlen) + doff - 1) / PAGE_SIZE;
248-
if (PageHighMem(dpage + n) &&
246+
n = (dlen - 1) / PAGE_SIZE;
247+
n += (offset_in_page(dlen - 1) + doff) / PAGE_SIZE;
248+
if (PageHighMem(nth_page(dpage, n)) &&
249249
size_add(doff, dlen) > PAGE_SIZE)
250250
break;
251251
dst = kmap_local_page(dpage) + doff;

0 commit comments

Comments
 (0)