From: Alexey Shabalin <shaba@altlinux.org>
To: devel-kernel@altlinux.org
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Subject: [d-kernel] [PATCH 6.12/sisyphus 16/29] crypto: krb5 - Use SG miter instead of doing it by hand
Date: Wed, 18 Nov 2026 14:45:05 +0300
Message-ID: <20261118114518.3605222-17-shaba@altlinux.org> (raw)
In-Reply-To: <20261118114518.3605222-1-shaba@altlinux.org>
From: Herbert Xu <herbert@gondor.apana.org.au>
The function crypto_shash_update_sg iterates through an SG by
hand. It fails to handle corner cases such as SG entries longer
than a page. Fix this by using the SG iterator.
Fixes: 348f5669d1f6 ("crypto/krb5: Implement the Kerberos5 rfc3961 get_mic and verify_mic")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
(cherry picked from commit da6f9bf40ac267b5c720694a817beea84fa40f77)
---
crypto/krb5/rfc3961_simplified.c | 37 ++++++++++++++------------------
1 file changed, 16 insertions(+), 21 deletions(-)
diff --git a/crypto/krb5/rfc3961_simplified.c b/crypto/krb5/rfc3961_simplified.c
index c1dcb0dd3a00..79180d28baa9 100644
--- a/crypto/krb5/rfc3961_simplified.c
+++ b/crypto/krb5/rfc3961_simplified.c
@@ -67,9 +67,9 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/random.h>
+#include <linux/scatterlist.h>
#include <linux/skbuff.h>
#include <linux/slab.h>
-#include <linux/highmem.h>
#include <linux/lcm.h>
#include <linux/rtnetlink.h>
#include <crypto/authenc.h>
@@ -83,26 +83,21 @@
int crypto_shash_update_sg(struct shash_desc *desc, struct scatterlist *sg,
size_t offset, size_t len)
{
- do {
- int ret;
-
- if (offset < sg->length) {
- struct page *page = sg_page(sg);
- void *p = kmap_local_page(page);
- void *q = p + sg->offset + offset;
- size_t seg = min_t(size_t, len, sg->length - offset);
-
- ret = crypto_shash_update(desc, q, seg);
- kunmap_local(p);
- if (ret < 0)
- return ret;
- len -= seg;
- offset = 0;
- } else {
- offset -= sg->length;
- }
- } while (len > 0 && (sg = sg_next(sg)));
- return 0;
+ struct sg_mapping_iter miter;
+ size_t i, n;
+ int ret = 0;
+
+ sg_miter_start(&miter, sg, sg_nents(sg),
+ SG_MITER_FROM_SG | SG_MITER_LOCAL);
+ for (i = 0; i < len; i += n) {
+ sg_miter_next(&miter);
+ n = min(miter.length, len - i);
+ ret = crypto_shash_update(desc, miter.addr, n);
+ if (ret < 0)
+ break;
+ }
+ sg_miter_stop(&miter);
+ return ret;
}
static int rfc3961_do_encrypt(struct crypto_sync_skcipher *tfm, void *iv,
--
2.50.1
next prev parent reply other threads:[~2026-11-18 11:45 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 11:44 [d-kernel] [PATCH 6.12/sisyphus 0/29] libceph: add support for AES256KRB5 (aes256k) cephx keys Alexey Shabalin
2026-11-18 11:45 ` [d-kernel] [PATCH 6.12/sisyphus 15/29] lib/scatterlist: Add SG_MITER_LOCAL and use it Alexey Shabalin
2026-11-18 11:45 ` Alexey Shabalin [this message]
2026-11-18 11:45 ` [d-kernel] [PATCH 6.12/sisyphus 17/29] crypto/krb5: Fix change to use SG miter to use offset Alexey Shabalin
2026-11-18 11:45 ` [d-kernel] [PATCH 6.12/sisyphus 18/29] crypto: krb5 - Fix memory leak in krb5_test_one_prf() Alexey Shabalin
2026-11-18 11:45 ` [d-kernel] [PATCH 6.12/sisyphus 21/29] crypto: krb5 - filter out async aead implementations at alloc Alexey Shabalin
2026-11-18 11:45 ` [d-kernel] [PATCH 6.12/sisyphus 22/29] crypto: krb5 - use kfree_sensitive() for derived key buffers Alexey Shabalin
2026-11-18 11:45 ` [d-kernel] [PATCH 6.12/sisyphus 23/29] libceph: Rename hmac_sha256() to ceph_hmac_sha256() Alexey Shabalin
2026-11-18 11:45 ` [d-kernel] [PATCH 6.12/sisyphus 24/29] libceph: generalize ceph_x_encrypt_offset() and ceph_x_encrypt_buflen() Alexey Shabalin
2026-11-18 11:45 ` [d-kernel] [PATCH 6.12/sisyphus 25/29] libceph: Remove unused ceph_crypto_key_encode Alexey Shabalin
2026-11-18 11:45 ` [d-kernel] [PATCH 6.12/sisyphus 26/29] libceph: introduce ceph_crypto_key_prepare() Alexey Shabalin
2026-11-18 11:45 ` [d-kernel] [PATCH 6.12/sisyphus 27/29] libceph: add support for CEPH_CRYPTO_AES256KRB5 Alexey Shabalin
2026-11-18 11:45 ` [d-kernel] [PATCH 6.12/sisyphus 28/29] libceph: adapt ceph_x_challenge_blob hashing and msgr1 message signing Alexey Shabalin
2026-11-18 11:45 ` [d-kernel] [PATCH 6.12/sisyphus 29/29] config: enable CONFIG_CRYPTO_KRB5 Alexey Shabalin
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=20261118114518.3605222-17-shaba@altlinux.org \
--to=shaba@altlinux.org \
--cc=devel-kernel@altlinux.org \
--cc=devel-kernel@lists.altlinux.org \
--cc=herbert@gondor.apana.org.au \
/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
ALT Linux kernel packages development
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/devel-kernel/0 devel-kernel/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 devel-kernel devel-kernel/ http://lore.altlinux.org/devel-kernel \
devel-kernel@altlinux.org devel-kernel@altlinux.ru devel-kernel@altlinux.com
public-inbox-index devel-kernel
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.devel-kernel
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git