Page MenuHomeFreeBSD

D18522.diff
No OneTemporary

D18522.diff

Index: head/sys/crypto/aesni/aesni.c
===================================================================
--- head/sys/crypto/aesni/aesni.c
+++ head/sys/crypto/aesni/aesni.c
@@ -403,29 +403,14 @@
aesni_cipher_alloc(struct cryptodesc *enccrd, struct cryptop *crp,
bool *allocated)
{
- struct mbuf *m;
- struct uio *uio;
- struct iovec *iov;
uint8_t *addr;
- if (crp->crp_flags & CRYPTO_F_IMBUF) {
- m = (struct mbuf *)crp->crp_buf;
- if (m->m_next != NULL)
- goto alloc;
- addr = mtod(m, uint8_t *);
- } else if (crp->crp_flags & CRYPTO_F_IOV) {
- uio = (struct uio *)crp->crp_buf;
- if (uio->uio_iovcnt != 1)
- goto alloc;
- iov = uio->uio_iov;
- addr = (uint8_t *)iov->iov_base;
- } else
- addr = (uint8_t *)crp->crp_buf;
- *allocated = false;
- addr += enccrd->crd_skip;
- return (addr);
-
-alloc:
+ addr = crypto_contiguous_subsegment(crp->crp_flags,
+ crp->crp_buf, enccrd->crd_skip, enccrd->crd_len);
+ if (addr != NULL) {
+ *allocated = false;
+ return (addr);
+ }
addr = malloc(enccrd->crd_len, M_AESNI, M_NOWAIT);
if (addr != NULL) {
*allocated = true;
Index: head/sys/opencrypto/criov.c
===================================================================
--- head/sys/opencrypto/criov.c
+++ head/sys/opencrypto/criov.c
@@ -38,6 +38,8 @@
#include <sys/kernel.h>
#include <sys/mbuf.h>
#include <sys/uio.h>
+#include <sys/limits.h>
+#include <sys/lock.h>
#include <opencrypto/cryptodev.h>
@@ -239,3 +241,55 @@
*cnt = i;
return 0;
}
+
+static inline void *
+m_contiguous_subsegment(struct mbuf *m, size_t skip, size_t len)
+{
+ int rel_off;
+
+ MPASS(skip <= INT_MAX);
+
+ m = m_getptr(m, (int)skip, &rel_off);
+ if (m == NULL)
+ return (NULL);
+
+ MPASS(rel_off >= 0);
+ skip = rel_off;
+ if (skip + len > m->m_len)
+ return (NULL);
+
+ return (mtod(m, char*) + skip);
+}
+
+static inline void *
+cuio_contiguous_segment(struct uio *uio, size_t skip, size_t len)
+{
+ int rel_off, idx;
+
+ MPASS(skip <= INT_MAX);
+ idx = cuio_getptr(uio, (int)skip, &rel_off);
+ if (idx < 0)
+ return (NULL);
+
+ MPASS(rel_off >= 0);
+ skip = rel_off;
+ if (skip + len > uio->uio_iov[idx].iov_len)
+ return (NULL);
+ return ((char *)uio->uio_iov[idx].iov_base + skip);
+}
+
+void *
+crypto_contiguous_subsegment(int crp_flags, void *crpbuf,
+ size_t skip, size_t len)
+{
+ if ((crp_flags & CRYPTO_F_IMBUF) != 0)
+ return (m_contiguous_subsegment(crpbuf, skip, len));
+ else if ((crp_flags & CRYPTO_F_IOV) != 0)
+ return (cuio_contiguous_segment(crpbuf, skip, len));
+ else {
+ MPASS((crp_flags & (CRYPTO_F_IMBUF | CRYPTO_F_IOV)) !=
+ (CRYPTO_F_IMBUF | CRYPTO_F_IOV));
+ return ((char*)crpbuf + skip);
+ }
+}
+
Index: head/sys/opencrypto/cryptodev.h
===================================================================
--- head/sys/opencrypto/cryptodev.h
+++ head/sys/opencrypto/cryptodev.h
@@ -564,5 +564,7 @@
extern int crypto_apply(int flags, caddr_t buf, int off, int len,
int (*f)(void *, void *, u_int), void *arg);
+extern void *crypto_contiguous_subsegment(int, void *, size_t, size_t);
+
#endif /* _KERNEL */
#endif /* _CRYPTO_CRYPTO_H_ */

File Metadata

Mime Type
text/plain
Expires
Sat, Jan 11, 8:43 AM (19 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15752206
Default Alt Text
D18522.diff (3 KB)

Event Timeline