Message ID | 20230530141635.136968-1-dhowells@redhat.com |
---|---|
Headers | show |
Series | crypto, splice, net: Make AF_ALG handle sendmsg(MSG_SPLICE_PAGES) | expand |
On Tue, May 30, 2023 at 03:16:34PM +0100, David Howells wrote: > > - if (limit > sk->sk_sndbuf) > - limit = sk->sk_sndbuf; > + /* Don't limit to ALG_MAX_PAGES if the pages are all already pinned. */ > + if (!user_backed_iter(&msg->msg_iter)) > + max_pages = INT_MAX; > + else > + max_pages = min_t(size_t, max_pages, > + DIV_ROUND_UP(sk->sk_sndbuf, PAGE_SIZE)); What's the purpose of relaxing this limit? Even if there is a reason for this shouldn't this be in a patch by itself? Thanks,
Herbert Xu <herbert@gondor.apana.org.au> wrote: > > - if (limit > sk->sk_sndbuf) > > - limit = sk->sk_sndbuf; > > + /* Don't limit to ALG_MAX_PAGES if the pages are all already pinned. */ > > + if (!user_backed_iter(&msg->msg_iter)) > > + max_pages = INT_MAX; If the iov_iter is a kernel-backed type (BVEC, KVEC, XARRAY) then (a) all the pages it refers to must already be pinned in memory and (b) the caller must have limited it in some way (splice is limited by the pipe capacity, for instance). In which case, it seems pointless taking more than one pass of the while loop if we can avoid it - at least from the point of view of memory handling; granted there might be other criteria such as hogging crypto offload hardware. > > + else > > + max_pages = min_t(size_t, max_pages, > > + DIV_ROUND_UP(sk->sk_sndbuf, PAGE_SIZE)); > > What's the purpose of relaxing this limit? If the iov_iter is a user-backed type (IOVEC or UBUF) then it's not relaxed. max_pages is ALG_MAX_PAGES here (actually, I should just move that here so that it's clearer). I am, however, applying the sk_sndbuf limit here also - there's no point extracting more pages than we need to if ALG_MAX_PAGES of whole pages would overrun the byte limit. > Even if there is a reason for this shouldn't this be in a patch by itself? I suppose I could do it as a follow-on patch; use ALG_MAX_PAGES and sk_sndbuf before that as for user-backed iterators. Actually, is it worth paying attention to sk_sndbuf for kernel-backed iterators? David
On Tue, Jun 06, 2023 at 10:24:55AM +0100, David Howells wrote: > > If the iov_iter is a user-backed type (IOVEC or UBUF) then it's not relaxed. > max_pages is ALG_MAX_PAGES here (actually, I should just move that here so > that it's clearer). Even if it's kernel memory they can't be freed during the hashing operation, which could be long if the amount is large (or the algo is slow). The reason for the limit here is to stop a malicious user from pinning an unlimited amount of memory by doing a hashing operation, IOW a DoS attack. So I think we should keep the limit as is. Cheers,
Herbert Xu <herbert@gondor.apana.org.au> wrote:
> So I think we should keep the limit as is.
Okay.
David