]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
crypto: af_alg - Fix page reassignment overflow in af_alg_pull_tsgl
authorHerbert Xu <herbert@gondor.apana.org.au>
Thu, 30 Apr 2026 06:36:03 +0000 (23:36 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 30 Apr 2026 09:24:38 +0000 (11:24 +0200)
commit 31d00156e50ecad37f2cb6cbf04aaa9a260505ef upstream.

When page reassignment was added to af_alg_pull_tsgl the original
loop wasn't updated so it may try to reassign one more page than
necessary.

Add the check to the reassignment so that this does not happen.

Also update the comment which still refers to the obsolete offset
argument.

Reported-by: syzbot+d23888375c2737c17ba5@syzkaller.appspotmail.com
Fixes: e870456d8e7c ("crypto: algif_skcipher - overhaul memory management")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
crypto/af_alg.c

index 4f667a503277100ae039ae21c1644ba7404943a9..8f7cf57da8f630681de0b434029b5e55b819df52 100644 (file)
@@ -597,8 +597,8 @@ void af_alg_pull_tsgl(struct sock *sk, size_t used, struct scatterlist *dst)
                         * Assumption: caller created af_alg_count_tsgl(len)
                         * SG entries in dst.
                         */
-                       if (dst) {
-                               /* reassign page to dst after offset */
+                       if (dst && plen) {
+                               /* reassign page to dst */
                                get_page(page);
                                sg_set_page(dst + j, page, plen, sg[i].offset);
                                j++;