<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/crypto/algif_skcipher.c, branch linux-4.14.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.14.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.14.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2020-10-29T08:07:01Z</updated>
<entry>
<title>crypto: algif_skcipher - EBUSY on aio should be an error</title>
<updated>2020-10-29T08:07:01Z</updated>
<author>
<name>Herbert Xu</name>
</author>
<published>2020-07-31T07:03:27Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=9751cc18971d1c3e1103a823b5324cb8312058a4'/>
<id>urn:sha1:9751cc18971d1c3e1103a823b5324cb8312058a4</id>
<content type='text'>
[ Upstream commit 2a05b029c1ee045b886ebf9efef9985ca23450de ]

I removed the MAY_BACKLOG flag on the aio path a while ago but
the error check still incorrectly interpreted EBUSY as success.
This may cause the submitter to wait for a request that will never
complete.

Fixes: dad419970637 ("crypto: algif_skcipher - Do not set...")
Signed-off-by: Herbert Xu &lt;herbert@gondor.apana.org.au&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>crypto: af_alg - fix use-after-free in af_alg_accept() due to bh_lock_sock()</title>
<updated>2020-07-09T07:36:30Z</updated>
<author>
<name>Herbert Xu</name>
</author>
<published>2020-06-08T06:48:43Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=687ca6afdae1f737a6adec8a3a8ec0b13ed45258'/>
<id>urn:sha1:687ca6afdae1f737a6adec8a3a8ec0b13ed45258</id>
<content type='text'>
commit 34c86f4c4a7be3b3e35aa48bd18299d4c756064d upstream.

The locking in af_alg_release_parent is broken as the BH socket
lock can only be taken if there is a code-path to handle the case
where the lock is owned by process-context.  Instead of adding
such handling, we can fix this by changing the ref counts to
atomic_t.

This patch also modifies the main refcnt to include both normal
and nokey sockets.  This way we don't have to fudge the nokey
ref count when a socket changes from nokey to normal.

Credits go to Mauricio Faria de Oliveira who diagnosed this bug
and sent a patch for it:

https://lore.kernel.org/linux-crypto/20200605161657.535043-1-mfo@canonical.com/

Reported-by: Brian Moyles &lt;bmoyles@netflix.com&gt;
Reported-by: Mauricio Faria de Oliveira &lt;mfo@canonical.com&gt;
Fixes: 37f96694cf73 ("crypto: af_alg - Use bh_lock_sock in...")
Cc: &lt;stable@vger.kernel.org&gt;
Signed-off-by: Herbert Xu &lt;herbert@gondor.apana.org.au&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>crypto: algif_skcipher - Cap recv SG list at ctx-&gt;used</title>
<updated>2020-06-25T13:42:01Z</updated>
<author>
<name>Herbert Xu</name>
</author>
<published>2020-05-29T04:54:43Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=29b13c01407846c4b9846f3d6794f9fd84ce57c4'/>
<id>urn:sha1:29b13c01407846c4b9846f3d6794f9fd84ce57c4</id>
<content type='text'>
commit 7cf81954705b7e5b057f7dc39a7ded54422ab6e1 upstream.

Somewhere along the line the cap on the SG list length for receive
was lost.  This patch restores it and removes the subsequent test
which is now redundant.

Fixes: 2d97591ef43d ("crypto: af_alg - consolidation of...")
Cc: &lt;stable@vger.kernel.org&gt;
Signed-off-by: Herbert Xu &lt;herbert@gondor.apana.org.au&gt;
Reviewed-by: Stephan Mueller &lt;smueller@chronox.de&gt;
Signed-off-by: Herbert Xu &lt;herbert@gondor.apana.org.au&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>crypto: af_alg - Fix race around ctx-&gt;rcvused by making it atomic_t</title>
<updated>2018-03-03T09:24:29Z</updated>
<author>
<name>Jonathan Cameron</name>
</author>
<published>2017-12-19T10:27:24Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=36d0a678fb25a7bce5bf9b2828c0d9395fa9a990'/>
<id>urn:sha1:36d0a678fb25a7bce5bf9b2828c0d9395fa9a990</id>
<content type='text'>
[ Upstream commit af955bf15d2c27496b0269b1f05c26f758c68314 ]

This variable was increased and decreased without any protection.
Result was an occasional misscount and negative wrap around resulting
in false resource allocation failures.

Fixes: 7d2c3f54e6f6 ("crypto: af_alg - remove locking in async callback")
Signed-off-by: Jonathan Cameron &lt;Jonathan.Cameron@huawei.com&gt;
Reviewed-by: Stephan Mueller &lt;smueller@chronox.de&gt;
Signed-off-by: Herbert Xu &lt;herbert@gondor.apana.org.au&gt;
Signed-off-by: Sasha Levin &lt;alexander.levin@verizon.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>crypto: af_alg - fix race accessing cipher request</title>
<updated>2017-12-29T16:53:46Z</updated>
<author>
<name>Stephan Mueller</name>
</author>
<published>2017-12-08T10:50:37Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=f09fca41e29c68944e75ab5f65a2efcfcc88aceb'/>
<id>urn:sha1:f09fca41e29c68944e75ab5f65a2efcfcc88aceb</id>
<content type='text'>
commit d53c5135792319e095bb126bc43b2ee98586f7fe upstream.

