]> git.baikalelectronics.ru Git - kernel.git/commit
tls: Fix socket mem accounting error under async encryption
authorVakul Garg <vakul.garg@nxp.com>
Tue, 25 Sep 2018 10:56:17 +0000 (16:26 +0530)
committerDavid S. Miller <davem@davemloft.net>
Tue, 25 Sep 2018 17:43:01 +0000 (10:43 -0700)
commit0183146368ebeba2865a08f9f3628a48f88b27c8
treee1471ac258124f6f57ab495b76ee8187138097d0
parentc9896e8980fe292f7a4f3e51e7fe7b42aca42134
tls: Fix socket mem accounting error under async encryption

Current async encryption implementation sometimes showed up socket
memory accounting error during socket close. This results in kernel
warning calltrace. The root cause of the problem is that socket var
sk_forward_alloc gets corrupted due to access in sk_mem_charge()
and sk_mem_uncharge() being invoked from multiple concurrent contexts
in multicore processor. The apis sk_mem_charge() and sk_mem_uncharge()
are called from functions alloc_plaintext_sg(), free_sg() etc. It is
required that memory accounting apis are called under a socket lock.

The plaintext sg data sent for encryption is freed using free_sg() in
tls_encryption_done(). It is wrong to call free_sg() from this function.
This is because this function may run in irq context. We cannot acquire
socket lock in this function.

We remove calling of function free_sg() for plaintext data from
tls_encryption_done() and defer freeing up of plaintext data to the time
when the record is picked up from tx_list and transmitted/freed. When
tls_tx_records() gets called, socket is already locked and thus there is
no concurrent access problem.

Fixes: 4e09428b5ad7 ("net/tls: Add support for async encryption")
Signed-off-by: Vakul Garg <vakul.garg@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/tls/tls_sw.c