CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Tue Jul 11 10:42:16 UTC 2023 Modified Files: src/sys/opencrypto: cryptodev.h Log Message: opencrypto/cryptodev.h: Fix includes. - Move sys/condvar.h under #ifdef _KERNEL. - Add some other necessary includes and forward declarations. - Sort. To generate a diff of this commit: cvs rdiff -u -r1.50 -r1.51 src/sys/opencrypto/cryptodev.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Tue Jul 11 10:42:16 UTC 2023 Modified Files: src/sys/opencrypto: cryptodev.h Log Message: opencrypto/cryptodev.h: Fix includes. - Move sys/condvar.h under #ifdef _KERNEL. - Add some other necessary includes and forward declarations. - Sort. To generate a diff of this commit: cvs rdiff -u -r1.50 -r1.51 src/sys/opencrypto/cryptodev.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptodev.h diff -u src/sys/opencrypto/cryptodev.h:1.50 src/sys/opencrypto/cryptodev.h:1.51 --- src/sys/opencrypto/cryptodev.h:1.50 Sun May 22 11:40:29 2022 +++ src/sys/opencrypto/cryptodev.h Tue Jul 11 10:42:16 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.h,v 1.50 2022/05/22 11:40:29 riastradh Exp $ */ +/* $NetBSD: cryptodev.h,v 1.51 2023/07/11 10:42:16 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.h,v 1.2.2.6 2003/07/02 17:04:50 sam Exp $ */ /* $OpenBSD: cryptodev.h,v 1.33 2002/07/17 23:52:39 art Exp $ */ @@ -85,8 +85,9 @@ #ifndef _CRYPTO_CRYPTO_H_ #define _CRYPTO_CRYPTO_H_ +#include + #include -#include #include #if defined(_KERNEL_OPT) @@ -409,6 +410,16 @@ struct cryptostats { }; #ifdef _KERNEL + +#include +#include +#include +#include +#include + +struct cpu_info; +struct uio; + /* Standard initialization structure beginning */ struct cryptoini { int cri_alg; /* Algorithm to use */
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun Jun 26 22:52:30 UTC 2022 Modified Files: src/sys/opencrypto: crypto.c Log Message: opencrypto(9): Fix missing initialization in error branch. Reported-by: syzbot+8c519140cac567be1...@syzkaller.appspotmail.com To generate a diff of this commit: cvs rdiff -u -r1.130 -r1.131 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/crypto.c diff -u src/sys/opencrypto/crypto.c:1.130 src/sys/opencrypto/crypto.c:1.131 --- src/sys/opencrypto/crypto.c:1.130 Sun May 22 11:40:54 2022 +++ src/sys/opencrypto/crypto.c Sun Jun 26 22:52:30 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: crypto.c,v 1.130 2022/05/22 11:40:54 riastradh Exp $ */ +/* $NetBSD: crypto.c,v 1.131 2022/06/26 22:52:30 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $ */ /* $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */ @@ -53,7 +53,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.130 2022/05/22 11:40:54 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.131 2022/06/26 22:52:30 riastradh Exp $"); #include #include @@ -1485,6 +1485,7 @@ crypto_kinvoke(struct cryptkop *krp, int return error; } else { krp->krp_status = ENODEV; + krp->reqcpu = curcpu(); crypto_kdone(krp); return 0; }
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun Jun 26 22:52:30 UTC 2022 Modified Files: src/sys/opencrypto: crypto.c Log Message: opencrypto(9): Fix missing initialization in error branch. Reported-by: syzbot+8c519140cac567be1...@syzkaller.appspotmail.com To generate a diff of this commit: cvs rdiff -u -r1.130 -r1.131 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:40:54 UTC 2022 Modified Files: src/sys/opencrypto: crypto.c Log Message: opencrypto: Assert session id is valid in crypto_freesession. This gives us the opportunity to detect usage mistakes like use-after-free. Exception: Continue to silently ignore sid=0. To generate a diff of this commit: cvs rdiff -u -r1.129 -r1.130 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/crypto.c diff -u src/sys/opencrypto/crypto.c:1.129 src/sys/opencrypto/crypto.c:1.130 --- src/sys/opencrypto/crypto.c:1.129 Sun May 22 11:40:29 2022 +++ src/sys/opencrypto/crypto.c Sun May 22 11:40:54 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: crypto.c,v 1.129 2022/05/22 11:40:29 riastradh Exp $ */ +/* $NetBSD: crypto.c,v 1.130 2022/05/22 11:40:54 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $ */ /* $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */ @@ -53,7 +53,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.129 2022/05/22 11:40:29 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.130 2022/05/22 11:40:54 riastradh Exp $"); #include #include @@ -870,11 +870,10 @@ crypto_freesession(u_int64_t sid) /* Determine two IDs. */ cap = crypto_checkdriver_lock(CRYPTO_SESID2HID(sid)); - if (cap == NULL) /* XXX should assert; need to audit callers */ - return; + KASSERTMSG(cap != NULL, "sid=%"PRIx64, sid); - if (cap->cc_sessions) - (cap->cc_sessions)--; + KASSERT(cap->cc_sessions > 0); + cap->cc_sessions--; /* Call the driver cleanup routine, if available. */ if (cap->cc_freesession)
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:40:54 UTC 2022 Modified Files: src/sys/opencrypto: crypto.c Log Message: opencrypto: Assert session id is valid in crypto_freesession. This gives us the opportunity to detect usage mistakes like use-after-free. Exception: Continue to silently ignore sid=0. To generate a diff of this commit: cvs rdiff -u -r1.129 -r1.130 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:40:38 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: opencrypto: Prune dead code now that crypto_dispatch never fails. To generate a diff of this commit: cvs rdiff -u -r1.123 -r1.124 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptodev.c diff -u src/sys/opencrypto/cryptodev.c:1.123 src/sys/opencrypto/cryptodev.c:1.124 --- src/sys/opencrypto/cryptodev.c:1.123 Sun May 22 11:40:29 2022 +++ src/sys/opencrypto/cryptodev.c Sun May 22 11:40:38 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.c,v 1.123 2022/05/22 11:40:29 riastradh Exp $ */ +/* $NetBSD: cryptodev.c,v 1.124 2022/05/22 11:40:38 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */ /* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */ @@ -64,7 +64,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.123 2022/05/22 11:40:29 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.124 2022/05/22 11:40:38 riastradh Exp $"); #include #include @@ -1292,30 +1292,8 @@ cryptodev_mop(struct fcrypt *fcr, crp->crp_reqid = cnop[req].reqid; crp->crp_usropaque = cnop[req].opaque; cv_init(>crp_cv, "crydev"); -#ifdef notyet -eagain: -#endif crypto_dispatch(crp); cnop[req].status = 0; - mutex_enter(_mtx); /* XXX why mutex? */ - - switch (cnop[req].status) { -#ifdef notyet /* don't loop forever -- but EAGAIN not possible here yet */ - case EAGAIN: - mutex_exit(_mtx); - goto eagain; - break; -#endif - case 0: - break; - default: - DPRINTF("not waiting, error.\n"); - mutex_exit(_mtx); - cv_destroy(>crp_cv); - goto bail; - } - - mutex_exit(_mtx); cv_destroy(>crp_cv); bail: if (cnop[req].status) {
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:40:38 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: opencrypto: Prune dead code now that crypto_dispatch never fails. To generate a diff of this commit: cvs rdiff -u -r1.123 -r1.124 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:40:15 UTC 2022 Modified Files: src/sys/opencrypto: crypto.c Log Message: opencrypto: Assert driver process routine returns 0 or ERESTART. No other errors are allowed -- other errors must be transmitted by crypto_done. All drivers in tree (sun8i_crypto, glxsb, via_padlock, mvcesa, mvxpsec, hifn, qat, ubsec, cryptosoft) have been audited for this. To generate a diff of this commit: cvs rdiff -u -r1.127 -r1.128 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/crypto.c diff -u src/sys/opencrypto/crypto.c:1.127 src/sys/opencrypto/crypto.c:1.128 --- src/sys/opencrypto/crypto.c:1.127 Sun May 22 11:40:03 2022 +++ src/sys/opencrypto/crypto.c Sun May 22 11:40:15 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: crypto.c,v 1.127 2022/05/22 11:40:03 riastradh Exp $ */ +/* $NetBSD: crypto.c,v 1.128 2022/05/22 11:40:15 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $ */ /* $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */ @@ -53,7 +53,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.127 2022/05/22 11:40:03 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.128 2022/05/22 11:40:15 riastradh Exp $"); #include #include @@ -1318,7 +1318,6 @@ crypto_dispatch(struct cryptop *crp) softint_schedule(crypto_q_si); kpreempt_enable(); } - return 0; } @@ -1336,7 +1335,6 @@ crypto_dispatch(struct cryptop *crp) * to other drivers in cryptointr() later. */ TAILQ_INSERT_TAIL(crp_q, crp, crp_next); - result = 0; goto out; } @@ -1347,7 +1345,6 @@ crypto_dispatch(struct cryptop *crp) * it unblocks and the swi thread gets kicked. */ TAILQ_INSERT_TAIL(crp_q, crp, crp_next); - result = 0; goto out; } @@ -1358,6 +1355,7 @@ crypto_dispatch(struct cryptop *crp) */ crypto_driver_unlock(cap); result = crypto_invoke(crp, 0); + KASSERTMSG(result == 0 || result == ERESTART, "result=%d", result); if (result == ERESTART) { /* * The driver ran out of resources, mark the @@ -1369,18 +1367,11 @@ crypto_dispatch(struct cryptop *crp) crypto_driver_unlock(cap); TAILQ_INSERT_HEAD(crp_q, crp, crp_next); cryptostats.cs_blocks++; - - /* - * The crp is enqueued to crp_q, that is, - * no error occurs. So, this function should - * not return error. - */ - result = 0; } out: crypto_put_crp_qs(); - return result; + return 0; } /* @@ -1411,7 +1402,6 @@ crypto_kdispatch(struct cryptkop *krp) */ if (cap == NULL) { TAILQ_INSERT_TAIL(crp_kq, krp, krp_next); - result = 0; goto out; } @@ -1422,12 +1412,12 @@ crypto_kdispatch(struct cryptkop *krp) * it unblocks and the swi thread gets kicked. */ TAILQ_INSERT_TAIL(crp_kq, krp, krp_next); - result = 0; goto out; } crypto_driver_unlock(cap); result = crypto_kinvoke(krp, 0); + KASSERTMSG(result == 0 || result == ERESTART, "result=%d", result); if (result == ERESTART) { /* * The driver ran out of resources, mark the @@ -1439,18 +1429,11 @@ crypto_kdispatch(struct cryptkop *krp) crypto_driver_unlock(cap); TAILQ_INSERT_HEAD(crp_kq, krp, krp_next); cryptostats.cs_kblocks++; - - /* - * The krp is enqueued to crp_kq, that is, - * no error occurs. So, this function should - * not return error. - */ - result = 0; } out: crypto_put_crp_qs(); - return result; + return 0; } /* @@ -1500,15 +1483,14 @@ crypto_kinvoke(struct cryptkop *krp, int krp->reqcpu = curcpu(); crypto_driver_unlock(cap); error = (*process)(arg, krp, hint); + KASSERTMSG(error == 0 || error == ERESTART, "error=%d", + error); + return error; } else { - error = ENODEV; - } - - if (error) { - krp->krp_status = error; + krp->krp_status = ENODEV; crypto_kdone(krp); + return 0; } - return 0; } #ifdef CRYPTO_TIMING @@ -1542,6 +1524,7 @@ static int crypto_invoke(struct cryptop *crp, int hint) { struct cryptocap *cap; + int error; KASSERT(crp != NULL); KASSERT(crp->crp_callback != NULL); @@ -1567,7 +1550,10 @@ crypto_invoke(struct cryptop *crp, int h */ DPRINTF("calling process for %p\n", crp); crypto_driver_unlock(cap); - return (*process)(arg, crp, hint); + error = (*process)(arg, crp, hint); + KASSERTMSG(error == 0 || error == ERESTART, "error=%d", + error); + return error; } else { if (cap != NULL) { crypto_driver_unlock(cap); @@ -1880,6 +1866,8 @@ cryptointr(void *arg __unused) if (submit != NULL) { TAILQ_REMOVE(crp_q, submit, crp_next); result = crypto_invoke(submit, hint); + KASSERTMSG(result == 0 || result == ERESTART, + "result=%d", result); /* we must take here as the TAILQ op or kinvoke may need this mutex below. sigh. */ if (result == ERESTART) { @@ -1924,6 +1912,8 @@ cryptointr(void *arg
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:40:15 UTC 2022 Modified Files: src/sys/opencrypto: crypto.c Log Message: opencrypto: Assert driver process routine returns 0 or ERESTART. No other errors are allowed -- other errors must be transmitted by crypto_done. All drivers in tree (sun8i_crypto, glxsb, via_padlock, mvcesa, mvxpsec, hifn, qat, ubsec, cryptosoft) have been audited for this. To generate a diff of this commit: cvs rdiff -u -r1.127 -r1.128 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:39:54 UTC 2022 Modified Files: src/sys/opencrypto: crypto.c Log Message: opencrypto: Assert nonnull callback up front in crypto_dispatch. Same with crypto_kdispatch. Convert some dead branches downstream to assertions too. To generate a diff of this commit: cvs rdiff -u -r1.125 -r1.126 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/crypto.c diff -u src/sys/opencrypto/crypto.c:1.125 src/sys/opencrypto/crypto.c:1.126 --- src/sys/opencrypto/crypto.c:1.125 Sun May 22 11:39:37 2022 +++ src/sys/opencrypto/crypto.c Sun May 22 11:39:54 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: crypto.c,v 1.125 2022/05/22 11:39:37 riastradh Exp $ */ +/* $NetBSD: crypto.c,v 1.126 2022/05/22 11:39:54 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $ */ /* $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */ @@ -53,7 +53,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.125 2022/05/22 11:39:37 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.126 2022/05/22 11:39:54 riastradh Exp $"); #include #include @@ -1283,6 +1283,7 @@ crypto_dispatch(struct cryptop *crp) struct crypto_crp_q *crp_q; KASSERT(crp != NULL); + KASSERT(crp->crp_callback != NULL); KASSERT(crp->crp_desc != NULL); KASSERT(crp->crp_buf != NULL); KASSERT(!cpu_intr_p()); @@ -1395,6 +1396,7 @@ crypto_kdispatch(struct cryptkop *krp) struct crypto_crp_kq *crp_kq; KASSERT(krp != NULL); + KASSERT(krp->krp_callback != NULL); KASSERT(!cpu_intr_p()); cryptostats.cs_kops++; @@ -1462,15 +1464,9 @@ crypto_kinvoke(struct cryptkop *krp, int int error; KASSERT(krp != NULL); + KASSERT(krp->krp_callback != NULL); KASSERT(!cpu_intr_p()); - /* Sanity checks. */ - if (krp->krp_callback == NULL) { - cv_destroy(>krp_cv); - crypto_kfreereq(krp); - return EINVAL; - } - mutex_enter(_drv_mtx); for (hid = 0; hid < crypto_drivers_num; hid++) { cap = crypto_checkdriver(hid); @@ -1548,21 +1544,14 @@ crypto_invoke(struct cryptop *crp, int h struct cryptocap *cap; KASSERT(crp != NULL); + KASSERT(crp->crp_callback != NULL); + KASSERT(crp->crp_desc != NULL); KASSERT(!cpu_intr_p()); #ifdef CRYPTO_TIMING if (crypto_timing) crypto_tstat(_invoke, >crp_tstamp); #endif - /* Sanity checks. */ - if (crp->crp_callback == NULL) { - return EINVAL; - } - if (crp->crp_desc == NULL) { - crp->crp_etype = EINVAL; - crypto_done(crp); - return 0; - } cap = crypto_checkdriver_lock(CRYPTO_SESID2HID(crp->crp_sid)); if (cap != NULL && (cap->cc_flags & CRYPTOCAP_F_CLEANUP) == 0) {
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:39:54 UTC 2022 Modified Files: src/sys/opencrypto: crypto.c Log Message: opencrypto: Assert nonnull callback up front in crypto_dispatch. Same with crypto_kdispatch. Convert some dead branches downstream to assertions too. To generate a diff of this commit: cvs rdiff -u -r1.125 -r1.126 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:39:46 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): Nix dead code now that crypto_freesession never fails. To generate a diff of this commit: cvs rdiff -u -r1.120 -r1.121 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptodev.c diff -u src/sys/opencrypto/cryptodev.c:1.120 src/sys/opencrypto/cryptodev.c:1.121 --- src/sys/opencrypto/cryptodev.c:1.120 Sun May 22 11:39:37 2022 +++ src/sys/opencrypto/cryptodev.c Sun May 22 11:39:45 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.c,v 1.120 2022/05/22 11:39:37 riastradh Exp $ */ +/* $NetBSD: cryptodev.c,v 1.121 2022/05/22 11:39:45 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */ /* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */ @@ -64,7 +64,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.120 2022/05/22 11:39:37 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.121 2022/05/22 11:39:45 riastradh Exp $"); #include #include @@ -182,11 +182,11 @@ static struct csession *csecreate(struct u_int64_t, void *, u_int64_t, u_int32_t, u_int32_t, u_int32_t, const struct enc_xform *, const struct auth_hash *, const struct comp_algo *); -static int csefree(struct csession *); +static void csefree(struct csession *); static int cryptodev_key(struct crypt_kop *); static int cryptodev_mkey(struct fcrypt *, struct crypt_n_kop *, int); -static int cryptodev_msessionfin(struct fcrypt *, int, u_int32_t *); +static void cryptodev_msessionfin(struct fcrypt *, int, u_int32_t *); static void cryptodev_cb(struct cryptop *); static void cryptodevkey_cb(struct cryptkop *); @@ -317,7 +317,7 @@ mbail: } csedelete(fcr, cse); mutex_exit(_mtx); - error = csefree(cse); + csefree(cse); break; case CIOCNFSESSION: mutex_enter(_mtx); @@ -334,7 +334,7 @@ mbail: error = copyin(sfop->sesid, sesid, (sfop->count * sizeof(u_int32_t))); if (!error) { - error = cryptodev_msessionfin(fcr, sfop->count, sesid); + cryptodev_msessionfin(fcr, sfop->count, sesid); } kmem_free(sesid, (sfop->count * sizeof(u_int32_t))); break; @@ -922,7 +922,7 @@ cryptof_close(struct file *fp) while ((cse = TAILQ_FIRST(>csessions))) { TAILQ_REMOVE(>csessions, cse, next); mutex_exit(_mtx); - (void)csefree(cse); + csefree(cse); mutex_enter(_mtx); } seldestroy(>sinfo); @@ -950,7 +950,7 @@ csefind(struct fcrypt *fcr, u_int ses) TAILQ_FOREACH_SAFE(cse, >csessions, next, cnext) if (cse->ses == ses) ret = cse; - + return ret; } @@ -1014,19 +1014,16 @@ csecreate(struct fcrypt *fcr, u_int64_t } } -static int +static void csefree(struct csession *cse) { - int error; crypto_freesession(cse->sid); - error = 0; if (cse->key) free(cse->key, M_XDATA); if (cse->mackey) free(cse->mackey, M_XDATA); pool_put(, cse); - return error; } static int @@ -1757,11 +1754,11 @@ cryptodev_msession(struct fcrypt *fcr, s return 0; } -static int +static void cryptodev_msessionfin(struct fcrypt *fcr, int count, u_int32_t *sesid) { struct csession *cse; - int req, error = 0; + int req; mutex_enter(_mtx); for(req = 0; req < count; req++) { @@ -1770,11 +1767,10 @@ cryptodev_msessionfin(struct fcrypt *fcr continue; csedelete(fcr, cse); mutex_exit(_mtx); - error = csefree(cse); + csefree(cse); mutex_enter(_mtx); } mutex_exit(_mtx); - return error; } /*
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:39:46 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): Nix dead code now that crypto_freesession never fails. To generate a diff of this commit: cvs rdiff -u -r1.120 -r1.121 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:39:17 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): crypto_freesession should never fail here. It can only fail if we pass it an invalid sid, which the logic to maintain the user sessions should not do. So kassert error=0 here. To generate a diff of this commit: cvs rdiff -u -r1.118 -r1.119 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptodev.c diff -u src/sys/opencrypto/cryptodev.c:1.118 src/sys/opencrypto/cryptodev.c:1.119 --- src/sys/opencrypto/cryptodev.c:1.118 Sun May 22 11:34:29 2022 +++ src/sys/opencrypto/cryptodev.c Sun May 22 11:39:17 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.c,v 1.118 2022/05/22 11:34:29 riastradh Exp $ */ +/* $NetBSD: cryptodev.c,v 1.119 2022/05/22 11:39:17 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */ /* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */ @@ -64,7 +64,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.118 2022/05/22 11:34:29 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.119 2022/05/22 11:39:17 riastradh Exp $"); #include #include @@ -1020,6 +1020,7 @@ csefree(struct csession *cse) int error; error = crypto_freesession(cse->sid); + KASSERTMSG(error == 0, "error=%d", error); if (cse->key) free(cse->key, M_XDATA); if (cse->mackey)
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:39:17 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): crypto_freesession should never fail here. It can only fail if we pass it an invalid sid, which the logic to maintain the user sessions should not do. So kassert error=0 here. To generate a diff of this commit: cvs rdiff -u -r1.118 -r1.119 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:38:59 UTC 2022 Modified Files: src/sys/opencrypto: cryptosoft.c Log Message: cryptosoft(4): Prune dead branches. Assert session id validity. To generate a diff of this commit: cvs rdiff -u -r1.62 -r1.63 src/sys/opencrypto/cryptosoft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptosoft.c diff -u src/sys/opencrypto/cryptosoft.c:1.62 src/sys/opencrypto/cryptosoft.c:1.63 --- src/sys/opencrypto/cryptosoft.c:1.62 Sun May 22 11:29:25 2022 +++ src/sys/opencrypto/cryptosoft.c Sun May 22 11:38:59 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptosoft.c,v 1.62 2022/05/22 11:29:25 riastradh Exp $ */ +/* $NetBSD: cryptosoft.c,v 1.63 2022/05/22 11:38:59 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptosoft.c,v 1.2.2.1 2002/11/21 23:34:23 sam Exp $ */ /* $OpenBSD: cryptosoft.c,v 1.35 2002/04/26 08:43:50 deraadt Exp $ */ @@ -24,7 +24,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.62 2022/05/22 11:29:25 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.63 2022/05/22 11:38:59 riastradh Exp $"); #include #include @@ -766,9 +766,6 @@ swcr_newsession(void *arg, u_int32_t *si u_int32_t i; int k, error; - if (sid == NULL || cri == NULL) - return EINVAL; - if (swcr_sessions) { for (i = 1; i < swcr_sesnum; i++) if (swcr_sessions[i] == NULL) @@ -1128,9 +1125,9 @@ swcr_freesession(void *arg, u_int64_t ti struct swcr_data *swd; u_int32_t sid = ((u_int32_t) tid) & 0x; - if (sid > swcr_sesnum || swcr_sessions == NULL || - swcr_sessions[sid] == NULL) - return EINVAL; + KASSERTMSG(sid < swcr_sesnum, "sid=%"PRIu32" swcr_sesnum=%"PRIu32, + sid, swcr_sesnum); + KASSERT(swcr_sessions[sid]); swd = swcr_sessions[sid]; swcr_sessions[sid] = NULL;
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:38:59 UTC 2022 Modified Files: src/sys/opencrypto: cryptosoft.c Log Message: cryptosoft(4): Prune dead branches. Assert session id validity. To generate a diff of this commit: cvs rdiff -u -r1.62 -r1.63 src/sys/opencrypto/cryptosoft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:34:40 UTC 2022 Modified Files: src/sys/opencrypto: crypto.c Log Message: opencrypto: Assert crp_desc and crp_buf are nonnull. - crypto_getreq ensures crp_desc is nonnull. - Caller is responsible for setting crp_buf. To generate a diff of this commit: cvs rdiff -u -r1.122 -r1.123 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/crypto.c diff -u src/sys/opencrypto/crypto.c:1.122 src/sys/opencrypto/crypto.c:1.123 --- src/sys/opencrypto/crypto.c:1.122 Sun May 22 11:34:17 2022 +++ src/sys/opencrypto/crypto.c Sun May 22 11:34:40 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: crypto.c,v 1.122 2022/05/22 11:34:17 riastradh Exp $ */ +/* $NetBSD: crypto.c,v 1.123 2022/05/22 11:34:40 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $ */ /* $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */ @@ -53,7 +53,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.122 2022/05/22 11:34:17 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.123 2022/05/22 11:34:40 riastradh Exp $"); #include #include @@ -1287,6 +1287,8 @@ crypto_dispatch(struct cryptop *crp) struct crypto_crp_q *crp_q; KASSERT(crp != NULL); + KASSERT(crp->crp_desc != NULL); + KASSERT(crp->crp_buf != NULL); KASSERT(!cpu_intr_p()); DPRINTF("crp %p, alg %d\n", crp, crp->crp_desc->crd_alg);
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:34:40 UTC 2022 Modified Files: src/sys/opencrypto: crypto.c Log Message: opencrypto: Assert crp_desc and crp_buf are nonnull. - crypto_getreq ensures crp_desc is nonnull. - Caller is responsible for setting crp_buf. To generate a diff of this commit: cvs rdiff -u -r1.122 -r1.123 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:34:29 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): Refuse crypto operations with nothing in them earlier. This way we avoid passing 0 to crypto_getreq -- makes it easier to reason about everything downstream. To generate a diff of this commit: cvs rdiff -u -r1.117 -r1.118 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptodev.c diff -u src/sys/opencrypto/cryptodev.c:1.117 src/sys/opencrypto/cryptodev.c:1.118 --- src/sys/opencrypto/cryptodev.c:1.117 Sun May 22 11:30:41 2022 +++ src/sys/opencrypto/cryptodev.c Sun May 22 11:34:29 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.c,v 1.117 2022/05/22 11:30:41 riastradh Exp $ */ +/* $NetBSD: cryptodev.c,v 1.118 2022/05/22 11:34:29 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */ /* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */ @@ -64,7 +64,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.117 2022/05/22 11:30:41 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.118 2022/05/22 11:34:29 riastradh Exp $"); #include #include @@ -471,6 +471,9 @@ cryptodev_op(struct csession *cse, struc return EINVAL; } + if (cse->tcomp == NULL && cse->txform == NULL && cse->thash == NULL) + return EINVAL; + DPRINTF("cryptodev_op[%u]: iov_len %d\n", CRYPTO_SESID2LID(cse->sid), iov_len); if ((cse->tcomp) && cop->dst_len) { @@ -1131,6 +1134,13 @@ cryptodev_mop(struct fcrypt *fcr, } } + if (cse->txform == NULL && + cse->thash == NULL && + cse->tcomp == NULL) { + cnop[req].status = EINVAL; + goto bail; + } + /* sanitize */ if (cnop[req].len <= 0) { cnop[req].status = ENOMEM;
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:34:29 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): Refuse crypto operations with nothing in them earlier. This way we avoid passing 0 to crypto_getreq -- makes it easier to reason about everything downstream. To generate a diff of this commit: cvs rdiff -u -r1.117 -r1.118 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:30:05 UTC 2022 Modified Files: src/sys/opencrypto: crypto.c cryptodev.h Log Message: opencrypto: Nix CRYPTO_F_DONE. Nothing uses it any more. To generate a diff of this commit: cvs rdiff -u -r1.120 -r1.121 src/sys/opencrypto/crypto.c cvs rdiff -u -r1.44 -r1.45 src/sys/opencrypto/cryptodev.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:30:05 UTC 2022 Modified Files: src/sys/opencrypto: crypto.c cryptodev.h Log Message: opencrypto: Nix CRYPTO_F_DONE. Nothing uses it any more. To generate a diff of this commit: cvs rdiff -u -r1.120 -r1.121 src/sys/opencrypto/crypto.c cvs rdiff -u -r1.44 -r1.45 src/sys/opencrypto/cryptodev.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/crypto.c diff -u src/sys/opencrypto/crypto.c:1.120 src/sys/opencrypto/crypto.c:1.121 --- src/sys/opencrypto/crypto.c:1.120 Sun May 22 11:25:14 2022 +++ src/sys/opencrypto/crypto.c Sun May 22 11:30:05 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: crypto.c,v 1.120 2022/05/22 11:25:14 riastradh Exp $ */ +/* $NetBSD: crypto.c,v 1.121 2022/05/22 11:30:05 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $ */ /* $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */ @@ -53,7 +53,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.120 2022/05/22 11:25:14 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.121 2022/05/22 11:30:05 riastradh Exp $"); #include #include @@ -1748,8 +1748,6 @@ crypto_done(struct cryptop *crp) #endif DPRINTF("lid[%u]: crp %p\n", CRYPTO_SESID2LID(crp->crp_sid), crp); - crp->crp_flags |= CRYPTO_F_DONE; - qs = crypto_get_crp_ret_qs(crp->reqcpu); crp_ret_q = >crp_ret_q; wasempty = TAILQ_EMPTY(crp_ret_q); @@ -1780,8 +1778,6 @@ crypto_kdone(struct cryptkop *krp) if (krp->krp_status != 0) cryptostats.cs_kerrs++; - krp->krp_flags |= CRYPTO_F_DONE; - qs = crypto_get_crp_ret_qs(krp->reqcpu); crp_ret_kq = >crp_ret_kq; Index: src/sys/opencrypto/cryptodev.h diff -u src/sys/opencrypto/cryptodev.h:1.44 src/sys/opencrypto/cryptodev.h:1.45 --- src/sys/opencrypto/cryptodev.h:1.44 Sun May 22 11:25:14 2022 +++ src/sys/opencrypto/cryptodev.h Sun May 22 11:30:05 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.h,v 1.44 2022/05/22 11:25:14 riastradh Exp $ */ +/* $NetBSD: cryptodev.h,v 1.45 2022/05/22 11:30:05 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.h,v 1.2.2.6 2003/07/02 17:04:50 sam Exp $ */ /* $OpenBSD: cryptodev.h,v 1.33 2002/07/17 23:52:39 art Exp $ */ @@ -470,10 +470,10 @@ struct cryptop { #define CRYPTO_F_REL 0x0004 /* Must return data in same place */ #define CRYPTO_F_BATCH 0x0008 /* Batch op if possible possible */ #define CRYPTO_F_UNUSED0 0x0010 /* was CRYPTO_F_CBIMM */ -#define CRYPTO_F_DONE 0x0020 /* Operation completed */ -#define CRYPTO_F_UNUSED1 0x0040 /* was CRYPTO_F_CBIFSYNC */ +#define CRYPTO_F_UNUSED1 0x0020 /* was CRYPTO_F_DONE */ +#define CRYPTO_F_UNUSED2 0x0040 /* was CRYPTO_F_CBIFSYNC */ #define CRYPTO_F_ONRETQ 0x0080 /* Request is on return queue */ -#define CRYPTO_F_UNUSED2 0x0100 /* was CRYPTO_F_USER */ +#define CRYPTO_F_UNUSED3 0x0100 /* was CRYPTO_F_USER */ #define CRYPTO_F_MORE 0x0200 /* more data to follow */ int crp_devflags; /* other than cryptodev.c must not use. */
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:29:54 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): Fix possible use-after-free in race around detach. This is extremely unlikely because I don't think we have any drivers for removable crypto decelerators^Waccelerators...but if we were to sprout one, and someone ran crypto_dispatch concurrently with crypto_unregister, cryptodev_cb/mcb would enter with crp->crp_etype = EAGAIN and with CRYPTO_F_DONE set in crp->crp_flags. In this case, cryptodev_cb/mcb would issue crypto_dispatch but -- since nothing clears CRYPTO_F_DONE -- it would _also_ consider the request done and notify the ioctl thread of that. With this change, we return early if crypto_dispatch succeeds. No need to consult CRYPTO_F_DONE: if the callback is invoked it's done, and if we try to redispatch it on EAGAIN but crypto_dispatch fails, it's done. (Soon we'll get rid of the possibility of crypto_dispatch failing synchronously, but not just yet.) XXX This path could really use some testing! To generate a diff of this commit: cvs rdiff -u -r1.115 -r1.116 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptodev.c diff -u src/sys/opencrypto/cryptodev.c:1.115 src/sys/opencrypto/cryptodev.c:1.116 --- src/sys/opencrypto/cryptodev.c:1.115 Sat May 21 23:11:03 2022 +++ src/sys/opencrypto/cryptodev.c Sun May 22 11:29:54 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.c,v 1.115 2022/05/21 23:11:03 riastradh Exp $ */ +/* $NetBSD: cryptodev.c,v 1.116 2022/05/22 11:29:54 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */ /* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */ @@ -64,7 +64,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.115 2022/05/21 23:11:03 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.116 2022/05/22 11:29:54 riastradh Exp $"); #include #include @@ -715,20 +715,18 @@ static int cryptodev_cb(struct cryptop *crp) { struct csession *cse = crp->crp_opaque; - int error = 0; + int error; - mutex_enter(_mtx); - cse->error = crp->crp_etype; - if (crp->crp_etype == EAGAIN) { - /* always drop mutex to call dispatch routine */ - mutex_exit(_mtx); + if ((error = crp->crp_etype) == EAGAIN) { error = crypto_dispatch(crp); - mutex_enter(_mtx); - } - if (error != 0 || (crp->crp_flags & CRYPTO_F_DONE)) { - crp->crp_devflags |= CRYPTODEV_F_RET; - cv_signal(>crp_cv); + if (error == 0) + return 0; } + + mutex_enter(_mtx); + cse->error = error; + crp->crp_devflags |= CRYPTODEV_F_RET; + cv_signal(>crp_cv); mutex_exit(_mtx); return 0; } @@ -737,15 +735,16 @@ static int cryptodev_mcb(struct cryptop *crp) { struct csession *cse = crp->crp_opaque; + int error; - mutex_enter(_mtx); - cse->error = crp->crp_etype; - if (crp->crp_etype == EAGAIN) { - mutex_exit(_mtx); - (void)crypto_dispatch(crp); - mutex_enter(_mtx); + if ((error = crp->crp_etype) == EAGAIN) { + error = crypto_dispatch(crp); + if (error == 0) + return 0; } + mutex_enter(_mtx); + cse->error = error; TAILQ_INSERT_TAIL(>fcrp->crp_ret_mq, crp, crp_next); selnotify(>fcrp->sinfo, 0, 0); mutex_exit(_mtx);
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:29:54 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): Fix possible use-after-free in race around detach. This is extremely unlikely because I don't think we have any drivers for removable crypto decelerators^Waccelerators...but if we were to sprout one, and someone ran crypto_dispatch concurrently with crypto_unregister, cryptodev_cb/mcb would enter with crp->crp_etype = EAGAIN and with CRYPTO_F_DONE set in crp->crp_flags. In this case, cryptodev_cb/mcb would issue crypto_dispatch but -- since nothing clears CRYPTO_F_DONE -- it would _also_ consider the request done and notify the ioctl thread of that. With this change, we return early if crypto_dispatch succeeds. No need to consult CRYPTO_F_DONE: if the callback is invoked it's done, and if we try to redispatch it on EAGAIN but crypto_dispatch fails, it's done. (Soon we'll get rid of the possibility of crypto_dispatch failing synchronously, but not just yet.) XXX This path could really use some testing! To generate a diff of this commit: cvs rdiff -u -r1.115 -r1.116 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:29:25 UTC 2022 Modified Files: src/sys/opencrypto: cryptosoft.c Log Message: cryptosoft(4): Rip out nonsense to quietly ignore sid=0. This is no longer necessary because crypto_freesession no longer calls into the driver for session ids that were never allocated in the first place. To generate a diff of this commit: cvs rdiff -u -r1.61 -r1.62 src/sys/opencrypto/cryptosoft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptosoft.c diff -u src/sys/opencrypto/cryptosoft.c:1.61 src/sys/opencrypto/cryptosoft.c:1.62 --- src/sys/opencrypto/cryptosoft.c:1.61 Tue Apr 6 03:38:04 2021 +++ src/sys/opencrypto/cryptosoft.c Sun May 22 11:29:25 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptosoft.c,v 1.61 2021/04/06 03:38:04 knakahara Exp $ */ +/* $NetBSD: cryptosoft.c,v 1.62 2022/05/22 11:29:25 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptosoft.c,v 1.2.2.1 2002/11/21 23:34:23 sam Exp $ */ /* $OpenBSD: cryptosoft.c,v 1.35 2002/04/26 08:43:50 deraadt Exp $ */ @@ -24,7 +24,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.61 2021/04/06 03:38:04 knakahara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.62 2022/05/22 11:29:25 riastradh Exp $"); #include #include @@ -1132,10 +1132,6 @@ swcr_freesession(void *arg, u_int64_t ti swcr_sessions[sid] == NULL) return EINVAL; - /* Silently accept and return */ - if (sid == 0) - return 0; - swd = swcr_sessions[sid]; swcr_sessions[sid] = NULL; swcr_freesession_internal(swd);
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:29:25 UTC 2022 Modified Files: src/sys/opencrypto: cryptosoft.c Log Message: cryptosoft(4): Rip out nonsense to quietly ignore sid=0. This is no longer necessary because crypto_freesession no longer calls into the driver for session ids that were never allocated in the first place. To generate a diff of this commit: cvs rdiff -u -r1.61 -r1.62 src/sys/opencrypto/cryptosoft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:25:14 UTC 2022 Modified Files: src/sys/opencrypto: crypto.c cryptodev.h Log Message: opencrypto: Make sid=0 always invalid, but OK to free. Previously, crypto_newsession could sometimes return 0 as the driver-specific part of the session id, and 0 as the hid, for sid=0. But netipsec assumes that it is always safe to free sid=0 from zero-initialized memory even if crypto_newsession has never succeeded. So it was up to every driver in tree to gracefully handle sid=0, if it happened to get assigned hid=0. And, as long as the freesession callback was expected to just return an error code when given a bogus session id, that worked out fine...because nothing ever used the error code. That was a terrible fragile system that should never have been invented. Instead, let's just ensure that valid session ids are nonzero, and make crypto_freesession with sid=0 be a no-op. To generate a diff of this commit: cvs rdiff -u -r1.119 -r1.120 src/sys/opencrypto/crypto.c cvs rdiff -u -r1.43 -r1.44 src/sys/opencrypto/cryptodev.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/crypto.c diff -u src/sys/opencrypto/crypto.c:1.119 src/sys/opencrypto/crypto.c:1.120 --- src/sys/opencrypto/crypto.c:1.119 Thu May 19 20:51:59 2022 +++ src/sys/opencrypto/crypto.c Sun May 22 11:25:14 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: crypto.c,v 1.119 2022/05/19 20:51:59 riastradh Exp $ */ +/* $NetBSD: crypto.c,v 1.120 2022/05/22 11:25:14 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $ */ /* $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */ @@ -53,7 +53,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.119 2022/05/19 20:51:59 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.120 2022/05/22 11:25:14 riastradh Exp $"); #include #include @@ -800,6 +800,16 @@ crypto_newsession(u_int64_t *sid, struct struct cryptocap *cap; int err = EINVAL; + /* + * On failure, leave *sid initialized to a sentinel value that + * crypto_freesession will ignore. This is the same as what + * you get from zero-initialized memory -- some callers (I'm + * looking at you, netipsec!) have paths that lead from + * zero-initialized memory into crypto_freesession without any + * crypto_newsession. + */ + *sid = 0; + mutex_enter(_drv_mtx); cap = crypto_select_driver_lock(cri, hard); @@ -807,6 +817,7 @@ crypto_newsession(u_int64_t *sid, struct u_int32_t hid, lid; hid = cap - crypto_drivers; + KASSERT(hid < 0xff); /* * Can't do everything in one session. * @@ -820,10 +831,11 @@ crypto_newsession(u_int64_t *sid, struct err = cap->cc_newsession(cap->cc_arg, , cri); crypto_driver_lock(cap); if (err == 0) { - (*sid) = hid; + (*sid) = hid + 1; (*sid) <<= 32; (*sid) |= (lid & 0x); - (cap->cc_sessions)++; + KASSERT(*sid != 0); + cap->cc_sessions++; } else { DPRINTF("crypto_drivers[%d].cc_newsession() failed. error=%d\n", hid, err); @@ -846,6 +858,17 @@ crypto_freesession(u_int64_t sid) struct cryptocap *cap; int err = 0; + /* + * crypto_newsession never returns 0 as a sid (by virtue of + * never returning 0 as a hid, which is part of the sid). + * However, some callers assume that freeing zero is safe. + * Previously this relied on all drivers to agree that freeing + * invalid sids is a no-op, but that's a terrible API contract + * that we're getting rid of. + */ + if (sid == 0) + return; + /* Determine two IDs. */ cap = crypto_checkdriver_lock(CRYPTO_SESID2HID(sid)); if (cap == NULL) Index: src/sys/opencrypto/cryptodev.h diff -u src/sys/opencrypto/cryptodev.h:1.43 src/sys/opencrypto/cryptodev.h:1.44 --- src/sys/opencrypto/cryptodev.h:1.43 Thu May 19 20:51:46 2022 +++ src/sys/opencrypto/cryptodev.h Sun May 22 11:25:14 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.h,v 1.43 2022/05/19 20:51:46 riastradh Exp $ */ +/* $NetBSD: cryptodev.h,v 1.44 2022/05/22 11:25:14 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.h,v 1.2.2.6 2003/07/02 17:04:50 sam Exp $ */ /* $OpenBSD: cryptodev.h,v 1.33 2002/07/17 23:52:39 art Exp $ */ @@ -589,7 +589,7 @@ struct cryptocap { * a copy of the driver's capabilities that can be used by client code to * optimize operation. */ -#define CRYPTO_SESID2HID(_sid) (((_sid) >> 32) & 0xff) +#define CRYPTO_SESID2HID(_sid) _sid) >> 32) & 0xff) - 1) #define CRYPTO_SESID2CAPS(_sid) (((_sid) >> 56) & 0xff) #define CRYPTO_SESID2LID(_sid) (((u_int32_t) (_sid)) & 0x)
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun May 22 11:25:14 UTC 2022 Modified Files: src/sys/opencrypto: crypto.c cryptodev.h Log Message: opencrypto: Make sid=0 always invalid, but OK to free. Previously, crypto_newsession could sometimes return 0 as the driver-specific part of the session id, and 0 as the hid, for sid=0. But netipsec assumes that it is always safe to free sid=0 from zero-initialized memory even if crypto_newsession has never succeeded. So it was up to every driver in tree to gracefully handle sid=0, if it happened to get assigned hid=0. And, as long as the freesession callback was expected to just return an error code when given a bogus session id, that worked out fine...because nothing ever used the error code. That was a terrible fragile system that should never have been invented. Instead, let's just ensure that valid session ids are nonzero, and make crypto_freesession with sid=0 be a no-op. To generate a diff of this commit: cvs rdiff -u -r1.119 -r1.120 src/sys/opencrypto/crypto.c cvs rdiff -u -r1.43 -r1.44 src/sys/opencrypto/cryptodev.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sat May 21 23:11:03 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): Fix set-but-unused variable warning. This deliberately ignores the error code returned by crypto_dispatch, but that error code is fundamentally incoherent and the issue will be mooted by subsequent changes to make it return void and always pass the error through the callback, as well as subsequent changes to rip out the EAGAIN logic anyway. To generate a diff of this commit: cvs rdiff -u -r1.114 -r1.115 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptodev.c diff -u src/sys/opencrypto/cryptodev.c:1.114 src/sys/opencrypto/cryptodev.c:1.115 --- src/sys/opencrypto/cryptodev.c:1.114 Sat May 21 20:37:18 2022 +++ src/sys/opencrypto/cryptodev.c Sat May 21 23:11:03 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.c,v 1.114 2022/05/21 20:37:18 riastradh Exp $ */ +/* $NetBSD: cryptodev.c,v 1.115 2022/05/21 23:11:03 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */ /* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */ @@ -64,7 +64,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.114 2022/05/21 20:37:18 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.115 2022/05/21 23:11:03 riastradh Exp $"); #include #include @@ -737,13 +737,12 @@ static int cryptodev_mcb(struct cryptop *crp) { struct csession *cse = crp->crp_opaque; - int error = 0; mutex_enter(_mtx); cse->error = crp->crp_etype; if (crp->crp_etype == EAGAIN) { mutex_exit(_mtx); - error = crypto_dispatch(crp); + (void)crypto_dispatch(crp); mutex_enter(_mtx); }
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sat May 21 23:11:03 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): Fix set-but-unused variable warning. This deliberately ignores the error code returned by crypto_dispatch, but that error code is fundamentally incoherent and the issue will be mooted by subsequent changes to make it return void and always pass the error through the callback, as well as subsequent changes to rip out the EAGAIN logic anyway. To generate a diff of this commit: cvs rdiff -u -r1.114 -r1.115 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sat May 21 20:37:18 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): Don't signal the condvar for multi-operation completion. The condvar may be destroyed by the time we got here, and nothing waits on it anyway -- instead the caller is expected to select/poll for completion in userland. The bug was already here, but the recent change to eliminate CRYPTO_F_CBIMM made it happen more often by causing the callback to _always_ be run asynchronously instead of sometimes being run synchronously. To generate a diff of this commit: cvs rdiff -u -r1.113 -r1.114 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptodev.c diff -u src/sys/opencrypto/cryptodev.c:1.113 src/sys/opencrypto/cryptodev.c:1.114 --- src/sys/opencrypto/cryptodev.c:1.113 Thu May 19 20:51:46 2022 +++ src/sys/opencrypto/cryptodev.c Sat May 21 20:37:18 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.c,v 1.113 2022/05/19 20:51:46 riastradh Exp $ */ +/* $NetBSD: cryptodev.c,v 1.114 2022/05/21 20:37:18 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */ /* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */ @@ -64,7 +64,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.113 2022/05/19 20:51:46 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.114 2022/05/21 20:37:18 riastradh Exp $"); #include #include @@ -746,9 +746,6 @@ cryptodev_mcb(struct cryptop *crp) error = crypto_dispatch(crp); mutex_enter(_mtx); } - if (error != 0 || (crp->crp_flags & CRYPTO_F_DONE)) { - cv_signal(>crp_cv); - } TAILQ_INSERT_TAIL(>fcrp->crp_ret_mq, crp, crp_next); selnotify(>fcrp->sinfo, 0, 0);
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sat May 21 20:37:18 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): Don't signal the condvar for multi-operation completion. The condvar may be destroyed by the time we got here, and nothing waits on it anyway -- instead the caller is expected to select/poll for completion in userland. The bug was already here, but the recent change to eliminate CRYPTO_F_CBIMM made it happen more often by causing the callback to _always_ be run asynchronously instead of sometimes being run synchronously. To generate a diff of this commit: cvs rdiff -u -r1.113 -r1.114 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Thu May 19 20:51:59 UTC 2022 Modified Files: src/sys/opencrypto: crypto.c Log Message: opencrypto: Assert !cpu_intr_p() on dispatch and invoke. These should only ever have been potentially called from hard interrupt context by CRYPTO_F_CBIMM callbacks (CBIMM = call back immediately). CRYPTO_F_CBIMM is no more, so there is no more need to allow this case of call from hard interrupt context. To generate a diff of this commit: cvs rdiff -u -r1.118 -r1.119 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/crypto.c diff -u src/sys/opencrypto/crypto.c:1.118 src/sys/opencrypto/crypto.c:1.119 --- src/sys/opencrypto/crypto.c:1.118 Thu May 19 20:51:46 2022 +++ src/sys/opencrypto/crypto.c Thu May 19 20:51:59 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: crypto.c,v 1.118 2022/05/19 20:51:46 riastradh Exp $ */ +/* $NetBSD: crypto.c,v 1.119 2022/05/19 20:51:59 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $ */ /* $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */ @@ -53,7 +53,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.118 2022/05/19 20:51:46 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.119 2022/05/19 20:51:59 riastradh Exp $"); #include #include @@ -1264,6 +1264,7 @@ crypto_dispatch(struct cryptop *crp) struct crypto_crp_q *crp_q; KASSERT(crp != NULL); + KASSERT(!cpu_intr_p()); DPRINTF("crp %p, alg %d\n", crp, crp->crp_desc->crd_alg); @@ -1373,6 +1374,7 @@ crypto_kdispatch(struct cryptkop *krp) struct crypto_crp_kq *crp_kq; KASSERT(krp != NULL); + KASSERT(!cpu_intr_p()); cryptostats.cs_kops++; @@ -1439,6 +1441,7 @@ crypto_kinvoke(struct cryptkop *krp, int int error; KASSERT(krp != NULL); + KASSERT(!cpu_intr_p()); /* Sanity checks. */ if (krp->krp_callback == NULL) { @@ -1524,6 +1527,7 @@ crypto_invoke(struct cryptop *crp, int h struct cryptocap *cap; KASSERT(crp != NULL); + KASSERT(!cpu_intr_p()); #ifdef CRYPTO_TIMING if (crypto_timing)
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Thu May 19 20:51:59 UTC 2022 Modified Files: src/sys/opencrypto: crypto.c Log Message: opencrypto: Assert !cpu_intr_p() on dispatch and invoke. These should only ever have been potentially called from hard interrupt context by CRYPTO_F_CBIMM callbacks (CBIMM = call back immediately). CRYPTO_F_CBIMM is no more, so there is no more need to allow this case of call from hard interrupt context. To generate a diff of this commit: cvs rdiff -u -r1.118 -r1.119 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Thu May 19 20:51:46 UTC 2022 Modified Files: src/sys/opencrypto: crypto.c cryptodev.c cryptodev.h Log Message: opencrypto: Nix CRYPTO_F_USER, CRYPTO_F_CBIMM, CRYPTO_F_CBIFSYNC. CRYPTO_F_USER is no longer needed. It was introduced in 2008 by darran@ in crypto.c 1.30, cryptodev.c 1.45 in an attempt to avoid double-free between the issuing thread and asynchronous callback. But the `fix' didn't work. In 2017, knakahara@ fixed it properly in cryptodev.c 1.87 by distinguishing `the crypto operation has completed' (CRYPTO_F_DONE) from `the callback is done touching the crp object' (CRYPTO_F_DQRETQ, now renamed to CRYPTODEV_F_RET). CRYPTO_F_CBIMM formerly served to invoke the callback synchronously from the driver's interrupt completion routine, to reduce contention on what was once a single cryptoret thread. Now, there is a per-CPU queue and softint for much cheaper processing, so there is less motivation for this in the first place. So let's remove the complicated logic. This means the callbacks never run in hard interrupt context, which means we don't need to worry about recursion into crypto_dispatch in hard interrupt context. To generate a diff of this commit: cvs rdiff -u -r1.117 -r1.118 src/sys/opencrypto/crypto.c cvs rdiff -u -r1.112 -r1.113 src/sys/opencrypto/cryptodev.c cvs rdiff -u -r1.42 -r1.43 src/sys/opencrypto/cryptodev.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/crypto.c diff -u src/sys/opencrypto/crypto.c:1.117 src/sys/opencrypto/crypto.c:1.118 --- src/sys/opencrypto/crypto.c:1.117 Tue May 17 10:32:58 2022 +++ src/sys/opencrypto/crypto.c Thu May 19 20:51:46 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: crypto.c,v 1.117 2022/05/17 10:32:58 riastradh Exp $ */ +/* $NetBSD: crypto.c,v 1.118 2022/05/19 20:51:46 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $ */ /* $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */ @@ -53,7 +53,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.117 2022/05/17 10:32:58 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.118 2022/05/19 20:51:46 riastradh Exp $"); #include #include @@ -1707,6 +1707,9 @@ crypto_kgetreq(int num __unused, int prf void crypto_done(struct cryptop *crp) { + int wasempty; + struct crypto_crp_ret_qs *qs; + struct crypto_crp_ret_q *crp_ret_q; KASSERT(crp != NULL); @@ -1720,70 +1723,19 @@ crypto_done(struct cryptop *crp) crp->crp_flags |= CRYPTO_F_DONE; - /* - * Normal case; queue the callback for the thread. - * - * The return queue is manipulated by the swi thread - * and, potentially, by crypto device drivers calling - * back to mark operations completed. Thus we need - * to mask both while manipulating the return queue. - */ - if (crp->crp_flags & CRYPTO_F_CBIMM) { - /* - * Do the callback directly. This is ok when the - * callback routine does very little (e.g. the - * /dev/crypto callback method just does a wakeup). - */ -#ifdef CRYPTO_TIMING - if (crypto_timing) { - /* - * NB: We must copy the timestamp before - * doing the callback as the cryptop is - * likely to be reclaimed. - */ - struct timespec t = crp->crp_tstamp; - crypto_tstat(_cb, ); - crp->crp_callback(crp); - crypto_tstat(_finis, ); - } else -#endif - crp->crp_callback(crp); - } else { -#if 0 - if (crp->crp_flags & CRYPTO_F_USER) { - /* - * TODO: - * If crp->crp_flags & CRYPTO_F_USER and the used - * encryption driver does all the processing in - * the same context, we can skip enqueueing crp_ret_q - * and softint_schedule(crypto_ret_si). - */ - DPRINTF("lid[%u]: crp %p CRYPTO_F_USER\n", -CRYPTO_SESID2LID(crp->crp_sid), crp); - } else -#endif - { - int wasempty; - struct crypto_crp_ret_qs *qs; - struct crypto_crp_ret_q *crp_ret_q; - - qs = crypto_get_crp_ret_qs(crp->reqcpu); - crp_ret_q = >crp_ret_q; - wasempty = TAILQ_EMPTY(crp_ret_q); - DPRINTF("lid[%u]: queueing %p\n", -CRYPTO_SESID2LID(crp->crp_sid), crp); - crp->crp_flags |= CRYPTO_F_ONRETQ; - TAILQ_INSERT_TAIL(crp_ret_q, crp, crp_next); - qs->crp_ret_q_len++; - if (wasempty && !qs->crp_ret_q_exit_flag) { -DPRINTF("lid[%u]: waking cryptoret," - "crp %p hit empty queue\n.", - CRYPTO_SESID2LID(crp->crp_sid), crp); -softint_schedule_cpu(crypto_ret_si, crp->reqcpu); - } - crypto_put_crp_ret_qs(crp->reqcpu); - } + qs = crypto_get_crp_ret_qs(crp->reqcpu); + crp_ret_q = >crp_ret_q; + wasempty = TAILQ_EMPTY(crp_ret_q); + DPRINTF("lid[%u]: queueing %p\n", CRYPTO_SESID2LID(crp->crp_sid), crp); + crp->crp_flags |= CRYPTO_F_ONRETQ; + TAILQ_INSERT_TAIL(crp_ret_q, crp, crp_next); + qs->crp_ret_q_len++; + if (wasempty && !qs->crp_ret_q_exit_flag) { + DPRINTF("lid[%u]: waking cryptoret, crp %p hit empty queue\n.", +
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Thu May 19 20:51:46 UTC 2022 Modified Files: src/sys/opencrypto: crypto.c cryptodev.c cryptodev.h Log Message: opencrypto: Nix CRYPTO_F_USER, CRYPTO_F_CBIMM, CRYPTO_F_CBIFSYNC. CRYPTO_F_USER is no longer needed. It was introduced in 2008 by darran@ in crypto.c 1.30, cryptodev.c 1.45 in an attempt to avoid double-free between the issuing thread and asynchronous callback. But the `fix' didn't work. In 2017, knakahara@ fixed it properly in cryptodev.c 1.87 by distinguishing `the crypto operation has completed' (CRYPTO_F_DONE) from `the callback is done touching the crp object' (CRYPTO_F_DQRETQ, now renamed to CRYPTODEV_F_RET). CRYPTO_F_CBIMM formerly served to invoke the callback synchronously from the driver's interrupt completion routine, to reduce contention on what was once a single cryptoret thread. Now, there is a per-CPU queue and softint for much cheaper processing, so there is less motivation for this in the first place. So let's remove the complicated logic. This means the callbacks never run in hard interrupt context, which means we don't need to worry about recursion into crypto_dispatch in hard interrupt context. To generate a diff of this commit: cvs rdiff -u -r1.117 -r1.118 src/sys/opencrypto/crypto.c cvs rdiff -u -r1.112 -r1.113 src/sys/opencrypto/cryptodev.c cvs rdiff -u -r1.42 -r1.43 src/sys/opencrypto/cryptodev.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Wed May 18 20:03:58 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): Simplify error test in cryptodev_op. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r1.111 -r1.112 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptodev.c diff -u src/sys/opencrypto/cryptodev.c:1.111 src/sys/opencrypto/cryptodev.c:1.112 --- src/sys/opencrypto/cryptodev.c:1.111 Wed May 18 20:03:45 2022 +++ src/sys/opencrypto/cryptodev.c Wed May 18 20:03:58 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.c,v 1.111 2022/05/18 20:03:45 riastradh Exp $ */ +/* $NetBSD: cryptodev.c,v 1.112 2022/05/18 20:03:58 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */ /* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */ @@ -64,7 +64,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.111 2022/05/18 20:03:45 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.112 2022/05/18 20:03:58 riastradh Exp $"); #include #include @@ -647,22 +647,12 @@ cryptodev_op(struct csession *cse, struc error = EINVAL; goto bail; } - crp->crp_mac=cse->tmp_mac; + crp->crp_mac = cse->tmp_mac; } cv_init(>crp_cv, "crydev"); - error = crypto_dispatch(crp); - - /* - * Don't touch crp before returned by any error or received - * cv_signal(>crp_cv). It is required to restructure locks. - */ - - switch (error) { - case 0: - break; - default: + if (error) { DPRINTF("not waiting, error.\n"); cv_destroy(>crp_cv); goto bail;
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Wed May 18 20:03:58 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): Simplify error test in cryptodev_op. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r1.111 -r1.112 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Wed May 18 20:03:45 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): Narrow scope of cryptodev_mtx to cover wait. No functional change intended -- this only removes an unnecessary lock/unlock cycle in the error case. To generate a diff of this commit: cvs rdiff -u -r1.110 -r1.111 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptodev.c diff -u src/sys/opencrypto/cryptodev.c:1.110 src/sys/opencrypto/cryptodev.c:1.111 --- src/sys/opencrypto/cryptodev.c:1.110 Wed May 18 20:03:32 2022 +++ src/sys/opencrypto/cryptodev.c Wed May 18 20:03:45 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.c,v 1.110 2022/05/18 20:03:32 riastradh Exp $ */ +/* $NetBSD: cryptodev.c,v 1.111 2022/05/18 20:03:45 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */ /* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */ @@ -64,7 +64,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.110 2022/05/18 20:03:32 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.111 2022/05/18 20:03:45 riastradh Exp $"); #include #include @@ -653,7 +653,6 @@ cryptodev_op(struct csession *cse, struc cv_init(>crp_cv, "crydev"); error = crypto_dispatch(crp); - mutex_enter(_mtx); /* * Don't touch crp before returned by any error or received @@ -665,11 +664,11 @@ cryptodev_op(struct csession *cse, struc break; default: DPRINTF("not waiting, error.\n"); - mutex_exit(_mtx); cv_destroy(>crp_cv); goto bail; } + mutex_enter(_mtx); while (!(crp->crp_devflags & CRYPTODEV_F_RET)) { DPRINTF("cse->sid[%d]: sleeping on cv %p for crp %p\n", (uint32_t)cse->sid, >crp_cv, crp);
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Wed May 18 20:03:45 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): Narrow scope of cryptodev_mtx to cover wait. No functional change intended -- this only removes an unnecessary lock/unlock cycle in the error case. To generate a diff of this commit: cvs rdiff -u -r1.110 -r1.111 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Wed May 18 20:03:32 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): Nix long-dead code and comments. To generate a diff of this commit: cvs rdiff -u -r1.109 -r1.110 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptodev.c diff -u src/sys/opencrypto/cryptodev.c:1.109 src/sys/opencrypto/cryptodev.c:1.110 --- src/sys/opencrypto/cryptodev.c:1.109 Wed May 18 20:02:49 2022 +++ src/sys/opencrypto/cryptodev.c Wed May 18 20:03:32 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.c,v 1.109 2022/05/18 20:02:49 riastradh Exp $ */ +/* $NetBSD: cryptodev.c,v 1.110 2022/05/18 20:03:32 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */ /* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */ @@ -64,7 +64,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.109 2022/05/18 20:02:49 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.110 2022/05/18 20:03:32 riastradh Exp $"); #include #include @@ -652,34 +652,15 @@ cryptodev_op(struct csession *cse, struc cv_init(>crp_cv, "crydev"); - /* - * XXX there was a comment here which said that we went to - * XXX splcrypto() but needed to only if CRYPTO_F_CBIMM, - * XXX disabled on NetBSD since 1.6O due to a race condition. - * XXX But crypto_dispatch went to splcrypto() itself! (And - * XXX now takes the cryptodev_mtx mutex itself). We do, however, - * XXX need to hold the mutex across the call to cv_wait(). - * XXX (should we arrange for crypto_dispatch to return to - * XXX us with it held? it seems quite ugly to do so.) - */ -#ifdef notyet -eagain: -#endif error = crypto_dispatch(crp); mutex_enter(_mtx); - /* + /* * Don't touch crp before returned by any error or received * cv_signal(>crp_cv). It is required to restructure locks. */ switch (error) { -#ifdef notyet /* don't loop forever -- but EAGAIN not possible here yet */ - case EAGAIN: - mutex_exit(_mtx); - goto eagain; - break; -#endif case 0: break; default: @@ -1056,7 +1037,6 @@ csecreate(struct fcrypt *fcr, u_int64_t } } -/* csefree: call with cryptodev_mtx held. */ static int csefree(struct csession *cse) {
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Wed May 18 20:03:32 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): Nix long-dead code and comments. To generate a diff of this commit: cvs rdiff -u -r1.109 -r1.110 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Wed May 18 20:02:49 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): Use IPL_NONE, not IPL_NET, for /dev/crypto pools. These are used (pool_get/put) only from thread context, never from interrupt or even soft interrupt context. To generate a diff of this commit: cvs rdiff -u -r1.108 -r1.109 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptodev.c diff -u src/sys/opencrypto/cryptodev.c:1.108 src/sys/opencrypto/cryptodev.c:1.109 --- src/sys/opencrypto/cryptodev.c:1.108 Tue May 17 09:53:09 2022 +++ src/sys/opencrypto/cryptodev.c Wed May 18 20:02:49 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.c,v 1.108 2022/05/17 09:53:09 riastradh Exp $ */ +/* $NetBSD: cryptodev.c,v 1.109 2022/05/18 20:02:49 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */ /* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */ @@ -64,7 +64,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.108 2022/05/17 09:53:09 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.109 2022/05/18 20:02:49 riastradh Exp $"); #include #include @@ -2118,9 +2118,9 @@ cryptoattach(int num) mutex_init(_mtx, MUTEX_DEFAULT, IPL_NONE); pool_init(, sizeof(struct fcrypt), 0, 0, 0, "fcrpl", - NULL, IPL_NET); /* XXX IPL_NET ("splcrypto") */ + NULL, IPL_NONE); pool_init(, sizeof(struct csession), 0, 0, 0, "csepl", - NULL, IPL_NET); /* XXX IPL_NET ("splcrypto") */ + NULL, IPL_NONE); /* * Preallocate space for 64 users, with 5 sessions each.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Wed May 18 20:02:49 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): Use IPL_NONE, not IPL_NET, for /dev/crypto pools. These are used (pool_get/put) only from thread context, never from interrupt or even soft interrupt context. To generate a diff of this commit: cvs rdiff -u -r1.108 -r1.109 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Tue May 17 10:32:58 UTC 2022 Modified Files: src/sys/opencrypto: crypto.c Log Message: opencrypto: Factor setting CRYPTO_F_DONE out of branches. This had been done in 1.30 when the locking was different. No need any more. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r1.116 -r1.117 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Tue May 17 10:32:58 UTC 2022 Modified Files: src/sys/opencrypto: crypto.c Log Message: opencrypto: Factor setting CRYPTO_F_DONE out of branches. This had been done in 1.30 when the locking was different. No need any more. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r1.116 -r1.117 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/crypto.c diff -u src/sys/opencrypto/crypto.c:1.116 src/sys/opencrypto/crypto.c:1.117 --- src/sys/opencrypto/crypto.c:1.116 Sat Aug 14 20:43:05 2021 +++ src/sys/opencrypto/crypto.c Tue May 17 10:32:58 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: crypto.c,v 1.116 2021/08/14 20:43:05 andvar Exp $ */ +/* $NetBSD: crypto.c,v 1.117 2022/05/17 10:32:58 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $ */ /* $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */ @@ -53,7 +53,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.116 2021/08/14 20:43:05 andvar Exp $"); +__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.117 2022/05/17 10:32:58 riastradh Exp $"); #include #include @@ -1718,6 +1718,8 @@ crypto_done(struct cryptop *crp) #endif DPRINTF("lid[%u]: crp %p\n", CRYPTO_SESID2LID(crp->crp_sid), crp); + crp->crp_flags |= CRYPTO_F_DONE; + /* * Normal case; queue the callback for the thread. * @@ -1732,8 +1734,6 @@ crypto_done(struct cryptop *crp) * callback routine does very little (e.g. the * /dev/crypto callback method just does a wakeup). */ - crp->crp_flags |= CRYPTO_F_DONE; - #ifdef CRYPTO_TIMING if (crypto_timing) { /* @@ -1749,7 +1749,6 @@ crypto_done(struct cryptop *crp) #endif crp->crp_callback(crp); } else { - crp->crp_flags |= CRYPTO_F_DONE; #if 0 if (crp->crp_flags & CRYPTO_F_USER) { /*
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Tue May 17 09:53:09 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: opencrypto(9): Omit needless casts around callbacks. Just declare the right types to begin with. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r1.107 -r1.108 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptodev.c diff -u src/sys/opencrypto/cryptodev.c:1.107 src/sys/opencrypto/cryptodev.c:1.108 --- src/sys/opencrypto/cryptodev.c:1.107 Thu Mar 31 19:30:17 2022 +++ src/sys/opencrypto/cryptodev.c Tue May 17 09:53:09 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.c,v 1.107 2022/03/31 19:30:17 pgoyette Exp $ */ +/* $NetBSD: cryptodev.c,v 1.108 2022/05/17 09:53:09 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */ /* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */ @@ -64,7 +64,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.107 2022/03/31 19:30:17 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.108 2022/05/17 09:53:09 riastradh Exp $"); #include #include @@ -188,11 +188,11 @@ static int cryptodev_key(struct crypt_ko static int cryptodev_mkey(struct fcrypt *, struct crypt_n_kop *, int); static int cryptodev_msessionfin(struct fcrypt *, int, u_int32_t *); -static int cryptodev_cb(void *); -static int cryptodevkey_cb(void *); +static int cryptodev_cb(struct cryptop *); +static int cryptodevkey_cb(struct cryptkop *); -static int cryptodev_mcb(void *); -static int cryptodevkey_mcb(void *); +static int cryptodev_mcb(struct cryptop *); +static int cryptodevkey_mcb(struct cryptkop *); static int cryptodev_getmstatus(struct fcrypt *, struct crypt_result *, int); @@ -612,9 +612,9 @@ cryptodev_op(struct csession *cse, struc crp->crp_flags = CRYPTO_F_IOV | (cop->flags & COP_F_BATCH) | CRYPTO_F_USER | flags; crp->crp_buf = (void *)>uio; - crp->crp_callback = (int (*) (struct cryptop *)) cryptodev_cb; + crp->crp_callback = cryptodev_cb; crp->crp_sid = cse->sid; - crp->crp_opaque = (void *)cse; + crp->crp_opaque = cse; if (cop->iv) { if (crde == NULL) { @@ -748,10 +748,9 @@ bail: } static int -cryptodev_cb(void *op) +cryptodev_cb(struct cryptop *crp) { - struct cryptop *crp = (struct cryptop *) op; - struct csession *cse = (struct csession *)crp->crp_opaque; + struct csession *cse = crp->crp_opaque; int error = 0; mutex_enter(_mtx); @@ -771,11 +770,10 @@ cryptodev_cb(void *op) } static int -cryptodev_mcb(void *op) +cryptodev_mcb(struct cryptop *crp) { - struct cryptop *crp = (struct cryptop *) op; - struct csession *cse = (struct csession *)crp->crp_opaque; - int error=0; + struct csession *cse = crp->crp_opaque; + int error = 0; mutex_enter(_mtx); cse->error = crp->crp_etype; @@ -795,10 +793,9 @@ cryptodev_mcb(void *op) } static int -cryptodevkey_cb(void *op) +cryptodevkey_cb(struct cryptkop *krp) { - struct cryptkop *krp = op; - + mutex_enter(_mtx); krp->krp_devflags |= CRYPTODEV_F_RET; cv_signal(>krp_cv); @@ -807,9 +804,8 @@ cryptodevkey_cb(void *op) } static int -cryptodevkey_mcb(void *op) +cryptodevkey_mcb(struct cryptkop *krp) { - struct cryptkop *krp = op; mutex_enter(_mtx); cv_signal(>krp_cv); @@ -892,7 +888,7 @@ cryptodev_key(struct crypt_kop *kop) krp->krp_iparams = kop->crk_iparams; krp->krp_oparams = kop->crk_oparams; krp->krp_status = 0; - krp->krp_callback = (int (*) (struct cryptkop *)) cryptodevkey_cb; + krp->krp_callback = cryptodevkey_cb; for (i = 0; i < CRK_MAXPARAM; i++) krp->krp_param[i].crp_nbits = kop->crk_param[i].crp_nbits; @@ -1306,9 +1302,9 @@ cryptodev_mop(struct fcrypt *fcr, crp->crp_flags = CRYPTO_F_IOV | CRYPTO_F_CBIMM | (cnop[req].flags & COP_F_BATCH) | flags; crp->crp_buf = (void *)>uio; - crp->crp_callback = (int (*) (struct cryptop *)) cryptodev_mcb; + crp->crp_callback = cryptodev_mcb; crp->crp_sid = cse->sid; - crp->crp_opaque = (void *)cse; + crp->crp_opaque = cse; crp->fcrp = fcr; crp->dst = cnop[req].dst; crp->len = cnop[req].len; /* input len, iov may be larger */ @@ -1482,8 +1478,7 @@ cryptodev_mkey(struct fcrypt *fcr, struc krp->krp_iparams = kop[req].crk_iparams; krp->krp_oparams = kop[req].crk_oparams; krp->krp_status = 0; - krp->krp_callback = - (int (*) (struct cryptkop *)) cryptodevkey_mcb; + krp->krp_callback = cryptodevkey_mcb; (void)memcpy(krp->crk_param, kop[req].crk_param, sizeof(kop[req].crk_param));
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Tue May 17 09:53:09 UTC 2022 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: opencrypto(9): Omit needless casts around callbacks. Just declare the right types to begin with. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r1.107 -r1.108 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sat Mar 12 17:15:04 UTC 2022 Modified Files: src/sys/opencrypto: ocryptodev.c Log Message: crypto(4): Refuse count>1 for old CIOCNCRYPTM. This hasn't worked since it was written in 2009; if anyone cared surely they would have fixed it by now! (Fixing this properly -- and putting a more reasonable upper bound than the maximum that size_t arithmetic allows -- left as an exercise or the reader.) Reported-by: syzbot+798d4a16bc15ae885...@syzkaller.appspotmail.com To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/sys/opencrypto/ocryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sat Mar 12 17:15:04 UTC 2022 Modified Files: src/sys/opencrypto: ocryptodev.c Log Message: crypto(4): Refuse count>1 for old CIOCNCRYPTM. This hasn't worked since it was written in 2009; if anyone cared surely they would have fixed it by now! (Fixing this properly -- and putting a more reasonable upper bound than the maximum that size_t arithmetic allows -- left as an exercise or the reader.) Reported-by: syzbot+798d4a16bc15ae885...@syzkaller.appspotmail.com To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/sys/opencrypto/ocryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/ocryptodev.c diff -u src/sys/opencrypto/ocryptodev.c:1.16 src/sys/opencrypto/ocryptodev.c:1.17 --- src/sys/opencrypto/ocryptodev.c:1.16 Mon Jan 27 17:09:17 2020 +++ src/sys/opencrypto/ocryptodev.c Sat Mar 12 17:15:04 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: ocryptodev.c,v 1.16 2020/01/27 17:09:17 pgoyette Exp $ */ +/* $NetBSD: ocryptodev.c,v 1.17 2022/03/12 17:15:04 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */ /* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */ @@ -69,7 +69,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ocryptodev.c,v 1.16 2020/01/27 17:09:17 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ocryptodev.c,v 1.17 2022/03/12 17:15:04 riastradh Exp $"); #include #include @@ -167,8 +167,7 @@ mbail: break; case OCIOCNCRYPTM: omop = (struct ocrypt_mop *)data; - if ((omop->count <= 0) || - (SIZE_MAX/sizeof(struct ocrypt_n_op) <= omop->count)) { + if (omop->count <= 0 || omop->count > 1) { error = EINVAL; break; }
CVS commit: src/sys/opencrypto
Module Name:src Committed By: andvar Date: Sat Aug 14 20:43:05 UTC 2021 Modified Files: src/sys/opencrypto: crypto.c cryptodev.h Log Message: fix typo in CRK_ALGORITHM_MIN definition to match CRK_ALGORITHM_MAX one. while here fix few typos in comments. To generate a diff of this commit: cvs rdiff -u -r1.115 -r1.116 src/sys/opencrypto/crypto.c cvs rdiff -u -r1.41 -r1.42 src/sys/opencrypto/cryptodev.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/crypto.c diff -u src/sys/opencrypto/crypto.c:1.115 src/sys/opencrypto/crypto.c:1.116 --- src/sys/opencrypto/crypto.c:1.115 Mon Aug 9 19:57:58 2021 +++ src/sys/opencrypto/crypto.c Sat Aug 14 20:43:05 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: crypto.c,v 1.115 2021/08/09 19:57:58 andvar Exp $ */ +/* $NetBSD: crypto.c,v 1.116 2021/08/14 20:43:05 andvar Exp $ */ /* $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $ */ /* $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */ @@ -53,7 +53,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.115 2021/08/09 19:57:58 andvar Exp $"); +__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.116 2021/08/14 20:43:05 andvar Exp $"); #include #include @@ -1047,7 +1047,7 @@ crypto_kregister(u_int32_t driverid, int cap = crypto_checkdriver_lock(driverid); if (cap != NULL && - (CRK_ALGORITM_MIN <= kalg && kalg <= CRK_ALGORITHM_MAX)) { + (CRK_ALGORITHM_MIN <= kalg && kalg <= CRK_ALGORITHM_MAX)) { /* * XXX Do some performance testing to determine placing. * XXX We probably need an auxiliary data structure that Index: src/sys/opencrypto/cryptodev.h diff -u src/sys/opencrypto/cryptodev.h:1.41 src/sys/opencrypto/cryptodev.h:1.42 --- src/sys/opencrypto/cryptodev.h:1.41 Mon Aug 9 19:57:58 2021 +++ src/sys/opencrypto/cryptodev.h Sat Aug 14 20:43:05 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.h,v 1.41 2021/08/09 19:57:58 andvar Exp $ */ +/* $NetBSD: cryptodev.h,v 1.42 2021/08/14 20:43:05 andvar Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.h,v 1.2.2.6 2003/07/02 17:04:50 sam Exp $ */ /* $OpenBSD: cryptodev.h,v 1.33 2002/07/17 23:52:39 art Exp $ */ @@ -325,7 +325,7 @@ struct cryptret { /* Asymmetric key operations */ -#define CRK_ALGORITM_MIN 0 +#define CRK_ALGORITHM_MIN 0 #define CRK_MOD_EXP 0 #define CRK_MOD_EXP_CRT 1 #define CRK_DSA_SIGN 2 @@ -402,7 +402,7 @@ struct cryptostats { * accumulate statistics about how long it takes to process * crypto requests at various points during processing. */ - struct cryptotstat cs_invoke; /* crypto_dipsatch -> crypto_invoke */ + struct cryptotstat cs_invoke; /* crypto_dispatch -> crypto_invoke */ struct cryptotstat cs_done; /* crypto_invoke -> crypto_done */ struct cryptotstat cs_cb; /* crypto_done -> callback */ struct cryptotstat cs_finis; /* callback -> callback return */ @@ -636,8 +636,8 @@ extern int crypto_devallowsoft; /* only /* * initialize the crypto framework subsystem (not the pseudo-device). * This must be called very early in boot, so the framework is ready - * to handle registration requests when crpto hardware is autoconfigured. - * (This declaration doesnt really belong here but there's no header + * to handle registration requests when crypto hardware is autoconfigured. + * (This declaration doesn't really belong here but there's no header * for the raw framework.) */ int crypto_init(void);
CVS commit: src/sys/opencrypto
Module Name:src Committed By: andvar Date: Sat Aug 14 20:43:05 UTC 2021 Modified Files: src/sys/opencrypto: crypto.c cryptodev.h Log Message: fix typo in CRK_ALGORITHM_MIN definition to match CRK_ALGORITHM_MAX one. while here fix few typos in comments. To generate a diff of this commit: cvs rdiff -u -r1.115 -r1.116 src/sys/opencrypto/crypto.c cvs rdiff -u -r1.41 -r1.42 src/sys/opencrypto/cryptodev.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: knakahara Date: Tue Apr 6 03:38:04 UTC 2021 Modified Files: src/sys/opencrypto: cryptosoft.c Log Message: Fix ATF failures, sorry. To generate a diff of this commit: cvs rdiff -u -r1.60 -r1.61 src/sys/opencrypto/cryptosoft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: knakahara Date: Tue Apr 6 03:38:04 UTC 2021 Modified Files: src/sys/opencrypto: cryptosoft.c Log Message: Fix ATF failures, sorry. To generate a diff of this commit: cvs rdiff -u -r1.60 -r1.61 src/sys/opencrypto/cryptosoft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptosoft.c diff -u src/sys/opencrypto/cryptosoft.c:1.60 src/sys/opencrypto/cryptosoft.c:1.61 --- src/sys/opencrypto/cryptosoft.c:1.60 Mon Apr 5 01:24:50 2021 +++ src/sys/opencrypto/cryptosoft.c Tue Apr 6 03:38:04 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptosoft.c,v 1.60 2021/04/05 01:24:50 knakahara Exp $ */ +/* $NetBSD: cryptosoft.c,v 1.61 2021/04/06 03:38:04 knakahara Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptosoft.c,v 1.2.2.1 2002/11/21 23:34:23 sam Exp $ */ /* $OpenBSD: cryptosoft.c,v 1.35 2002/04/26 08:43:50 deraadt Exp $ */ @@ -24,7 +24,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.60 2021/04/05 01:24:50 knakahara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.61 2021/04/06 03:38:04 knakahara Exp $"); #include #include @@ -712,7 +712,7 @@ swcr_compdec(struct cryptodesc *crd, con * copy in a buffer. */ - data = kmem_alloc(crd->crd_len, KM_NOSLEEP); + data = malloc(crd->crd_len, M_CRYPTO_DATA, M_NOWAIT); if (data == NULL) return (EINVAL); COPYDATA(outtype, buf, crd->crd_skip, crd->crd_len, data); @@ -723,7 +723,7 @@ swcr_compdec(struct cryptodesc *crd, con result = cxf->decompress(data, crd->crd_len, , *res_size); - kmem_free(data, crd->crd_len); + free(data, M_CRYPTO_DATA); if (result == 0) return EINVAL; @@ -1115,7 +1115,7 @@ swcr_freesession_internal(struct swcr_da break; } - free(swd, M_CRYPTO_DATA); + kmem_free(swd, sizeof(*swd)); } }
CVS commit: src/sys/opencrypto
Module Name:src Committed By: knakahara Date: Mon Apr 5 01:24:50 UTC 2021 Modified Files: src/sys/opencrypto: cryptosoft.c Log Message: refactor: reduce access to swcr_sessions[i] directly To generate a diff of this commit: cvs rdiff -u -r1.59 -r1.60 src/sys/opencrypto/cryptosoft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptosoft.c diff -u src/sys/opencrypto/cryptosoft.c:1.59 src/sys/opencrypto/cryptosoft.c:1.60 --- src/sys/opencrypto/cryptosoft.c:1.59 Mon Apr 5 01:23:15 2021 +++ src/sys/opencrypto/cryptosoft.c Mon Apr 5 01:24:50 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptosoft.c,v 1.59 2021/04/05 01:23:15 knakahara Exp $ */ +/* $NetBSD: cryptosoft.c,v 1.60 2021/04/05 01:24:50 knakahara Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptosoft.c,v 1.2.2.1 2002/11/21 23:34:23 sam Exp $ */ /* $OpenBSD: cryptosoft.c,v 1.35 2002/04/26 08:43:50 deraadt Exp $ */ @@ -24,7 +24,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.59 2021/04/05 01:23:15 knakahara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.60 2021/04/05 01:24:50 knakahara Exp $"); #include #include @@ -76,6 +76,7 @@ static int swcr_combined(struct cryptop static int swcr_process(void *, struct cryptop *, int); static int swcr_newsession(void *, u_int32_t *, struct cryptoini *); static int swcr_freesession(void *, u_int64_t); +static void swcr_freesession_internal(struct swcr_data *); static int swcryptoattach_internal(void); @@ -758,6 +759,7 @@ static int swcr_newsession(void *arg, u_int32_t *sid, struct cryptoini *cri) { struct swcr_data **swd; + struct swcr_data *first, *tmp; const struct swcr_auth_hash *axf; const struct swcr_enc_xform *txf; const struct swcr_comp_algo *cxf; @@ -802,15 +804,16 @@ swcr_newsession(void *arg, u_int32_t *si swcr_sessions = newsessions; } - swd = _sessions[i]; - *sid = i; - + first = NULL; + swd = while (cri) { *swd = kmem_zalloc(sizeof **swd, KM_NOSLEEP); if (*swd == NULL) { - swcr_freesession(NULL, i); + if (first != NULL) +swcr_freesession_internal(first); return ENOBUFS; - } + } else if (first == NULL) + first = *swd; switch (cri->cri_alg) { case CRYPTO_DES_CBC: @@ -850,7 +853,7 @@ swcr_newsession(void *arg, u_int32_t *si error = txf->setkey(&((*swd)->sw_kschedule), cri->cri_key, cri->cri_klen / 8); if (error) { -swcr_freesession(NULL, i); +swcr_freesession_internal(first); return error; } (*swd)->sw_exf = txf; @@ -889,13 +892,13 @@ swcr_newsession(void *arg, u_int32_t *si authcommon: (*swd)->sw_ictx = kmem_alloc(axf->ctxsize, KM_NOSLEEP); if ((*swd)->sw_ictx == NULL) { -swcr_freesession(NULL, i); +swcr_freesession_internal(first); return ENOBUFS; } (*swd)->sw_octx = kmem_alloc(axf->ctxsize, KM_NOSLEEP); if ((*swd)->sw_octx == NULL) { -swcr_freesession(NULL, i); +swcr_freesession_internal(first); return ENOBUFS; } @@ -933,7 +936,7 @@ swcr_newsession(void *arg, u_int32_t *si auth2common: (*swd)->sw_ictx = kmem_alloc(axf->ctxsize, KM_NOSLEEP); if ((*swd)->sw_ictx == NULL) { -swcr_freesession(NULL, i); +swcr_freesession_internal(first); return ENOBUFS; } @@ -941,7 +944,7 @@ swcr_newsession(void *arg, u_int32_t *si (*swd)->sw_octx = kmem_alloc(cri->cri_klen / 8, KM_NOSLEEP); if ((*swd)->sw_octx == NULL) { -swcr_freesession(NULL, i); +swcr_freesession_internal(first); return ENOBUFS; } @@ -964,7 +967,7 @@ swcr_newsession(void *arg, u_int32_t *si auth3common: (*swd)->sw_ictx = kmem_alloc(axf->ctxsize, KM_NOSLEEP); if ((*swd)->sw_ictx == NULL) { -swcr_freesession(NULL, i); +swcr_freesession_internal(first); return ENOBUFS; } @@ -986,7 +989,7 @@ swcr_newsession(void *arg, u_int32_t *si auth4common: (*swd)->sw_ictx = kmem_alloc(axf->ctxsize, KM_NOSLEEP); if ((*swd)->sw_ictx == NULL) { -swcr_freesession(NULL, i); +swcr_freesession_internal(first); return ENOBUFS; } axf->Init((*swd)->sw_ictx); @@ -1010,7 +1013,7 @@ swcr_newsession(void *arg, u_int32_t *si (*swd)->sw_cxf = cxf; break; default: - swcr_freesession(NULL, i); + swcr_freesession_internal(first); return EINVAL; } @@ -1018,30 +1021,25 @@ swcr_newsession(void *arg, u_int32_t *si cri = cri->cri_next; swd = &((*swd)->sw_next); } + + swcr_sessions[i] = first; + *sid = i; return 0; } -/* - * Free a session. - */ -static int -swcr_freesession(void *arg, u_int64_t tid) +static void +swcr_freesession_internal(struct swcr_data *arg) { - struct swcr_data *swd; + struct swcr_data *swd, *swd0; const struct swcr_enc_xform *txf; const struct swcr_auth_hash *axf; - u_int32_t sid = ((u_int32_t) tid) & 0x; - - if (sid > swcr_sesnum || swcr_sessions == NULL || - swcr_sessions[sid] ==
CVS commit: src/sys/opencrypto
Module Name:src Committed By: knakahara Date: Mon Apr 5 01:24:50 UTC 2021 Modified Files: src/sys/opencrypto: cryptosoft.c Log Message: refactor: reduce access to swcr_sessions[i] directly To generate a diff of this commit: cvs rdiff -u -r1.59 -r1.60 src/sys/opencrypto/cryptosoft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: knakahara Date: Mon Apr 5 01:23:15 UTC 2021 Modified Files: src/sys/opencrypto: cryptosoft.c Log Message: refactor: reduce changing swcr_sesnum To generate a diff of this commit: cvs rdiff -u -r1.58 -r1.59 src/sys/opencrypto/cryptosoft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: knakahara Date: Mon Apr 5 01:23:15 UTC 2021 Modified Files: src/sys/opencrypto: cryptosoft.c Log Message: refactor: reduce changing swcr_sesnum To generate a diff of this commit: cvs rdiff -u -r1.58 -r1.59 src/sys/opencrypto/cryptosoft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptosoft.c diff -u src/sys/opencrypto/cryptosoft.c:1.58 src/sys/opencrypto/cryptosoft.c:1.59 --- src/sys/opencrypto/cryptosoft.c:1.58 Mon Apr 5 01:22:22 2021 +++ src/sys/opencrypto/cryptosoft.c Mon Apr 5 01:23:15 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptosoft.c,v 1.58 2021/04/05 01:22:22 knakahara Exp $ */ +/* $NetBSD: cryptosoft.c,v 1.59 2021/04/05 01:23:15 knakahara Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptosoft.c,v 1.2.2.1 2002/11/21 23:34:23 sam Exp $ */ /* $OpenBSD: cryptosoft.c,v 1.35 2002/04/26 08:43:50 deraadt Exp $ */ @@ -24,7 +24,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.58 2021/04/05 01:22:22 knakahara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.59 2021/04/05 01:23:15 knakahara Exp $"); #include #include @@ -775,32 +775,31 @@ swcr_newsession(void *arg, u_int32_t *si i = 1; /* NB: to silence compiler warning */ if (swcr_sessions == NULL || i == swcr_sesnum) { + u_int32_t newnum; + struct swcr_data **newsessions; + if (swcr_sessions == NULL) { i = 1; /* We leave swcr_sessions[0] empty */ - swcr_sesnum = CRYPTO_SW_SESSIONS; + newnum = CRYPTO_SW_SESSIONS; } else - swcr_sesnum *= 2; + newnum = swcr_sesnum *= 2; - swd = kmem_zalloc(swcr_sesnum * sizeof(struct swcr_data *), + newsessions = kmem_zalloc(newnum * sizeof(struct swcr_data *), KM_NOSLEEP); - if (swd == NULL) { - /* Reset session number */ - if (swcr_sesnum == CRYPTO_SW_SESSIONS) -swcr_sesnum = 0; - else -swcr_sesnum /= 2; + if (newsessions == NULL) { return ENOBUFS; } /* Copy existing sessions */ if (swcr_sessions) { - memcpy(swd, swcr_sessions, - (swcr_sesnum / 2) * sizeof(struct swcr_data *)); + memcpy(newsessions, swcr_sessions, + swcr_sesnum * sizeof(struct swcr_data *)); kmem_free(swcr_sessions, -(swcr_sesnum / 2) * sizeof(struct swcr_data *)); + swcr_sesnum * sizeof(struct swcr_data *)); } - swcr_sessions = swd; + swcr_sesnum = newnum; + swcr_sessions = newsessions; } swd = _sessions[i];
CVS commit: src/sys/opencrypto
Module Name:src Committed By: knakahara Date: Mon Apr 5 01:22:22 UTC 2021 Modified Files: src/sys/opencrypto: cryptosoft.c Log Message: use kmem_{z,}alloc() instead of malloc() To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 src/sys/opencrypto/cryptosoft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptosoft.c diff -u src/sys/opencrypto/cryptosoft.c:1.57 src/sys/opencrypto/cryptosoft.c:1.58 --- src/sys/opencrypto/cryptosoft.c:1.57 Sat Jul 4 18:07:31 2020 +++ src/sys/opencrypto/cryptosoft.c Mon Apr 5 01:22:22 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptosoft.c,v 1.57 2020/07/04 18:07:31 riastradh Exp $ */ +/* $NetBSD: cryptosoft.c,v 1.58 2021/04/05 01:22:22 knakahara Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptosoft.c,v 1.2.2.1 2002/11/21 23:34:23 sam Exp $ */ /* $OpenBSD: cryptosoft.c,v 1.35 2002/04/26 08:43:50 deraadt Exp $ */ @@ -24,11 +24,11 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.57 2020/07/04 18:07:31 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.58 2021/04/05 01:22:22 knakahara Exp $"); #include #include -#include +#include #include #include #include @@ -711,7 +711,7 @@ swcr_compdec(struct cryptodesc *crd, con * copy in a buffer. */ - data = malloc(crd->crd_len, M_CRYPTO_DATA, M_NOWAIT); + data = kmem_alloc(crd->crd_len, KM_NOSLEEP); if (data == NULL) return (EINVAL); COPYDATA(outtype, buf, crd->crd_skip, crd->crd_len, data); @@ -722,7 +722,7 @@ swcr_compdec(struct cryptodesc *crd, con result = cxf->decompress(data, crd->crd_len, , *res_size); - free(data, M_CRYPTO_DATA); + kmem_free(data, crd->crd_len); if (result == 0) return EINVAL; @@ -781,8 +781,8 @@ swcr_newsession(void *arg, u_int32_t *si } else swcr_sesnum *= 2; - swd = malloc(swcr_sesnum * sizeof(struct swcr_data *), - M_CRYPTO_DATA, M_NOWAIT); + swd = kmem_zalloc(swcr_sesnum * sizeof(struct swcr_data *), + KM_NOSLEEP); if (swd == NULL) { /* Reset session number */ if (swcr_sesnum == CRYPTO_SW_SESSIONS) @@ -792,13 +792,12 @@ swcr_newsession(void *arg, u_int32_t *si return ENOBUFS; } - memset(swd, 0, swcr_sesnum * sizeof(struct swcr_data *)); - /* Copy existing sessions */ if (swcr_sessions) { memcpy(swd, swcr_sessions, (swcr_sesnum / 2) * sizeof(struct swcr_data *)); - free(swcr_sessions, M_CRYPTO_DATA); + kmem_free(swcr_sessions, +(swcr_sesnum / 2) * sizeof(struct swcr_data *)); } swcr_sessions = swd; @@ -808,12 +807,11 @@ swcr_newsession(void *arg, u_int32_t *si *sid = i; while (cri) { - *swd = malloc(sizeof **swd, M_CRYPTO_DATA, M_NOWAIT); + *swd = kmem_zalloc(sizeof **swd, KM_NOSLEEP); if (*swd == NULL) { swcr_freesession(NULL, i); return ENOBUFS; } - memset(*swd, 0, sizeof(struct swcr_data)); switch (cri->cri_alg) { case CRYPTO_DES_CBC:
CVS commit: src/sys/opencrypto
Module Name:src Committed By: knakahara Date: Mon Apr 5 01:22:22 UTC 2021 Modified Files: src/sys/opencrypto: cryptosoft.c Log Message: use kmem_{z,}alloc() instead of malloc() To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 src/sys/opencrypto/cryptosoft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sat Jul 4 18:07:31 UTC 2020 Modified Files: src/sys/opencrypto: cryptosoft.c Log Message: Fix kmem_free size in recent malloc->kmem conversion. Should address this bracket report that has my name all over it: https://mail-index.netbsd.org/current-users/2020/07/04/msg039059.html To generate a diff of this commit: cvs rdiff -u -r1.56 -r1.57 src/sys/opencrypto/cryptosoft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptosoft.c diff -u src/sys/opencrypto/cryptosoft.c:1.56 src/sys/opencrypto/cryptosoft.c:1.57 --- src/sys/opencrypto/cryptosoft.c:1.56 Mon Jun 29 23:34:48 2020 +++ src/sys/opencrypto/cryptosoft.c Sat Jul 4 18:07:31 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptosoft.c,v 1.56 2020/06/29 23:34:48 riastradh Exp $ */ +/* $NetBSD: cryptosoft.c,v 1.57 2020/07/04 18:07:31 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptosoft.c,v 1.2.2.1 2002/11/21 23:34:23 sam Exp $ */ /* $OpenBSD: cryptosoft.c,v 1.35 2002/04/26 08:43:50 deraadt Exp $ */ @@ -24,7 +24,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.56 2020/06/29 23:34:48 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.57 2020/07/04 18:07:31 riastradh Exp $"); #include #include @@ -1096,7 +1096,7 @@ swcr_freesession(void *arg, u_int64_t ti } if (swd->sw_octx) { explicit_memset(swd->sw_octx, 0, swd->sw_klen); -kmem_free(swd->sw_octx, axf->ctxsize); +kmem_free(swd->sw_octx, swd->sw_klen); } break;
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sat Jul 4 18:07:31 UTC 2020 Modified Files: src/sys/opencrypto: cryptosoft.c Log Message: Fix kmem_free size in recent malloc->kmem conversion. Should address this bracket report that has my name all over it: https://mail-index.netbsd.org/current-users/2020/07/04/msg039059.html To generate a diff of this commit: cvs rdiff -u -r1.56 -r1.57 src/sys/opencrypto/cryptosoft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Mon Jun 29 23:34:48 UTC 2020 Modified Files: src/sys/opencrypto: aesxcbcmac.c aesxcbcmac.h cryptosoft.c cryptosoft_xform.c files.opencrypto gmac.c gmac.h xform.c Log Message: opencrypto: Switch from legacy rijndael API to new aes API. While here, apply various rijndael->aes renames, reduce the size of aesxcbc_ctx by 480 bytes, and convert some malloc->kmem. Leave in the symbol enc_xform_rijndael128 for now, though, so this doesn't break any kernel ABI. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/opencrypto/aesxcbcmac.c \ src/sys/opencrypto/gmac.h cvs rdiff -u -r1.1 -r1.2 src/sys/opencrypto/aesxcbcmac.h cvs rdiff -u -r1.55 -r1.56 src/sys/opencrypto/cryptosoft.c cvs rdiff -u -r1.28 -r1.29 src/sys/opencrypto/cryptosoft_xform.c cvs rdiff -u -r1.29 -r1.30 src/sys/opencrypto/files.opencrypto \ src/sys/opencrypto/xform.c cvs rdiff -u -r1.3 -r1.4 src/sys/opencrypto/gmac.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/aesxcbcmac.c diff -u src/sys/opencrypto/aesxcbcmac.c:1.2 src/sys/opencrypto/aesxcbcmac.c:1.3 --- src/sys/opencrypto/aesxcbcmac.c:1.2 Mon Sep 26 14:50:54 2016 +++ src/sys/opencrypto/aesxcbcmac.c Mon Jun 29 23:34:48 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: aesxcbcmac.c,v 1.2 2016/09/26 14:50:54 christos Exp $ */ +/* $NetBSD: aesxcbcmac.c,v 1.3 2020/06/29 23:34:48 riastradh Exp $ */ /* * Copyright (C) 1995, 1996, 1997, 1998 and 2003 WIDE Project. @@ -30,11 +30,12 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: aesxcbcmac.c,v 1.2 2016/09/26 14:50:54 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: aesxcbcmac.c,v 1.3 2020/06/29 23:34:48 riastradh Exp $"); #include #include -#include + +#include #include @@ -47,24 +48,31 @@ aes_xcbc_mac_init(void *vctx, const uint { 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 }; static const uint8_t k3seed[AES_BLOCKSIZE] = { 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 }; - u_int32_t r_ks[(RIJNDAEL_MAXNR+1)*4]; + struct aesenc r_ks; aesxcbc_ctx *ctx; uint8_t k1[AES_BLOCKSIZE]; ctx = vctx; memset(ctx, 0, sizeof(*ctx)); - if ((ctx->r_nr = rijndaelKeySetupEnc(r_ks, key, keylen * 8)) == 0) - return -1; - rijndaelEncrypt(r_ks, ctx->r_nr, k1seed, k1); - rijndaelEncrypt(r_ks, ctx->r_nr, k2seed, ctx->k2); - rijndaelEncrypt(r_ks, ctx->r_nr, k3seed, ctx->k3); - if (rijndaelKeySetupEnc(ctx->r_k1s, k1, AES_BLOCKSIZE * 8) == 0) - return -1; - if (rijndaelKeySetupEnc(ctx->r_k2s, ctx->k2, AES_BLOCKSIZE * 8) == 0) - return -1; - if (rijndaelKeySetupEnc(ctx->r_k3s, ctx->k3, AES_BLOCKSIZE * 8) == 0) - return -1; + switch (keylen) { + case 16: + ctx->r_nr = aes_setenckey128(_ks, key); + break; + case 24: + ctx->r_nr = aes_setenckey192(_ks, key); + break; + case 32: + ctx->r_nr = aes_setenckey256(_ks, key); + break; + } + aes_enc(_ks, k1seed, k1, ctx->r_nr); + aes_enc(_ks, k2seed, ctx->k2, ctx->r_nr); + aes_enc(_ks, k3seed, ctx->k3, ctx->r_nr); + aes_setenckey128(>r_k1s, k1); + + explicit_memset(_ks, 0, sizeof(r_ks)); + explicit_memset(k1, 0, sizeof(k1)); return 0; } @@ -83,7 +91,7 @@ aes_xcbc_mac_loop(void *vctx, const uint if (ctx->buflen == sizeof(ctx->buf)) { for (i = 0; i < sizeof(ctx->e); i++) ctx->buf[i] ^= ctx->e[i]; - rijndaelEncrypt(ctx->r_k1s, ctx->r_nr, ctx->buf, ctx->e); + aes_enc(>r_k1s, ctx->buf, ctx->e, ctx->r_nr); ctx->buflen = 0; } if (ctx->buflen + len < sizeof(ctx->buf)) { @@ -96,7 +104,7 @@ aes_xcbc_mac_loop(void *vctx, const uint sizeof(ctx->buf) - ctx->buflen); for (i = 0; i < sizeof(ctx->e); i++) ctx->buf[i] ^= ctx->e[i]; - rijndaelEncrypt(ctx->r_k1s, ctx->r_nr, ctx->buf, ctx->e); + aes_enc(>r_k1s, ctx->buf, ctx->e, ctx->r_nr); addr += sizeof(ctx->buf) - ctx->buflen; ctx->buflen = 0; } @@ -105,7 +113,7 @@ aes_xcbc_mac_loop(void *vctx, const uint memcpy(buf, addr, AES_BLOCKSIZE); for (i = 0; i < sizeof(buf); i++) buf[i] ^= ctx->e[i]; - rijndaelEncrypt(ctx->r_k1s, ctx->r_nr, buf, ctx->e); + aes_enc(>r_k1s, buf, ctx->e, ctx->r_nr); addr += AES_BLOCKSIZE; } if (addr < ep) { @@ -129,7 +137,7 @@ aes_xcbc_mac_result(uint8_t *addr, void ctx->buf[i] ^= ctx->e[i]; ctx->buf[i] ^= ctx->k2[i]; } - rijndaelEncrypt(ctx->r_k1s, ctx->r_nr, ctx->buf, digest); + aes_enc(>r_k1s, ctx->buf, digest, ctx->r_nr); } else { for (i = ctx->buflen; i < sizeof(ctx->buf); i++) ctx->buf[i] = (i == ctx->buflen) ? 0x80 : 0x00; @@ -137,7 +145,7 @@ aes_xcbc_mac_result(uint8_t *addr, void ctx->buf[i] ^= ctx->e[i]; ctx->buf[i] ^= ctx->k3[i]; } - rijndaelEncrypt(ctx->r_k1s, ctx->r_nr, ctx->buf, digest); + aes_enc(>r_k1s, ctx->buf, digest, ctx->r_nr); } memcpy(addr, digest, sizeof(digest)); Index: src/sys/opencrypto/gmac.h diff -u src/sys/opencrypto/gmac.h:1.2 src/sys/opencrypto/gmac.h:1.3 --- src/sys/opencrypto/gmac.h:1.2 Thu Jun 9 14:47:42 2011 +++
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Mon Jun 29 23:34:48 UTC 2020 Modified Files: src/sys/opencrypto: aesxcbcmac.c aesxcbcmac.h cryptosoft.c cryptosoft_xform.c files.opencrypto gmac.c gmac.h xform.c Log Message: opencrypto: Switch from legacy rijndael API to new aes API. While here, apply various rijndael->aes renames, reduce the size of aesxcbc_ctx by 480 bytes, and convert some malloc->kmem. Leave in the symbol enc_xform_rijndael128 for now, though, so this doesn't break any kernel ABI. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/opencrypto/aesxcbcmac.c \ src/sys/opencrypto/gmac.h cvs rdiff -u -r1.1 -r1.2 src/sys/opencrypto/aesxcbcmac.h cvs rdiff -u -r1.55 -r1.56 src/sys/opencrypto/cryptosoft.c cvs rdiff -u -r1.28 -r1.29 src/sys/opencrypto/cryptosoft_xform.c cvs rdiff -u -r1.29 -r1.30 src/sys/opencrypto/files.opencrypto \ src/sys/opencrypto/xform.c cvs rdiff -u -r1.3 -r1.4 src/sys/opencrypto/gmac.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun Jun 14 23:23:55 UTC 2020 Modified Files: src/sys/opencrypto: cryptosoft.c Log Message: swcrypto(4): Simplify iv generation logic with cprng_fast. To generate a diff of this commit: cvs rdiff -u -r1.54 -r1.55 src/sys/opencrypto/cryptosoft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptosoft.c diff -u src/sys/opencrypto/cryptosoft.c:1.54 src/sys/opencrypto/cryptosoft.c:1.55 --- src/sys/opencrypto/cryptosoft.c:1.54 Sat Oct 12 00:49:30 2019 +++ src/sys/opencrypto/cryptosoft.c Sun Jun 14 23:23:55 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptosoft.c,v 1.54 2019/10/12 00:49:30 christos Exp $ */ +/* $NetBSD: cryptosoft.c,v 1.55 2020/06/14 23:23:55 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptosoft.c,v 1.2.2.1 2002/11/21 23:34:23 sam Exp $ */ /* $OpenBSD: cryptosoft.c,v 1.35 2002/04/26 08:43:50 deraadt Exp $ */ @@ -24,7 +24,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.54 2019/10/12 00:49:30 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.55 2020/06/14 23:23:55 riastradh Exp $"); #include #include @@ -112,25 +112,7 @@ swcr_encdec(struct cryptodesc *crd, cons } else if (exf->reinit) { exf->reinit(sw->sw_kschedule, 0, iv); } else { - /* Get random IV */ - for (i = 0; - i + sizeof (u_int32_t) <= EALG_MAX_BLOCK_LEN; - i += sizeof (u_int32_t)) { -u_int32_t temp = cprng_fast32(); - -memcpy(iv + i, , sizeof(u_int32_t)); - } - /* - * What if the block size is not a multiple - * of sizeof (u_int32_t), which is the size of - * what arc4random() returns ? - */ - if (EALG_MAX_BLOCK_LEN % sizeof (u_int32_t) != 0) { -u_int32_t temp = cprng_fast32(); - -bcopy (, iv + i, -EALG_MAX_BLOCK_LEN - i); - } + cprng_fast(iv, EALG_MAX_BLOCK_LEN); } /* Do we need to write the IV */
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sun Jun 14 23:23:55 UTC 2020 Modified Files: src/sys/opencrypto: cryptosoft.c Log Message: swcrypto(4): Simplify iv generation logic with cprng_fast. To generate a diff of this commit: cvs rdiff -u -r1.54 -r1.55 src/sys/opencrypto/cryptosoft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: pgoyette Date: Wed Apr 8 15:27:18 UTC 2020 Modified Files: src/sys/opencrypto: crypto.c Log Message: Revert previous change to use SYSCTL_SETUP since it breaks on macppc. For some reason, the crypto module fails to link, and this results in opencrypto sysctl failures. Should resolve PR kern/55154 To generate a diff of this commit: cvs rdiff -u -r1.113 -r1.114 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/crypto.c diff -u src/sys/opencrypto/crypto.c:1.113 src/sys/opencrypto/crypto.c:1.114 --- src/sys/opencrypto/crypto.c:1.113 Mon Mar 16 21:20:12 2020 +++ src/sys/opencrypto/crypto.c Wed Apr 8 15:27:18 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: crypto.c,v 1.113 2020/03/16 21:20:12 pgoyette Exp $ */ +/* $NetBSD: crypto.c,v 1.114 2020/04/08 15:27:18 pgoyette Exp $ */ /* $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $ */ /* $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */ @@ -53,7 +53,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.113 2020/03/16 21:20:12 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.114 2020/04/08 15:27:18 pgoyette Exp $"); #include #include @@ -383,7 +383,8 @@ int crypto_userasymcrypto = 1; /* userla */ int crypto_devallowsoft = 1; /* only use hardware crypto */ -SYSCTL_SETUP(sysctl_opencrypto_setup, "opencrypto sysctl") +static void +sysctl_opencrypto_setup(struct sysctllog **clog) { const struct sysctlnode *ocnode; const struct sysctlnode *retqnode, *retkqnode; @@ -518,6 +519,8 @@ static struct cryptostats cryptostats; static int crypto_timing = 0; #endif +static struct sysctllog *sysctl_opencrypto_clog; + static void crypto_crp_ret_qs_init(void) { @@ -584,6 +587,8 @@ crypto_init0(void) return crypto_destroy(false); } + sysctl_opencrypto_setup(_opencrypto_clog); + return 0; } @@ -650,6 +655,9 @@ crypto_destroy(bool exit_kthread) } } + if (sysctl_opencrypto_clog != NULL) + sysctl_teardown(_opencrypto_clog); + if (crypto_ret_si != NULL) softint_disestablish(crypto_ret_si);
CVS commit: src/sys/opencrypto
Module Name:src Committed By: pgoyette Date: Wed Apr 8 15:27:18 UTC 2020 Modified Files: src/sys/opencrypto: crypto.c Log Message: Revert previous change to use SYSCTL_SETUP since it breaks on macppc. For some reason, the crypto module fails to link, and this results in opencrypto sysctl failures. Should resolve PR kern/55154 To generate a diff of this commit: cvs rdiff -u -r1.113 -r1.114 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sat Feb 1 13:48:09 UTC 2020 Modified Files: src/sys/opencrypto: crypto.c Log Message: softint_disestablish does xc_barrier(0) for us already. To generate a diff of this commit: cvs rdiff -u -r1.111 -r1.112 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/crypto.c diff -u src/sys/opencrypto/crypto.c:1.111 src/sys/opencrypto/crypto.c:1.112 --- src/sys/opencrypto/crypto.c:1.111 Sat Feb 1 12:54:30 2020 +++ src/sys/opencrypto/crypto.c Sat Feb 1 13:48:08 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: crypto.c,v 1.111 2020/02/01 12:54:30 riastradh Exp $ */ +/* $NetBSD: crypto.c,v 1.112 2020/02/01 13:48:08 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $ */ /* $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */ @@ -53,7 +53,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.111 2020/02/01 12:54:30 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.112 2020/02/01 13:48:08 riastradh Exp $"); #include #include @@ -644,10 +644,7 @@ crypto_destroy(bool exit_kthread) * prohibit touch crypto_drivers[] and each element after here. */ - /* - * Ensure cryptoret_softint() is never scheduled and then wait - * for last softint_execute(). - */ + /* Ensure cryptoret_softint() is never scheduled again. */ for (i = 0; i < ncpu; i++) { struct crypto_crp_ret_qs *qs; struct cpu_info *ci = cpu_lookup(i); @@ -656,7 +653,6 @@ crypto_destroy(bool exit_kthread) qs->crp_ret_q_exit_flag = true; crypto_put_crp_ret_qs(ci); } - xc_barrier(0); } if (sysctl_opencrypto_clog != NULL)
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sat Feb 1 13:48:09 UTC 2020 Modified Files: src/sys/opencrypto: crypto.c Log Message: softint_disestablish does xc_barrier(0) for us already. To generate a diff of this commit: cvs rdiff -u -r1.111 -r1.112 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sat Feb 1 12:54:30 UTC 2020 Modified Files: src/sys/opencrypto: crypto.c Log Message: Switch opencrypto to percpu_create. Can't sleep for allocation in percpu_foreach. To generate a diff of this commit: cvs rdiff -u -r1.110 -r1.111 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/crypto.c diff -u src/sys/opencrypto/crypto.c:1.110 src/sys/opencrypto/crypto.c:1.111 --- src/sys/opencrypto/crypto.c:1.110 Sun Oct 6 15:11:17 2019 +++ src/sys/opencrypto/crypto.c Sat Feb 1 12:54:30 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: crypto.c,v 1.110 2019/10/06 15:11:17 uwe Exp $ */ +/* $NetBSD: crypto.c,v 1.111 2020/02/01 12:54:30 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $ */ /* $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */ @@ -53,7 +53,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.110 2019/10/06 15:11:17 uwe Exp $"); +__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.111 2020/02/01 12:54:30 riastradh Exp $"); #include #include @@ -562,8 +562,8 @@ crypto_init0(void) cryptkop_cache = pool_cache_init(sizeof(struct cryptkop), coherency_unit, 0, 0, "cryptkop", NULL, IPL_NET, NULL, NULL, NULL); - crypto_crp_qs_percpu = percpu_alloc(sizeof(struct crypto_crp_qs)); - percpu_foreach(crypto_crp_qs_percpu, crypto_crp_qs_init_pc, NULL); + crypto_crp_qs_percpu = percpu_create(sizeof(struct crypto_crp_qs), + crypto_crp_qs_init_pc, /*XXX*/NULL, NULL); crypto_crp_ret_qs_init();
CVS commit: src/sys/opencrypto
Module Name:src Committed By: riastradh Date: Sat Feb 1 12:54:30 UTC 2020 Modified Files: src/sys/opencrypto: crypto.c Log Message: Switch opencrypto to percpu_create. Can't sleep for allocation in percpu_foreach. To generate a diff of this commit: cvs rdiff -u -r1.110 -r1.111 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: pgoyette Date: Mon Jan 27 17:11:27 UTC 2020 Modified Files: src/sys/opencrypto: compat_crypto_50.c Log Message: Remove left-over #includes To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/opencrypto/compat_crypto_50.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/compat_crypto_50.c diff -u src/sys/opencrypto/compat_crypto_50.c:1.1 src/sys/opencrypto/compat_crypto_50.c:1.2 --- src/sys/opencrypto/compat_crypto_50.c:1.1 Mon Jan 27 17:09:17 2020 +++ src/sys/opencrypto/compat_crypto_50.c Mon Jan 27 17:11:27 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: compat_crypto_50.c,v 1.1 2020/01/27 17:09:17 pgoyette Exp $ */ +/* $NetBSD: compat_crypto_50.c,v 1.2 2020/01/27 17:11:27 pgoyette Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -30,28 +30,10 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: compat_crypto_50.c,v 1.1 2020/01/27 17:09:17 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: compat_crypto_50.c,v 1.2 2020/01/27 17:11:27 pgoyette Exp $"); #include #include -/* XXX PRG -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -XXX PRG */ #include #include
CVS commit: src/sys/opencrypto
Module Name:src Committed By: pgoyette Date: Mon Jan 27 17:11:27 UTC 2020 Modified Files: src/sys/opencrypto: compat_crypto_50.c Log Message: Remove left-over #includes To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/opencrypto/compat_crypto_50.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: pgoyette Date: Mon Jan 27 02:56:15 UTC 2020 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: If we get an error from devsw_attach(), don't destroy the error value, since we need to return it to our caller. While we're here, improve the value of the debug message by actually printing the error value. To generate a diff of this commit: cvs rdiff -u -r1.103 -r1.104 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptodev.c diff -u src/sys/opencrypto/cryptodev.c:1.103 src/sys/opencrypto/cryptodev.c:1.104 --- src/sys/opencrypto/cryptodev.c:1.103 Thu Jan 16 15:29:24 2020 +++ src/sys/opencrypto/cryptodev.c Mon Jan 27 02:56:15 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.c,v 1.103 2020/01/16 15:29:24 christos Exp $ */ +/* $NetBSD: cryptodev.c,v 1.104 2020/01/27 02:56:15 pgoyette Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */ /* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */ @@ -64,7 +64,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.103 2020/01/16 15:29:24 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.104 2020/01/27 02:56:15 pgoyette Exp $"); #include #include @@ -2201,6 +2201,7 @@ crypto_modcmd(modcmd_t cmd, void *arg) { int error = 0; #ifdef _MODULE + int error2; devmajor_t cmajor = NODEVMAJOR, bmajor = NODEVMAJOR; #endif @@ -2235,14 +2236,14 @@ crypto_modcmd(modcmd_t cmd, void *arg) error = devsw_attach(crypto_cd.cd_name, NULL, , _cdevsw, ); if (error) { - error = config_cfdata_detach(crypto_cfdata); - if (error) { -return error; + error2 = config_cfdata_detach(crypto_cfdata); + if (error2) { +return error2; } config_cfattach_detach(crypto_cd.cd_name, _ca); config_cfdriver_detach(_cd); - aprint_error("%s: unable to register devsw\n", -crypto_cd.cd_name); + aprint_error("%s: unable to register devsw, error %d\n", +crypto_cd.cd_name, error); return error; }
CVS commit: src/sys/opencrypto
Module Name:src Committed By: pgoyette Date: Mon Jan 27 02:56:15 UTC 2020 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: If we get an error from devsw_attach(), don't destroy the error value, since we need to return it to our caller. While we're here, improve the value of the debug message by actually printing the error value. To generate a diff of this commit: cvs rdiff -u -r1.103 -r1.104 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: christos Date: Thu Jan 16 15:29:24 UTC 2020 Modified Files: src/sys/opencrypto: cryptodev.c ocryptodev.c Log Message: Initialize the session variable to an impossible session to prevent compiler warnings. To generate a diff of this commit: cvs rdiff -u -r1.102 -r1.103 src/sys/opencrypto/cryptodev.c cvs rdiff -u -r1.14 -r1.15 src/sys/opencrypto/ocryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptodev.c diff -u src/sys/opencrypto/cryptodev.c:1.102 src/sys/opencrypto/cryptodev.c:1.103 --- src/sys/opencrypto/cryptodev.c:1.102 Fri Nov 29 03:30:30 2019 +++ src/sys/opencrypto/cryptodev.c Thu Jan 16 10:29:24 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.c,v 1.102 2019/11/29 08:30:30 hikaru Exp $ */ +/* $NetBSD: cryptodev.c,v 1.103 2020/01/16 15:29:24 christos Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */ /* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */ @@ -64,7 +64,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.102 2019/11/29 08:30:30 hikaru Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.103 2020/01/16 15:29:24 christos Exp $"); #include #include @@ -1787,6 +1787,7 @@ cryptodev_msession(struct fcrypt *fcr, s s_op.key = sn_ops->key; s_op.mackeylen = sn_ops->mackeylen; s_op.mackey = sn_ops->mackey; + s_op.ses = ~0; sn_ops->status = cryptodev_session(fcr, _op); Index: src/sys/opencrypto/ocryptodev.c diff -u src/sys/opencrypto/ocryptodev.c:1.14 src/sys/opencrypto/ocryptodev.c:1.15 --- src/sys/opencrypto/ocryptodev.c:1.14 Wed Dec 11 21:15:43 2019 +++ src/sys/opencrypto/ocryptodev.c Thu Jan 16 10:29:24 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: ocryptodev.c,v 1.14 2019/12/12 02:15:43 pgoyette Exp $ */ +/* $NetBSD: ocryptodev.c,v 1.15 2020/01/16 15:29:24 christos Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */ /* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */ @@ -69,7 +69,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ocryptodev.c,v 1.14 2019/12/12 02:15:43 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ocryptodev.c,v 1.15 2020/01/16 15:29:24 christos Exp $"); #include #include @@ -279,6 +279,7 @@ ocryptodev_msession(struct fcrypt *fcr, os_op.key = osn_ops->key; os_op.mackeylen = osn_ops->mackeylen; os_op.mackey = osn_ops->mackey; + os_op.ses = ~0; osn_ops->status = ocryptodev_session(fcr, _op); osn_ops->ses = os_op.ses;
CVS commit: src/sys/opencrypto
Module Name:src Committed By: christos Date: Thu Jan 16 15:29:24 UTC 2020 Modified Files: src/sys/opencrypto: cryptodev.c ocryptodev.c Log Message: Initialize the session variable to an impossible session to prevent compiler warnings. To generate a diff of this commit: cvs rdiff -u -r1.102 -r1.103 src/sys/opencrypto/cryptodev.c cvs rdiff -u -r1.14 -r1.15 src/sys/opencrypto/ocryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: hikaru Date: Fri Nov 29 08:30:31 UTC 2019 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): accept CRYPTO_SHA2_384_HMAC and CRYPTO_SHA2_512_HMAC. To generate a diff of this commit: cvs rdiff -u -r1.101 -r1.102 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptodev.c diff -u src/sys/opencrypto/cryptodev.c:1.101 src/sys/opencrypto/cryptodev.c:1.102 --- src/sys/opencrypto/cryptodev.c:1.101 Thu Jun 13 02:02:45 2019 +++ src/sys/opencrypto/cryptodev.c Fri Nov 29 08:30:30 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.c,v 1.101 2019/06/13 02:02:45 christos Exp $ */ +/* $NetBSD: cryptodev.c,v 1.102 2019/11/29 08:30:30 hikaru Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */ /* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */ @@ -64,7 +64,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.101 2019/06/13 02:02:45 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.102 2019/11/29 08:30:30 hikaru Exp $"); #include #include @@ -1644,6 +1644,12 @@ cryptodev_session(struct fcrypt *fcr, st return EINVAL; } break; + case CRYPTO_SHA2_384_HMAC: + thash = _hash_hmac_sha2_384; + break; + case CRYPTO_SHA2_512_HMAC: + thash = _hash_hmac_sha2_512; + break; case CRYPTO_RIPEMD160_HMAC: thash = _hash_hmac_ripemd_160; break;
CVS commit: src/sys/opencrypto
Module Name:src Committed By: hikaru Date: Fri Nov 29 08:30:31 UTC 2019 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: crypto(4): accept CRYPTO_SHA2_384_HMAC and CRYPTO_SHA2_512_HMAC. To generate a diff of this commit: cvs rdiff -u -r1.101 -r1.102 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: hikaru Date: Fri Nov 29 07:20:03 UTC 2019 Modified Files: src/sys/opencrypto: cryptodev.h Log Message: HMAC-SHA-512 has 32 bytes MAC. To generate a diff of this commit: cvs rdiff -u -r1.39 -r1.40 src/sys/opencrypto/cryptodev.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: hikaru Date: Fri Nov 29 07:20:03 UTC 2019 Modified Files: src/sys/opencrypto: cryptodev.h Log Message: HMAC-SHA-512 has 32 bytes MAC. To generate a diff of this commit: cvs rdiff -u -r1.39 -r1.40 src/sys/opencrypto/cryptodev.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptodev.h diff -u src/sys/opencrypto/cryptodev.h:1.39 src/sys/opencrypto/cryptodev.h:1.40 --- src/sys/opencrypto/cryptodev.h:1.39 Wed Jul 26 06:44:50 2017 +++ src/sys/opencrypto/cryptodev.h Fri Nov 29 07:20:03 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.h,v 1.39 2017/07/26 06:44:50 knakahara Exp $ */ +/* $NetBSD: cryptodev.h,v 1.40 2019/11/29 07:20:03 hikaru Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.h,v 1.2.2.6 2003/07/02 17:04:50 sam Exp $ */ /* $OpenBSD: cryptodev.h,v 1.33 2002/07/17 23:52:39 art Exp $ */ @@ -262,7 +262,7 @@ struct crypt_sgop { struct session_n_op * sessions; }; -#define CRYPTO_MAX_MAC_LEN 20 +#define CRYPTO_MAX_MAC_LEN 32 /* Keep this updated */ /* bignum parameter, in packed bytes, ... */ struct crparam {
CVS commit: src/sys/opencrypto
Module Name:src Committed By: christos Date: Sat Oct 12 00:49:30 UTC 2019 Modified Files: src/sys/opencrypto: cryptosoft.c cryptosoft_xform.c Log Message: add (void *) intermediate casts to elide gcc function cast warnings. This is the simplest solution; choices: - add pragmas, complex and ugly (need to be gcc-specific) - add -Wno to COPTS. Needs to be done in many makefiles because of rump - add intermediate functions: slows down things To generate a diff of this commit: cvs rdiff -u -r1.53 -r1.54 src/sys/opencrypto/cryptosoft.c cvs rdiff -u -r1.27 -r1.28 src/sys/opencrypto/cryptosoft_xform.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptosoft.c diff -u src/sys/opencrypto/cryptosoft.c:1.53 src/sys/opencrypto/cryptosoft.c:1.54 --- src/sys/opencrypto/cryptosoft.c:1.53 Thu Jul 11 19:27:24 2019 +++ src/sys/opencrypto/cryptosoft.c Fri Oct 11 20:49:30 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptosoft.c,v 1.53 2019/07/11 23:27:24 christos Exp $ */ +/* $NetBSD: cryptosoft.c,v 1.54 2019/10/12 00:49:30 christos Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptosoft.c,v 1.2.2.1 2002/11/21 23:34:23 sam Exp $ */ /* $OpenBSD: cryptosoft.c,v 1.35 2002/04/26 08:43:50 deraadt Exp $ */ @@ -24,7 +24,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.53 2019/07/11 23:27:24 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.54 2019/10/12 00:49:30 christos Exp $"); #include #include @@ -500,7 +500,7 @@ swcr_authcompute(struct cryptop *crp, st break; case CRYPTO_BUF_MBUF: err = m_apply((struct mbuf *) buf, crd->crd_skip, crd->crd_len, - (int (*)(void*, void *, unsigned int)) axf->Update, + (int (*)(void*, void *, unsigned int))(void *)axf->Update, (void *) ); if (err) return err; @@ -508,7 +508,7 @@ swcr_authcompute(struct cryptop *crp, st case CRYPTO_BUF_IOV: err = cuio_apply((struct uio *) buf, crd->crd_skip, crd->crd_len, - (int (*)(void *, void *, unsigned int)) axf->Update, + (int (*)(void *, void *, unsigned int))(void *)axf->Update, (void *) ); if (err) { return err; Index: src/sys/opencrypto/cryptosoft_xform.c diff -u src/sys/opencrypto/cryptosoft_xform.c:1.27 src/sys/opencrypto/cryptosoft_xform.c:1.28 --- src/sys/opencrypto/cryptosoft_xform.c:1.27 Thu Nov 27 15:30:21 2014 +++ src/sys/opencrypto/cryptosoft_xform.c Fri Oct 11 20:49:30 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptosoft_xform.c,v 1.27 2014/11/27 20:30:21 christos Exp $ */ +/* $NetBSD: cryptosoft_xform.c,v 1.28 2019/10/12 00:49:30 christos Exp $ */ /* $FreeBSD: src/sys/opencrypto/xform.c,v 1.1.2.1 2002/11/21 23:34:23 sam Exp $ */ /* $OpenBSD: xform.c,v 1.19 2002/08/16 22:47:25 dhartmei Exp $ */ @@ -40,7 +40,7 @@ */ #include -__KERNEL_RCSID(1, "$NetBSD: cryptosoft_xform.c,v 1.27 2014/11/27 20:30:21 christos Exp $"); +__KERNEL_RCSID(1, "$NetBSD: cryptosoft_xform.c,v 1.28 2019/10/12 00:49:30 christos Exp $"); #include #include @@ -313,26 +313,26 @@ static const struct swcr_auth_hash swcr_ static const struct swcr_auth_hash swcr_auth_hash_hmac_sha2_256 = { _hash_hmac_sha2_256, sizeof(SHA256_CTX), - (void (*)(void *)) SHA256_Init, NULL, NULL, SHA256Update_int, - (void (*)(u_int8_t *, void *)) SHA256_Final + (void (*)(void *))(void *)SHA256_Init, NULL, NULL, SHA256Update_int, + (void (*)(u_int8_t *, void *))(void *)SHA256_Final }; static const struct swcr_auth_hash swcr_auth_hash_hmac_sha2_384 = { _hash_hmac_sha2_384, sizeof(SHA384_CTX), - (void (*)(void *)) SHA384_Init, NULL, NULL, SHA384Update_int, - (void (*)(u_int8_t *, void *)) SHA384_Final + (void (*)(void *))(void *)SHA384_Init, NULL, NULL, SHA384Update_int, + (void (*)(u_int8_t *, void *))(void *)SHA384_Final }; static const struct swcr_auth_hash swcr_auth_hash_hmac_sha2_512 = { _hash_hmac_sha2_512, sizeof(SHA512_CTX), - (void (*)(void *)) SHA512_Init, NULL, NULL, SHA512Update_int, - (void (*)(u_int8_t *, void *)) SHA512_Final + (void (*)(void *))(void *)SHA512_Init, NULL, NULL, SHA512Update_int, + (void (*)(u_int8_t *, void *))(void *)SHA512_Final }; static const struct swcr_auth_hash swcr_auth_hash_aes_xcbc_mac = { _hash_aes_xcbc_mac_96, sizeof(aesxcbc_ctx), null_init, - (void (*)(void *, const u_int8_t *, u_int16_t))aes_xcbc_mac_init, + (void (*)(void *, const u_int8_t *, u_int16_t))(void *)aes_xcbc_mac_init, NULL, aes_xcbc_mac_loop, aes_xcbc_mac_result };
CVS commit: src/sys/opencrypto
Module Name:src Committed By: christos Date: Sat Oct 12 00:49:30 UTC 2019 Modified Files: src/sys/opencrypto: cryptosoft.c cryptosoft_xform.c Log Message: add (void *) intermediate casts to elide gcc function cast warnings. This is the simplest solution; choices: - add pragmas, complex and ugly (need to be gcc-specific) - add -Wno to COPTS. Needs to be done in many makefiles because of rump - add intermediate functions: slows down things To generate a diff of this commit: cvs rdiff -u -r1.53 -r1.54 src/sys/opencrypto/cryptosoft.c cvs rdiff -u -r1.27 -r1.28 src/sys/opencrypto/cryptosoft_xform.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: christos Date: Thu Jul 11 23:28:17 UTC 2019 Modified Files: src/sys/opencrypto: crypto.c Log Message: relinguish our lock while we are autoloading. To generate a diff of this commit: cvs rdiff -u -r1.107 -r1.108 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: christos Date: Thu Jul 11 23:28:17 UTC 2019 Modified Files: src/sys/opencrypto: crypto.c Log Message: relinguish our lock while we are autoloading. To generate a diff of this commit: cvs rdiff -u -r1.107 -r1.108 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/crypto.c diff -u src/sys/opencrypto/crypto.c:1.107 src/sys/opencrypto/crypto.c:1.108 --- src/sys/opencrypto/crypto.c:1.107 Wed Jun 12 22:07:31 2019 +++ src/sys/opencrypto/crypto.c Thu Jul 11 19:28:17 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: crypto.c,v 1.107 2019/06/13 02:07:31 christos Exp $ */ +/* $NetBSD: crypto.c,v 1.108 2019/07/11 23:28:17 christos Exp $ */ /* $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $ */ /* $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */ @@ -53,7 +53,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.107 2019/06/13 02:07:31 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.108 2019/07/11 23:28:17 christos Exp $"); #include #include @@ -812,7 +812,9 @@ again: } if (best == NULL && hard == 0 && error == 0) { + mutex_exit(_drv_mtx); error = module_autoload("swcrypto", MODULE_CLASS_DRIVER); + mutex_enter(_drv_mtx); if (error == 0) { error = EINVAL; goto again;
CVS commit: src/sys/opencrypto
Module Name:src Committed By: christos Date: Thu Jul 11 23:27:24 UTC 2019 Modified Files: src/sys/opencrypto: cryptosoft.c Log Message: Disable unloading until we keep track of references To generate a diff of this commit: cvs rdiff -u -r1.52 -r1.53 src/sys/opencrypto/cryptosoft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptosoft.c diff -u src/sys/opencrypto/cryptosoft.c:1.52 src/sys/opencrypto/cryptosoft.c:1.53 --- src/sys/opencrypto/cryptosoft.c:1.52 Fri Jun 23 07:41:58 2017 +++ src/sys/opencrypto/cryptosoft.c Thu Jul 11 19:27:24 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptosoft.c,v 1.52 2017/06/23 11:41:58 knakahara Exp $ */ +/* $NetBSD: cryptosoft.c,v 1.53 2019/07/11 23:27:24 christos Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptosoft.c,v 1.2.2.1 2002/11/21 23:34:23 sam Exp $ */ /* $OpenBSD: cryptosoft.c,v 1.35 2002/04/26 08:43:50 deraadt Exp $ */ @@ -24,7 +24,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.52 2017/06/23 11:41:58 knakahara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.53 2019/07/11 23:27:24 christos Exp $"); #include #include @@ -1447,6 +1447,10 @@ swcrypto_modcmd(modcmd_t cmd, void *arg) #endif return error; case MODULE_CMD_FINI: +#if 1 + // XXX: Need to keep track if we are in use. + return ENOTTY; +#else error = config_cfdata_detach(swcrypto_cfdata); if (error) { return error; @@ -1456,6 +1460,7 @@ swcrypto_modcmd(modcmd_t cmd, void *arg) config_cfdriver_detach(_cd); return 0; +#endif default: return ENOTTY; }
CVS commit: src/sys/opencrypto
Module Name:src Committed By: christos Date: Thu Jul 11 23:27:24 UTC 2019 Modified Files: src/sys/opencrypto: cryptosoft.c Log Message: Disable unloading until we keep track of references To generate a diff of this commit: cvs rdiff -u -r1.52 -r1.53 src/sys/opencrypto/cryptosoft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: christos Date: Thu Jun 13 02:07:31 UTC 2019 Modified Files: src/sys/opencrypto: crypto.c Log Message: Try to load swcrypto if we we did not find any software drivers. To generate a diff of this commit: cvs rdiff -u -r1.106 -r1.107 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/crypto.c diff -u src/sys/opencrypto/crypto.c:1.106 src/sys/opencrypto/crypto.c:1.107 --- src/sys/opencrypto/crypto.c:1.106 Tue Jun 5 21:49:09 2018 +++ src/sys/opencrypto/crypto.c Wed Jun 12 22:07:31 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: crypto.c,v 1.106 2018/06/06 01:49:09 maya Exp $ */ +/* $NetBSD: crypto.c,v 1.107 2019/06/13 02:07:31 christos Exp $ */ /* $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $ */ /* $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */ @@ -53,7 +53,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.106 2018/06/06 01:49:09 maya Exp $"); +__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.107 2019/06/13 02:07:31 christos Exp $"); #include #include @@ -746,6 +746,7 @@ crypto_select_driver_lock(struct cryptoi u_int32_t hid; int accept; struct cryptocap *cap, *best; + int error = 0; best = NULL; /* @@ -810,6 +811,14 @@ again: goto again; } + if (best == NULL && hard == 0 && error == 0) { + error = module_autoload("swcrypto", MODULE_CLASS_DRIVER); + if (error == 0) { + error = EINVAL; + goto again; + } + } + return best; }
CVS commit: src/sys/opencrypto
Module Name:src Committed By: christos Date: Thu Jun 13 02:07:31 UTC 2019 Modified Files: src/sys/opencrypto: crypto.c Log Message: Try to load swcrypto if we we did not find any software drivers. To generate a diff of this commit: cvs rdiff -u -r1.106 -r1.107 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: christos Date: Thu Jun 13 02:02:45 UTC 2019 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: don't always panic when modunload crypto (int the pool destroy code, because the pools are busy). XXX: this is still racy; we need to prevent creating more sessions while destroying. To generate a diff of this commit: cvs rdiff -u -r1.100 -r1.101 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptodev.c diff -u src/sys/opencrypto/cryptodev.c:1.100 src/sys/opencrypto/cryptodev.c:1.101 --- src/sys/opencrypto/cryptodev.c:1.100 Fri Mar 1 06:06:57 2019 +++ src/sys/opencrypto/cryptodev.c Wed Jun 12 22:02:45 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.c,v 1.100 2019/03/01 11:06:57 pgoyette Exp $ */ +/* $NetBSD: cryptodev.c,v 1.101 2019/06/13 02:02:45 christos Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */ /* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */ @@ -64,7 +64,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.100 2019/03/01 11:06:57 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.101 2019/06/13 02:02:45 christos Exp $"); #include #include @@ -2246,6 +2246,8 @@ crypto_modcmd(modcmd_t cmd, void *arg) return error; case MODULE_CMD_FINI: #ifdef _MODULE + if (crypto_refcount != 0) + return EBUSY; error = config_cfdata_detach(crypto_cfdata); if (error) { return error;
CVS commit: src/sys/opencrypto
Module Name:src Committed By: christos Date: Thu Jun 13 02:02:45 UTC 2019 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: don't always panic when modunload crypto (int the pool destroy code, because the pools are busy). XXX: this is still racy; we need to prevent creating more sessions while destroying. To generate a diff of this commit: cvs rdiff -u -r1.100 -r1.101 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: knakahara Date: Mon Jan 8 23:34:56 UTC 2018 Modified Files: src/sys/opencrypto: crypto.c Log Message: Fix PR kern/52910. Reported and implemented a patch by Sevan Janiyan, thanks. To generate a diff of this commit: cvs rdiff -u -r1.104 -r1.105 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/crypto.c diff -u src/sys/opencrypto/crypto.c:1.104 src/sys/opencrypto/crypto.c:1.105 --- src/sys/opencrypto/crypto.c:1.104 Mon Jan 8 23:33:40 2018 +++ src/sys/opencrypto/crypto.c Mon Jan 8 23:34:56 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: crypto.c,v 1.104 2018/01/08 23:33:40 knakahara Exp $ */ +/* $NetBSD: crypto.c,v 1.105 2018/01/08 23:34:56 knakahara Exp $ */ /* $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $ */ /* $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */ @@ -53,7 +53,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.104 2018/01/08 23:33:40 knakahara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.105 2018/01/08 23:34:56 knakahara Exp $"); #include #include @@ -360,7 +360,7 @@ sysctl_opencrypto_kq_maxlen(SYSCTLFN_ARG } /* - * Crypto op and desciptor data structures are allocated + * Crypto op and descriptor data structures are allocated * from separate private zones(FreeBSD)/pools(netBSD/OpenBSD) . */ static pool_cache_t cryptop_cache;
CVS commit: src/sys/opencrypto
Module Name:src Committed By: knakahara Date: Mon Jan 8 23:34:56 UTC 2018 Modified Files: src/sys/opencrypto: crypto.c Log Message: Fix PR kern/52910. Reported and implemented a patch by Sevan Janiyan, thanks. To generate a diff of this commit: cvs rdiff -u -r1.104 -r1.105 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: christos Date: Tue Nov 14 14:29:33 UTC 2017 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: check results of pool_prime. To generate a diff of this commit: cvs rdiff -u -r1.95 -r1.96 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/cryptodev.c diff -u src/sys/opencrypto/cryptodev.c:1.95 src/sys/opencrypto/cryptodev.c:1.96 --- src/sys/opencrypto/cryptodev.c:1.95 Thu Jun 15 08:41:18 2017 +++ src/sys/opencrypto/cryptodev.c Tue Nov 14 09:29:33 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.c,v 1.95 2017/06/15 12:41:18 knakahara Exp $ */ +/* $NetBSD: cryptodev.c,v 1.96 2017/11/14 14:29:33 christos Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */ /* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */ @@ -64,7 +64,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.95 2017/06/15 12:41:18 knakahara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.96 2017/11/14 14:29:33 christos Exp $"); #include #include @@ -2110,6 +2110,8 @@ cryptof_poll(struct file *fp, int events void cryptoattach(int num) { + int error; + crypto_init(); mutex_init(_mtx, MUTEX_DEFAULT, IPL_NONE); @@ -2126,8 +2128,9 @@ cryptoattach(int num) * the negotiation, plus HMAC_SHA1 for the actual SSL records, * consuming one session here for each algorithm. */ - pool_prime(, 64); - pool_prime(, 64 * 5); + if ((error = pool_prime(, 64)) != 0 || + (error = pool_prime(, 64 * 5)) != 0) + panic("%s: can't prime pool: %d", __func__, error); } void crypto_attach(device_t, device_t, void *);
CVS commit: src/sys/opencrypto
Module Name:src Committed By: christos Date: Tue Nov 14 14:29:33 UTC 2017 Modified Files: src/sys/opencrypto: cryptodev.c Log Message: check results of pool_prime. To generate a diff of this commit: cvs rdiff -u -r1.95 -r1.96 src/sys/opencrypto/cryptodev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/opencrypto
Module Name:src Committed By: christos Date: Thu Nov 9 22:20:26 UTC 2017 Modified Files: src/sys/opencrypto: crypto.c Log Message: use PR_NOWAIT. To generate a diff of this commit: cvs rdiff -u -r1.101 -r1.102 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/opencrypto/crypto.c diff -u src/sys/opencrypto/crypto.c:1.101 src/sys/opencrypto/crypto.c:1.102 --- src/sys/opencrypto/crypto.c:1.101 Thu Sep 21 23:04:06 2017 +++ src/sys/opencrypto/crypto.c Thu Nov 9 17:20:25 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: crypto.c,v 1.101 2017/09/22 03:04:06 knakahara Exp $ */ +/* $NetBSD: crypto.c,v 1.102 2017/11/09 22:20:25 christos Exp $ */ /* $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $ */ /* $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */ @@ -53,7 +53,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.101 2017/09/22 03:04:06 knakahara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.102 2017/11/09 22:20:25 christos Exp $"); #include #include @@ -1655,14 +1655,14 @@ crypto_getreq(int num) } crypto_put_crp_ret_qs(curcpu()); - crp = pool_cache_get(cryptop_cache, 0); + crp = pool_cache_get(cryptop_cache, PR_NOWAIT); if (crp == NULL) { return NULL; } memset(crp, 0, sizeof(struct cryptop)); while (num--) { - crd = pool_cache_get(cryptodesc_cache, 0); + crd = pool_cache_get(cryptodesc_cache, PR_NOWAIT); if (crd == NULL) { crypto_freereq(crp); return NULL;
CVS commit: src/sys/opencrypto
Module Name:src Committed By: christos Date: Thu Nov 9 22:20:26 UTC 2017 Modified Files: src/sys/opencrypto: crypto.c Log Message: use PR_NOWAIT. To generate a diff of this commit: cvs rdiff -u -r1.101 -r1.102 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.