When invoking an asynchronous cipher operation, the invocation of the
callback may be performed before the subsequent operations in the
initial code path are invoked. The callback deletes the cipher request
data structure which implies that after the invocation of the
asynchronous cipher operation, this data structure must not be accessed
any more.

The setting of the return code size with the request data structure must
therefore be moved before the invocation of the asynchronous cipher
operation.

Fixes: e870456d8e7c ("crypto: algif_skcipher - overhaul memory management")
Fixes: d887c52d6ae4 ("crypto: algif_aead - overhaul memory management")
Reported-by: syzbot &lt;syzkaller@googlegroups.com&gt;
Signed-off-by: Stephan Mueller &lt;smueller@chronox.de&gt;
Acked-by: Jonathan Cameron &lt;Jonathan.Cameron@huawei.com&gt;
Signed-off-by: Herbert Xu &lt;herbert@gondor.apana.org.au&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>crypto: af_alg - wait for data at beginning of recvmsg</title>
<updated>2017-12-29T16:53:46Z</updated>
<author>
<name>Stephan Mueller</name>
</author>
<published>2017-11-29T11:02:23Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=c692698ebebed838627aa3879e30959c4a75f033'/>
<id>urn:sha1:c692698ebebed838627aa3879e30959c4a75f033</id>
<content type='text'>
commit 11edb555966ed2c66c533d17c604f9d7e580a829 upstream.

The wait for data is a non-atomic operation that can sleep and therefore
potentially release the socket lock. The release of the socket lock
allows another thread to modify the context data structure. The waiting
operation for new data therefore must be called at the beginning of
recvmsg. This prevents a race condition where checks of the members of
the context data structure are performed by recvmsg while there is a
potential for modification of these values.

Fixes: e870456d8e7c ("crypto: algif_skcipher - overhaul memory management")
Fixes: d887c52d6ae4 ("crypto: algif_aead - overhaul memory management")
Reported-by: syzbot &lt;syzkaller@googlegroups.com&gt;
Signed-off-by: Stephan Mueller &lt;smueller@chronox.de&gt;
Signed-off-by: Herbert Xu &lt;herbert@gondor.apana.org.au&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>crypto: af_alg - remove locking in async callback</title>
<updated>2017-12-05T10:26:30Z</updated>
<author>
<name>Stephan Mueller</name>
</author>
<published>2017-11-10T12:20:55Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=7f21961a2d7bfe45f734eab5b0ce6a40ee128b17'/>
<id>urn:sha1:7f21961a2d7bfe45f734eab5b0ce6a40ee128b17</id>
<content type='text'>
commit 7d2c3f54e6f646887d019faa45f35d6fe9fe82ce upstream.

The code paths protected by the socket-lock do not use or modify the
socket in a non-atomic fashion. The actions pertaining the socket do not
even need to be handled as an atomic operation. Thus, the socket-lock
can be safely ignored.

This fixes a bug regarding scheduling in atomic as the callback function
may be invoked in interrupt context.

In addition, the sock_hold is moved before the AIO encrypt/decrypt
operation to ensure that the socket is always present. This avoids a
tiny race window where the socket is unprotected and yet used by the AIO
operation.

Finally, the release of resources for a crypto operation is moved into a
common function of af_alg_free_resources.

Fixes: e870456d8e7c8 ("crypto: algif_skcipher - overhaul memory management")
Fixes: d887c52d6ae43 ("crypto: algif_aead - overhaul memory management")
Reported-by: Romain Izard &lt;romain.izard.pro@gmail.com&gt;
Signed-off-by: Stephan Mueller &lt;smueller@chronox.de&gt;
Tested-by: Romain Izard &lt;romain.izard.pro@gmail.com&gt;
Signed-off-by: Herbert Xu &lt;herbert@gondor.apana.org.au&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>crypto: af_alg - consolidation of duplicate code</title>
<updated>2017-08-09T12:18:32Z</updated>
<author>
<name>Stephan Mueller</name>
</author>
<published>2017-08-02T05:56:19Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=2d97591ef43d0587be22ad1b0d758d6df4999a0b'/>
<id>urn:sha1:2d97591ef43d0587be22ad1b0d758d6df4999a0b</id>
<content type='text'>
Consolidate following data structures:

skcipher_async_req, aead_async_req -&gt; af_alg_async_req
skcipher_rsgl, aead_rsql -&gt; af_alg_rsgl
skcipher_tsgl, aead_tsql -&gt; af_alg_tsgl
skcipher_ctx, aead_ctx -&gt; af_alg_ctx

Consolidate following functions:

