]> git.baikalelectronics.ru Git - kernel.git/commit
tls: cap the output scatter list to something reasonable
authorJakub Kicinski <kuba@kernel.org>
Wed, 2 Feb 2022 22:20:31 +0000 (14:20 -0800)
committerDavid S. Miller <davem@davemloft.net>
Fri, 4 Feb 2022 10:14:07 +0000 (10:14 +0000)
commit4465cb27eeeaeb851cb9445785d36f202d3c2a47
tree48d9273feaf831aaa0b4f3393c199a049505b1f6
parent81dca6939e300d8d344be11f261c75386182cd65
tls: cap the output scatter list to something reasonable

TLS recvmsg() passes user pages as destination for decrypt.
The decrypt operation is repeated record by record, each
record being 16kB, max. TLS allocates an sg_table and uses
iov_iter_get_pages() to populate it with enough pages to
fit the decrypted record.

Even though we decrypt a single message at a time we size
the sg_table based on the entire length of the iovec.
This leads to unnecessarily large allocations, risking
triggering OOM conditions.

Use iov_iter_truncate() / iov_iter_reexpand() to construct
a "capped" version of iov_iter_npages(). Alternatively we
could parametrize iov_iter_npages() to take the size as
arg instead of using i->count, or do something else..

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/uio.h
net/tls/tls_sw.c