Up to [cvs.NetBSD.org] / src / sys / opencrypto
Request diff between arbitrary revisions
Keyword substitution: kv
Default branch: MAIN
Sync with HEAD
opencrypto(9): Sprinkle SET_ERROR dtrace probes.
opencrypto(9): Sort includes and nix trailing whitespace. No functional change intended.
Pull up following revision(s) (requested by riastradh in ticket #1278):
sys/opencrypto/cryptodev.c: revision 1.130
sys/opencrypto/cryptodev.c: revision 1.131
sys/opencrypto/cryptodev.c: revision 1.132
sys/opencrypto/cryptodev.c: revision 1.133
tests/crypto/opencrypto/Makefile: revision 1.6
sys/opencrypto/cryptosoft.c: revision 1.67
sys/opencrypto/ocryptodev.c: revision 1.19
tests/crypto/opencrypto/h_thread.c: revision 1.1
sys/rump/dev/lib/libopencrypto/OPENCRYPTO.ioconf: revision 1.2
tests/crypto/opencrypto/h_thread.c: revision 1.2
sys/rump/dev/lib/libopencrypto/opencrypto_component.c: revision 1.7
tests/crypto/opencrypto/t_opencrypto.sh: revision 1.12
tests/crypto/opencrypto/t_opencrypto.sh: revision 1.13
sys/opencrypto/cryptodev_internal.h: revision 1.5
tests/crypto/opencrypto/t_opencrypto.sh: revision 1.14
sys/opencrypto/cryptodev.c: revision 1.129
distrib/sets/lists/debug/mi: revision 1.512
distrib/sets/lists/tests/mi: revision 1.1417
Add a threaded test to test for races in cryptodev.
new thread cryptodev test
crypto(4): Make test more reliable, and test more.
1. New thread to concurrently create and destroy sessions.
(There should really be multiple threads to concurrently compete
with each other to create and destroy sessions, but this is
already surfacing more crashes, as I expected.)
2. Handle EBUSY in CIOCFSESSION in case there is a concurrent
CIOCCRYPT, as we are trying to test.
3. Handle CIOCCRYPT failure if a concurrent CIOCFSESSION beat us to
it, as we are trying to test
4. Dump core if the threads get stuck for too long.
5. Provide stack traces from the test program or rump server if they
dump core.
PR kern/60281: crypto(4): bugs in reference counting and test
crypto(4): Take reference _before_ releasing the lock.
Otherwise nothing ensures the object will still exist by the time we
try to take the reference.
Also guard against too many references, since this is only a 32-bit
reference count.
PR kern/60281: crypto(4): bugs in reference counting and test
crypto(4): Fix missing membars on reference count release.
If two threads A and B both hold references, we need to ensure that
memory ops in thread A happen before memory free in thread B in:
thread A thread B notes
-------- -------- -----
memory ops
atomic_dec(&refcnt) goes from 2 to 1
atomic_dec(&refcnt) goes from 1 to 0
memory free
This requires a membar_release in thread A before the atomic_dec (or
atomic_dec with memory_order_release), and a membar_acquire in thread
B after the atomic_dec is found to have brought the reference count
down to zero (or atomic_dec wiht memory_order_acquire).
kern/60281: crypto(4): bugs in reference counting and test
crypto(4): Disentangle initialization and attachment goo.
Lotta unnecessary boilerplate deleted here!
Disable module unloading: can't be done safely. Explain precisely
why it can't be done safely.
This also fixes annoying `crypto: unable to register devsw, error 17'
messages in rump dmesg by having exactly one path to devsw_attach.
PR kern/60281: crypto(4): bugs in reference counting and test
crypto(4): Omit needless locking in fcrypt_dtor.
We must have exclusive access to the object for this function to work
at all, so if removing the locks appeared to cause issues, it would
necessarily happen only because there is a bug somewhere else.
PR kern/60281: crypto(4): bugs in reference counting and test
crypto(4): Nix spurious mutex_exit; add missing bounds checks.
Consistently use `foo = kmem_alloc(n * sizeof(*foo), ...)' instead of
`sizeof(struct whatever_foo_is)'. Makes it easier for a reader to
notice a discrepancy this way.
Move CRYPTODEV_OPS_MAX to cryptodev_internal.h so it can be used by
the compat ocryptodev.c shims too. I think this is waaaaaaaaaaaaay
too high, by the way. For example, it looks like qat(4) puts a limit
of 16384 on the number of sessions. Other devices like hifn(4) look
like they're limited to numbers of sessions ranging from 2 to around
256.
PR kern/60281: crypto(4): bugs in reference counting and test
Pull up following revision(s) (requested by riastradh in ticket #330):
sys/opencrypto/cryptodev.c: revision 1.130
sys/opencrypto/cryptodev.c: revision 1.131
sys/opencrypto/cryptodev.c: revision 1.132
sys/opencrypto/cryptodev.c: revision 1.133
tests/crypto/opencrypto/Makefile: revision 1.6
sys/opencrypto/cryptosoft.c: revision 1.67
sys/opencrypto/ocryptodev.c: revision 1.19
tests/crypto/opencrypto/h_thread.c: revision 1.1
sys/rump/dev/lib/libopencrypto/OPENCRYPTO.ioconf: revision 1.2
tests/crypto/opencrypto/h_thread.c: revision 1.2
sys/rump/dev/lib/libopencrypto/opencrypto_component.c: revision 1.7
tests/crypto/opencrypto/t_opencrypto.sh: revision 1.12
tests/crypto/opencrypto/t_opencrypto.sh: revision 1.13
sys/opencrypto/cryptodev_internal.h: revision 1.5
tests/crypto/opencrypto/t_opencrypto.sh: revision 1.14
sys/opencrypto/cryptodev.c: revision 1.129
distrib/sets/lists/debug/mi: revision 1.512
distrib/sets/lists/tests/mi: revision 1.1417
Add a threaded test to test for races in cryptodev.
new thread cryptodev test
crypto(4): Make test more reliable, and test more.
1. New thread to concurrently create and destroy sessions.
(There should really be multiple threads to concurrently compete
with each other to create and destroy sessions, but this is
already surfacing more crashes, as I expected.)
2. Handle EBUSY in CIOCFSESSION in case there is a concurrent
CIOCCRYPT, as we are trying to test.
3. Handle CIOCCRYPT failure if a concurrent CIOCFSESSION beat us to
it, as we are trying to test
4. Dump core if the threads get stuck for too long.
5. Provide stack traces from the test program or rump server if they
dump core.
PR kern/60281: crypto(4): bugs in reference counting and test
crypto(4): Take reference _before_ releasing the lock.
Otherwise nothing ensures the object will still exist by the time we
try to take the reference.
Also guard against too many references, since this is only a 32-bit
reference count.
PR kern/60281: crypto(4): bugs in reference counting and test
crypto(4): Fix missing membars on reference count release.
If two threads A and B both hold references, we need to ensure that
memory ops in thread A happen before memory free in thread B in:
thread A thread B notes
-------- -------- -----
memory ops
atomic_dec(&refcnt) goes from 2 to 1
atomic_dec(&refcnt) goes from 1 to 0
memory free
This requires a membar_release in thread A before the atomic_dec (or
atomic_dec with memory_order_release), and a membar_acquire in thread
B after the atomic_dec is found to have brought the reference count
down to zero (or atomic_dec wiht memory_order_acquire).
kern/60281: crypto(4): bugs in reference counting and test
crypto(4): Disentangle initialization and attachment goo.
Lotta unnecessary boilerplate deleted here!
Disable module unloading: can't be done safely. Explain precisely
why it can't be done safely.
This also fixes annoying `crypto: unable to register devsw, error 17'
messages in rump dmesg by having exactly one path to devsw_attach.
PR kern/60281: crypto(4): bugs in reference counting and test
crypto(4): Omit needless locking in fcrypt_dtor.
We must have exclusive access to the object for this function to work
at all, so if removing the locks appeared to cause issues, it would
necessarily happen only because there is a bug somewhere else.
PR kern/60281: crypto(4): bugs in reference counting and test
crypto(4): Nix spurious mutex_exit; add missing bounds checks.
Consistently use `foo = kmem_alloc(n * sizeof(*foo), ...)' instead of
`sizeof(struct whatever_foo_is)'. Makes it easier for a reader to
notice a discrepancy this way.
Move CRYPTODEV_OPS_MAX to cryptodev_internal.h so it can be used by
the compat ocryptodev.c shims too. I think this is waaaaaaaaaaaaay
too high, by the way. For example, it looks like qat(4) puts a limit
of 16384 on the number of sessions. Other devices like hifn(4) look
like they're limited to numbers of sessions ranging from 2 to around
256.
PR kern/60281: crypto(4): bugs in reference counting and test
crypto(4): Nix spurious mutex_exit; add missing bounds checks. Consistently use `foo = kmem_alloc(n * sizeof(*foo), ...)' instead of `sizeof(struct whatever_foo_is)'. Makes it easier for a reader to notice a discrepancy this way. Move CRYPTODEV_OPS_MAX to cryptodev_internal.h so it can be used by the compat ocryptodev.c shims too. I think this is waaaaaaaaaaaaay too high, by the way. For example, it looks like qat(4) puts a limit of 16384 on the number of sessions. Other devices like hifn(4) look like they're limited to numbers of sessions ranging from 2 to around 256. PR kern/60281: crypto(4): bugs in reference counting and test
Pull up following revision(s) (requested by christos in ticket #1262): sys/opencrypto/crypto.c: revision 1.132 sys/opencrypto/crypto.c: revision 1.133 sys/opencrypto/cryptosoft.h: revision 1.8 sys/opencrypto/xform.c: revision 1.32 sys/opencrypto/deflate.h: revision 1.10 sys/opencrypto/cryptodev.h: revision 1.52 sys/opencrypto/cryptosoft.c: revision 1.66 sys/opencrypto/cryptodev.h: revision 1.53 sys/opencrypto/ocryptodev.c: revision 1.18 sys/opencrypto/cryptodev_internal.h: revision 1.4 sys/opencrypto/aesxcbcmac.c: revision 1.4 sys/opencrypto/cryptodev.c: revision 1.127 sys/opencrypto/aesxcbcmac.h: revision 1.3 sys/opencrypto/cryptodev.c: revision 1.128 sys/opencrypto/cryptosoft_xform.c: revision 1.31 sys/opencrypto/deflate.c: revision 1.24 sys/opencrypto/deflate.c: revision 1.25 sys/opencrypto/xform.h: revision 1.22 sys/opencrypto/ocryptodev.h: revision 1.5 sys/opencrypto/ocryptodev.h: revision 1.6 u_intXX_t -> uintXX_t Fix: An integer wraparound bug that could cause a NULL pointer exception. Data sharing issues that could cause data corruption. Locking issues that could cause double freeing or using free memory. Issues discovered by nasm and coordinated by VulnCheck Thank you!
Pull up following revision(s) (requested by christos in ticket #262): sys/opencrypto/crypto.c: revision 1.132 sys/opencrypto/crypto.c: revision 1.133 sys/opencrypto/cryptosoft.h: revision 1.8 sys/opencrypto/xform.c: revision 1.32 sys/opencrypto/deflate.h: revision 1.10 sys/opencrypto/cryptodev.h: revision 1.52 sys/opencrypto/cryptosoft.c: revision 1.66 sys/opencrypto/cryptodev.h: revision 1.53 sys/opencrypto/ocryptodev.c: revision 1.18 sys/opencrypto/cryptodev_internal.h: revision 1.4 sys/opencrypto/aesxcbcmac.c: revision 1.4 sys/opencrypto/cryptodev.c: revision 1.127 sys/opencrypto/aesxcbcmac.h: revision 1.3 sys/opencrypto/cryptodev.c: revision 1.128 sys/opencrypto/cryptosoft_xform.c: revision 1.31 sys/opencrypto/deflate.c: revision 1.24 sys/opencrypto/deflate.c: revision 1.25 sys/opencrypto/xform.h: revision 1.22 sys/opencrypto/ocryptodev.h: revision 1.5 sys/opencrypto/ocryptodev.h: revision 1.6 u_intXX_t -> uintXX_t Fix: An integer wraparound bug that could cause a NULL pointer exception. Data sharing issues that could cause data corruption. Locking issues that could cause double freeing or using free memory. Issues discovered by nasm and coordinated by VulnCheck Thank you!
Fix: An integer wraparound bug that could cause a NULL pointer exception. Data sharing issues that could cause data corruption. Locking issues that could cause double freeing or using free memory. Issues discovered by nasm and coordinated by VulnCheck Thank you!
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+798d4a16bc15ae88526e@syzkaller.appspotmail.com
Merge changes from current as of 20200406
Sync with head.
Split the module glue out from the rest of opencrypto/ocryptodev to make rump happy. Rump doesn't have compat modules (the compat code is included in the relevant librump*.so), so there's no module compat_50 listed in link_set_modules, and thus ocryptodev's MODULE(...) can't "require" it. This fixes the problem of "built-in module compat_50 not found" when starting up rump_allserver (or rump_server with -l rumpdev_opencrypto). XXX This does not resolve the long-standing "crypto: unable to XXX register devsw, error 17" message noted at line 78 of XXX sys/rump/dev/lib/libopencrypto/opencrypto_component.c
Sync with head.
Initialize the session variable to an impossible session to prevent compiler warnings.
Rather than keeping a separate mutex, condvar, and pserialize for each module hook, we can share a common set of synchronization structures. This cuts the amount of cacheline_aligned data for these structures by 50%. Note that we still have a per-hook localcount, since we need to count individual references. As discussed with riastradh@ Welcome to 9.99.22 !
Sync with HEAD
Rename the MODULE_*_HOOK() macros to MODULE_HOOK_*() as briefly discussed on irc. NFCI intended. Ride the earlier kernel bump - it;s getting crowded.
Merge the [pgoyette-compat] branch
Convert the macros for setting and unsetting a hook to generate in-line code rather than using an intermediary hook##set routine. Hooks are set and unset only in one place, so the intermediary routine provides no benefit. IMHO using the macro at the point- of-call is more readable than using it elsewhere in the code and then calling the generated intermediary routine (for which you won't even find its declaration or definition unless you remember to search for the HOOK_SET macro instead). NFC intended, will verify with a bulk build and an atf test run.
Fix some thinkos/pastos/typos
Split the compat_crypto_50 from the rest of the crypto module Cleanup some stuff left over from similar changes to raid modules.
Since the caller passes the address of our mutex, use it rather than trying to reference it via global symbol (which might not exist).
When the compat code needs to callback to the original code, we cannot call directly via the routines' global symbols, since the original code might not be built-in. So, the original code that calls compat code needs to pass in the addresses of the callbacks. This allows for the compat code to be built whether or not the original (calling) code is included. XXX Done for cryptodev, will need to do the same thing for ccd(4) and XXX vnd(4)
The COMPAT_HOOK macros were renamed to MODULE_HOOK, adjust all callers
Adapt (most of) the indirect function pointers to the new MP-safe mechanism. Still remaining are the compat_netbsd32 stuff, and some usb subroutines.
Handle the compat_50 stuff for opencrypto/cryptodev
update from HEAD
Sync with HEAD
Pull up following revision(s) (requested by knakahara in ticket #178):
sys/opencrypto/crypto.c: 1.92-1.100
sys/opencrypto/cryptodev.h: 1.38-1.39
sys/opencrypto/ocryptodev.c: 1.9-1.11
sys/opencrypto/xform.c: revision 1.29
sys/opencrypto/xform.h: revision 1.20
KNF
--
Apply C99-style struct initialization to enc_xform, auth_hash and comp_algo
--
make cryptoret() context softint to balance dequeuing crypto_ret_q with enqueuing it.
--
fix panic when using ecryption devices attached earlier than ipi_sysinit().
pointed out and tested by martin@n.o, thanks.
--
fix typo
--
make crp_{,k}q percpu to scale crypto_dispatch().
update locking note later.
--
divide crp_ret_{,k}q by CPU to avoid reordering.
update locking note later.
--
update locking notes of opencrypto(9)
--
Don't disclose uninitialized 32-bit word if cryptodev_session fails.
From Ilja Van Sprundel.
--
Avert userland-controlled integer overflow.
From Ilja Van Sprundel.
--
Avoid another userland-controlled integer overflow.
From Ilja Van Sprundel.
--
refactor: remove glue macros for FreeBSD code.
--
pack crypto_drivers variables to struct and add cacheline_aligned qualifier.
--
use kmem_alloc KPI instead of malloc KPI.
--
use pool_cache(9) instead of pool(9) as they can be called concurrently.
Avoid another userland-controlled integer overflow. From Ilja Van Sprundel.
Avert userland-controlled integer overflow. From Ilja Van Sprundel.
Don't disclose uninitialized 32-bit word if cryptodev_session fails. From Ilja Van Sprundel.
rename crypto_mtx to cryptodev_mtx It is used by cryptodev.c and ocryptodev.c only.
Resolve conflicts from previous merge (all resulting from $NetBSD keywork expansion)
opencrypto: cleanup debug messages.
Try not to use f_data, use f_fcrypt to get a correctly typed pointer.
Rebase to HEAD as of a few days ago.
sync with head.
for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.
this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
sync with head
Modularize the opencrypto components and link to the build
Sync with HEAD.
sync with head
bring matt-nb5-mips64 up to date with netbsd-5-1-RELEASE (except compat).
file ocryptodev.c was added on branch matt-nb5-mips64 on 2011-05-20 08:11:32 +0000
split the "crypto_mtx" spinlock into 3: one spinlock each for the incoming and outgoing request queues (which can be dealt with by hardware accelerators) and an adaptive lock for "all the rest" (mostly driver configuration, but also some unrelated stuff in cryptodev.c which should be revisited) The latter one seems to be uneeded at many places, but for now I've done simple replacements only, except minor fixes (where softint_schedule() was called without the lock held)
sync with head
Sync with HEAD
make the compatibility code conditional on COMPAT_50
Sync with HEAD. Commit is split, to avoid a "too many arguments" protocol error.
sync with head.
Pull up following revision(s) (requested by tls in ticket #611): sys/lib/libkern/Makefile: patch sys/lib/libkern/crc32.c: revision 1.1 sys/lib/libkern/crc32.h: revision 1.1 sys/lib/libkern/libkern.h: revision 1.89 sys/lib/libkern/arch/i386/Makefile.inc: revision 1.28 sys/net/zlib.h: revision 1.14 via patch sys/opencrypto/crypto.c: revision 1.33 sys/opencrypto/cryptodev.c: revision 1.46 sys/opencrypto/cryptodev.h: revision 1.16 sys/opencrypto/cryptosoft.c: revision 1.24 sys/opencrypto/cryptosoft.h: revision 1.6 sys/opencrypto/deflate.h: revision 1.6 sys/opencrypto/cryptosoft_xform.c: revision 1.12 sys/opencrypto/deflate.c: revision 1.13 sys/opencrypto/files.opencrypto: revision 1.20 sys/opencrypto/ocryptodev.c: revision 1.1 sys/opencrypto/ocryptodev.h: revision 1.1 sys/opencrypto/xform.c: revision 1.18 sys/opencrypto/xform.h: revision 1.10 Fixes PR kern/41069 and PR kern/41070. Extends the Opencrypto API to allow the destination buffer size to be specified when its not the same size as the input buffer (i.e. for operations like compress and decompress). The crypto_op and crypt_n_op structures gain a u_int dst_len field. The session_op structure gains a comp_alg field to specify a compression algorithm. Moved four ioctls to new ids; CIOCGSESSION, CIOCNGSESSION, CIOCCRYPT, and CIOCNCRYPTM. Added four backward compatible ioctls; OCIOCGSESSION, OCIOCNGSESSION, OCIOCCRYPT, and OCIOCNCRYPTM. Backward compatibility is maintained in ocryptodev.h and ocryptodev.c which implement the original ioctls and set dst_len and comp_alg to 0. Adds user-space access to compression features. Adds software gzip support (CRYPTO_GZIP_COMP). Adds the fast version of crc32 from zlib to libkern. This should be generally useful and provide a place to start normalizing the various crc32 routines in the kernel. The crc32 routine is used in this patch to support GZIP. With input and support from tls@NetBSD.org.
Sync with HEAD.
file ocryptodev.c was added on branch jym-xensuspend on 2009-05-13 17:22:56 +0000
file ocryptodev.c was added on branch yamt-nfs-mp on 2009-05-04 08:14:24 +0000
file ocryptodev.c was added on branch netbsd-5 on 2009-05-03 17:24:45 +0000
file ocryptodev.c was added on branch nick-hppapmap on 2009-04-28 07:37:50 +0000
avoid a useless uninitialised use, picked up by gcc -O3.
Fixes PR kern/41069 and PR kern/41070. Extends the Opencrypto API to allow the destination buffer size to be specified when its not the same size as the input buffer (i.e. for operations like compress and decompress). The crypto_op and crypt_n_op structures gain a u_int dst_len field. The session_op structure gains a comp_alg field to specify a compression algorithm. Moved four ioctls to new ids; CIOCGSESSION, CIOCNGSESSION, CIOCCRYPT, and CIOCNCRYPTM. Added four backward compatible ioctls; OCIOCGSESSION, OCIOCNGSESSION, OCIOCCRYPT, and OCIOCNCRYPTM. Backward compatibility is maintained in ocryptodev.h and ocryptodev.c which implement the original ioctls and set dst_len and comp_alg to 0. Adds user-space access to compression features. Adds software gzip support (CRYPTO_GZIP_COMP). Adds the fast version of crc32 from zlib to libkern. This should be generally useful and provide a place to start normalizing the various crc32 routines in the kernel. The crc32 routine is used in this patch to support GZIP. With input and support from tls@NetBSD.org.