skcipher_sndbuf, aead_sndbuf -&gt; af_alg_sndbuf
skcipher_writable, aead_writable -&gt; af_alg_writable
skcipher_rcvbuf, aead_rcvbuf -&gt; af_alg_rcvbuf
skcipher_readable, aead_readable -&gt; af_alg_readable
aead_alloc_tsgl, skcipher_alloc_tsgl -&gt; af_alg_alloc_tsgl
aead_count_tsgl, skcipher_count_tsgl -&gt; af_alg_count_tsgl
aead_pull_tsgl, skcipher_pull_tsgl -&gt; af_alg_pull_tsgl
aead_free_areq_sgls, skcipher_free_areq_sgls -&gt; af_alg_free_areq_sgls
aead_wait_for_wmem, skcipher_wait_for_wmem -&gt; af_alg_wait_for_wmem
aead_wmem_wakeup, skcipher_wmem_wakeup -&gt; af_alg_wmem_wakeup
aead_wait_for_data, skcipher_wait_for_data -&gt; af_alg_wait_for_data
aead_data_wakeup, skcipher_data_wakeup -&gt; af_alg_data_wakeup
aead_sendmsg, skcipher_sendmsg -&gt; af_alg_sendmsg
aead_sendpage, skcipher_sendpage -&gt; af_alg_sendpage
aead_async_cb, skcipher_async_cb -&gt; af_alg_async_cb
aead_poll, skcipher_poll -&gt; af_alg_poll

Split out the following common code from recvmsg:

af_alg_alloc_areq: allocation of the request data structure for the
cipher operation

af_alg_get_rsgl: creation of the RX SGL anchored in the request data
structure

The following changes to the implementation without affecting the
functionality have been applied to synchronize slightly different code
bases in algif_skcipher and algif_aead:

The wakeup in af_alg_wait_for_data is triggered when either more data
is received or the indicator that more data is to be expected is
released. The first is triggered by user space, the second is
triggered by the kernel upon finishing the processing of data
(i.e. the kernel is ready for more).

af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
Return code determination is consistent with algif_skcipher. The
scope of the variable i is reduced to match algif_aead. The type of the
variable i is switched from int to unsigned int to match algif_aead.

af_alg_sendpage does not contain the superfluous err = 0 from
aead_sendpage.

af_alg_async_cb requires to store the number of output bytes in
areq-&gt;outlen before the AIO callback is triggered.

The POLLIN / POLLRDNORM is now set when either not more data is given or
the kernel is supplied with data. This is consistent to the wakeup from
sleep when the kernel waits for data.

The request data structure is extended by the field last_rsgl which
points to the last RX SGL list entry. This shall help recvmsg
implementation to chain the RX SGL to other SG(L)s if needed. It is
currently used by algif_aead which chains the tag SGL to the RX SGL
during decryption.

Signed-off-by: Stephan Mueller &lt;smueller@chronox.de&gt;
Signed-off-by: Herbert Xu &lt;herbert@gondor.apana.org.au&gt;
</content>
</entry>
<entry>
<title>crypto: algif - return error code when no data was processed</title>
<updated>2017-08-09T12:17:50Z</updated>
<author>
<name>Stephan Mueller</name>
</author>
<published>2017-07-30T12:31:18Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=5703c826b758e0b33c998739af093879979315b8'/>
<id>urn:sha1:5703c826b758e0b33c998739af093879979315b8</id>
<content type='text'>
If no data has been processed during recvmsg, return the error code.
This covers all errors received during non-AIO operations.

If any error occurs during a synchronous operation in addition to
-EIOCBQUEUED or -EBADMSG (like -ENOMEM), it should be relayed to the
caller.

Signed-off-by: Stephan Mueller &lt;smueller@chronox.de&gt;
Signed-off-by: Herbert Xu &lt;herbert@gondor.apana.org.au&gt;
</content>
</entry>
<entry>
<title>crypto: algif_skcipher - overhaul memory management</title>
<updated>2017-07-28T09:54:30Z</updated>
<author>
<name>Stephan Mueller</name>
</author>
<published>2017-06-25T15:12:39Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=e870456d8e7c8d57c059ea479b5aadbb55ff4c3a'/>
<id>urn:sha1:e870456d8e7c8d57c059ea479b5aadbb55ff4c3a</id>
<content type='text'>
The updated memory management is described in the top part of the code.
As one benefit of the changed memory management, the AIO and synchronous
operation is now implemented in one common function. The AF_ALG
operation uses the async kernel crypto API interface for each cipher
operation. Thus, the only difference between the AIO and sync operation
types visible from user space is:

1. the callback function to be invoked when the asynchronous operation
   is completed

2. whether to wait for the completion of the kernel crypto API operation
   or not

In addition, the code structure is adjusted to match the structure of
algif_aead for easier code assessment.

The user space interface changed slightly as follows: the old AIO
operation returned zero upon success and &lt; 0 in case of an error to user
space. As all other AF_ALG interfaces (including the sync skcipher
interface) returned the number of processed bytes upon success and &lt; 0
in case of an error, the new skcipher interface (regardless of AIO or
sync) returns the number of processed bytes in case of success.

Signed-off-by: Stephan Mueller &lt;smueller@chronox.de&gt;
Signed-off-by: Herbert Xu &lt;herbert@gondor.apana.org.au&gt;
</content>
</entry>
</feed>
