Skip to content

Commit d958274

Browse files
smuellerDDgregkh
authored andcommitted
crypto: algif_skcipher - only call put_page on referenced and used pages
commit 445a582738de6802669aeed9c33ca406c23c3b1f upstream. For asynchronous operation, SGs are allocated without a page mapped to them or with a page that is not used (ref-counted). If the SGL is freed, the code must only call put_page for an SG if there was a page assigned and ref-counted in the first place. This fixes a kernel crash when using io_submit with more than one iocb using the sendmsg and sendpage (vmsplice/splice) interface. Signed-off-by: Stephan Mueller <smueller@chronox.de> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ab3ee6b commit d958274

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

crypto/algif_skcipher.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,13 @@ static void skcipher_free_async_sgls(struct skcipher_async_req *sreq)
8686
}
8787
sgl = sreq->tsg;
8888
n = sg_nents(sgl);
89-
for_each_sg(sgl, sg, n, i)
90-
put_page(sg_page(sg));
89+
for_each_sg(sgl, sg, n, i) {
90+
struct page *page = sg_page(sg);
91+
92+
/* some SGs may not have a page mapped */
93+
if (page && atomic_read(&page->_count))
94+
put_page(page);
95+
}
9196

9297
kfree(sreq->tsg);
9398
}

0 commit comments

Comments
 (0)