Skip to contentSkip to conversation

crypto: acomp - fix dst-folio branch setting src instead of dst in acomp_virt_to_sg

PATCH In review Aaron Esau 2 participants 4 messages May 7 – May 8

Subsystems (2)
lore
Share & tools
lore

Aaron Esau

author
#0 lore raw

PATCH 1/1 crypto: acomp - fix dst-folio branch setting src instead of dst in acomp_virt_to_sg

In acomp_virt_to_sg(), the dst_isfolio branch calls acomp_request_set_src_sg() instead of acomp_request_set_dst_sg(). This overwrites req->src with the destination folio SG and leaves req->dst holding a raw struct folio pointer (via the src/dst union). The algorithm then reads from the wrong buffer and dereferences the stale folio pointer as a scatterlist.

The bug is reachable from UBIFS decompression on systems with a hardware compression accelerator (HiSilicon ZIP, Intel IAA, Intel QAT), where crypto_alloc_acomp() selects the hardware driver over scompress. Software scompress backends are unaffected because they set CRYPTO_ALG_REQ_CHAIN and bypass acomp_virt_to_sg() entirely.

Fixes 8a6771cda3f4 ("crypto: acomp - Add support for folios")
---
 crypto/acompress.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/acompress.c +1 -1
index f7a3fbe54..5a8b0cf3a 100644
@@ -237,7 +237,7 @@ static void acomp_virt_to_sg(struct acomp_req *req)
 		sg_init_table(&state->dsg, 1);
 		sg_set_page(&state->dsg, folio_page(folio, off / PAGE_SIZE),
 			    dlen, off % PAGE_SIZE);
-		acomp_request_set_src_sg(req, &state->dsg, dlen);
+		acomp_request_set_dst_sg(req, &state->dsg, dlen);
 	}
 }
 
Signature · 1 line
2.53.0
maintainer
#1 lore raw

crypto/acompress.c static void acomp_virt_to_sg(struct acomp_req *req) · line 242

Quoted 13 lines · Aaron Esau
crypto/acompress.c +1 -1
index f7a3fbe54..5a8b0cf3a 100644
@@ -237,7 +237,7 @@ static void acomp_virt_to_sg(struct acomp_req *req)
 		sg_init_table(&state->dsg, 1);
 		sg_set_page(&state->dsg, folio_page(folio, off / PAGE_SIZE),
 			    dlen, off % PAGE_SIZE);
-		acomp_request_set_src_sg(req, &state->dsg, dlen);
+		acomp_request_set_dst_sg(req, &state->dsg, dlen);
 	}
 }

This patch doesn't apply against mainline. In fact the code that you're referencing does not exist on mainline.

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
author
#2 lore raw

Hi Herbert,

The patch was generated against v6.15-rc6 (82f2b0b97). The buggy line is at crypto/acompress.c:240 in that tag, and the index hash f7a3fbe54 matched (I just checked again).

Could you double-check?

Thanks,
Aaron

maintainer
#3 lore raw
Quoted 6 lines · Aaron Esau

The patch was generated against v6.15-rc6 (82f2b0b97). The buggy line is at crypto/acompress.c:240 in that tag, and the index hash f7a3fbe54 matched (I just checked again).

Could you double-check?

We're currently at v7.0 heading towards v7.1. The bug that you're reporting does not exist in v7.0.

Cheers,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt