From: sashiko-bot@kernel.org
To: "Kanchana P. Sridhar" <kanchanapsridhar2026@gmail.com>,
hannes@cmpxchg.org, yosry@kernel.org, nphamcs@gmail.com,
chengming.zhou@linux.dev, akpm@linux-foundation.org,
linux-mm@kvack.org, herbert@gondor.apana.org.au,
davem@davemloft.net, linux-crypto@vger.kernel.org
Cc: rientjes@google.com, willy@infradead.org, senozhatsky@chromium.org
Subject: Re: [PATCH v3 3/8] crypto: acomp - Add trivial segmentation wrapper.
Date: Sat, 07 Nov 2026 07:25:05 +0000 [thread overview]
Message-ID: <sashiko-outbox-202709@kernel.org> (raw)
In-Reply-To: <20261106072412.7909-4-kanchanapsridhar2026@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] crypto: acomp - missing non-zero unit_size check in
crypto_acomp_compress()
- [Medium] crypto: acomp - union type confusion in
acomp_reqchain_finish() on virt dst
--
commit c2a605231cabd5e0e15d6d778b3943a2c118d756
Author: Kanchana P. Sridhar <kanchanapsridhar2026@gmail.com>
crypto: acomp - Add trivial segmentation wrapper.
This commit adds a single-segment compression wrapper for algorithms that do
not natively support segmentation, returning the compressed length or error
in req->dst->length when req->unit_size is set.
> diff --git a/crypto/acompress.c b/crypto/acompress.c
> index c8b4b8589769e..ac4dc52668b89 100644
> --- a/crypto/acompress.c
> +++ b/crypto/acompress.c
[ ... ]
> @@ -242,6 +246,10 @@ static int acomp_reqchain_finish(struct acomp_req *req, int err)
> {
> acomp_reqchain_virt(req);
> acomp_restore_req(req);
> +
> + if (req->unit_size)
> + req->dst->length = unlikely(err) ? err : req->dlen;
> +
> return err;
> }
>
> @@ -266,10 +274,13 @@ static int acomp_do_req_chain(struct acomp_req *req, bool comp)
> {
> int err;
>
> + if (unlikely(req->unit_size && req->slen > req->unit_size))
> + return -ENOSYS;
[Severity: Medium]
Can acomp_reqchain_finish() corrupt the destination buffer when a request
with a non-zero req->unit_size uses virtual addresses?
In struct acomp_req, dst and dvirt share an anonymous union. When
acomp_do_req_chain() handles a virtual-address request
(CRYPTO_ACOMP_REQ_DST_VIRT), acomp_reqchain_virt() restores the raw u8 *
buffer pointer into req->dvirt before acomp_restore_req() restores
req->unit_size. Writing to req->dst->length then treats req->dvirt as a
struct scatterlist * and overwrites 4 bytes inside the caller's output
buffer.
In addition, acomp_do_req_chain() is called for decompression (comp == false),
so a decompression request with req->unit_size set will also hit the
compression-only req->slen > req->unit_size check and write to
req->dst->length.
> acomp_save_req(req, acomp_reqchain_done);
>
> err = acomp_do_one_req(req, comp);
> - if (err == -EBUSY || err == -EINPROGRESS)
> + if (unlikely(err == -EBUSY || err == -EINPROGRESS))
> return err;
>
> return acomp_reqchain_finish(req, err);
> @@ -279,10 +290,27 @@ int crypto_acomp_compress(struct acomp_req *req)
> {
> struct crypto_acomp *tfm = crypto_acomp_reqtfm(req);
>
> + if (likely((req->unit_size == req->slen) && acomp_request_issg(req) &&
> + !crypto_acomp_req_seg(tfm) && !acomp_is_async(tfm))) {
> + int err = tfm->compress(req);
> +
> + req->dst->length = unlikely(err) ? err : req->dlen;
> + return err;
> + }
[Severity: Medium]
Should this fast-path check also verify that req->unit_size is non-zero?
Callers that do not use segmentation leave req->unit_size at 0. If such a
caller submits a scatterlist request with req->slen == 0 on a synchronous
non-segmented transform, req->unit_size == req->slen is true, so
crypto_acomp_compress() enters the segmentation path and writes the negative
error from tfm->compress(req) into req->dst->length, corrupting the caller's
scatterlist or causing a NULL pointer dereference if req->dst is NULL (which
can also happen when req->unit_size is non-zero and req->dst is NULL here or
in acomp_reqchain_finish()).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261106072412.7909-1-kanchanapsridhar2026@gmail.com?part=3
next prev parent reply other threads:[~2026-11-07 7:25 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 7:24 [PATCH v3 0/8] Batched zswap_store() framework with compression batching Kanchana P. Sridhar
2026-11-06 7:24 ` [PATCH v3 1/8] crypto: acomp - Define a unit_size in struct acomp_req to enable batching. mm: zswap: Set the unit size for zswap to PAGE_SIZE Kanchana P. Sridhar
2026-11-06 7:24 ` [PATCH v3 2/8] crypto: acomp - Add bit to indicate segmentation support Kanchana P. Sridhar
2026-11-06 7:24 ` [PATCH v3 3/8] crypto: acomp - Add trivial segmentation wrapper Kanchana P. Sridhar
2026-11-07 7:25 ` sashiko-bot [this message]
2026-11-06 7:24 ` [PATCH v3 4/8] crypto: acomp - Add API to get a compression algorithm's batch-size Kanchana P. Sridhar
2026-11-07 7:25 ` sashiko-bot
2026-11-06 7:24 ` [PATCH v3 5/8] mm: zswap: Store the folio's node id in the zswap_entry Kanchana P. Sridhar
2026-11-07 7:25 ` sashiko-bot
2026-11-06 7:24 ` [PATCH v3 6/8] mm: zswap: Store large folios in batches Kanchana P. Sridhar
2026-11-06 7:24 ` [PATCH v3 7/8] mm: zswap: Refactor and optimize zswap_store_pages() batch operations Kanchana P. Sridhar
2026-11-07 7:25 ` sashiko-bot
2026-11-06 7:24 ` [PATCH v3 8/8] mm: zswap: Batched zswap_compress() for storing large folios in batches Kanchana P. Sridhar
2026-11-07 7:25 ` sashiko-bot
2026-11-06 23:59 ` [PATCH v3 0/8] Batched zswap_store() framework with compression batching Yosry Ahmed
2026-11-07 1:28 ` Kanchana P. Sridhar
2026-11-09 16:23 ` Yosry Ahmed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-202709@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=davem@davemloft.net \
--cc=hannes@cmpxchg.org \
--cc=herbert@gondor.apana.org.au \
--cc=kanchanapsridhar2026@gmail.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=rientjes@google.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=senozhatsky@chromium.org \
--cc=willy@infradead.org \
--cc=yosry@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.