From d7f6d056cb6fc511e6858a92f3216aac8b9d955f Mon Sep 17 00:00:00 2001 From: cem Date: Thu, 19 Apr 2018 15:24:21 +0000 Subject: [PATCH] cryptosoft: Do not exceed crd_len around *crypt_multi When a caller passes in a uio or mbuf chain that is longer than crd_len, in tandem with a transform that supports the multi-block interface, swcr_encdec() would process the entire mbuf or uio instead of just the portion indicated by crd_len (+ crd_skip). De/encryption are performed in-place, so this would trash subsequent uio or mbuf contents. This was introduced in r331639 (mea culpa). It only affects the {de,en}crypt_multi() family of interfaces. That interface only has one consumer transform in-tree (for now): Chacha20. PR: 227605 Submitted by: Valentin Vergez --- sys/opencrypto/cryptosoft.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sys/opencrypto/cryptosoft.c b/sys/opencrypto/cryptosoft.c index 45dc4d4957f0..1cab483c305b 100644 --- a/sys/opencrypto/cryptosoft.c +++ b/sys/opencrypto/cryptosoft.c @@ -253,7 +253,8 @@ swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf, size_t nb, rem; nb = blks; - rem = uio->uio_iov[ind].iov_len - k; + rem = MIN((size_t)i, + uio->uio_iov[ind].iov_len - (size_t)k); idat = (uint8_t *)uio->uio_iov[ind].iov_base + k; if (exf->reinit) {