From: Sasha Levin <sasha.levin@oracle.com>
To: Sasha Levin <sasha.levin@oracle.com>,
lauro.venancio@openbossa.org, aloisio.almeida@openbossa.org,
sameo@linux.intel.com, davem@davemloft.net
Cc: linux-wireless@vger.kernel.org, linux-nfc@ml01.01.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] NFC: Read frag at a time when sending packets
Date: Mon, 04 Aug 2014 15:39:33 -0400 [thread overview]
Message-ID: <53DFE175.5040602@oracle.com> (raw)
In-Reply-To: <1403234596-19149-1-git-send-email-sasha.levin@oracle.com>
Ping?
On 06/19/2014 11:23 PM, Sasha Levin wrote:
> Right now userspace can pass a large chunk of data and the kernel
> will attempt to allocate all of it to copy it in from userspace.
>
> The problem is that there is no upper limit on the size userspace
> can pass. Right now userspace can even force a machine to run out
> of memory by forcing the kernel to allocate large chunks of memory.
>
> To avoid imposing a limit, instead of allocating the entire block,
> we can allocate just the size of the biggest frag possible and read
> it from userspace one frag at a time.
>
> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
> ---
>
> ** WARNING: COMPLETELY UNTESTED ** (I don't have the hardware).
>
> net/nfc/llcp_commands.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/net/nfc/llcp_commands.c b/net/nfc/llcp_commands.c
> index a3ad69a..da68924 100644
> --- a/net/nfc/llcp_commands.c
> +++ b/net/nfc/llcp_commands.c
> @@ -727,27 +727,27 @@ int nfc_llcp_send_ui_frame(struct nfc_llcp_sock *sock, u8 ssap, u8 dsap,
> if (local == NULL)
> return -ENODEV;
>
> - msg_data = kzalloc(len, GFP_KERNEL);
> + remote_miu = sock->remote_miu > LLCP_MAX_MIU ?
> + local->remote_miu : sock->remote_miu;
> +
> + msg_data = kzalloc(remote_miu, GFP_KERNEL);
> if (msg_data == NULL)
> return -ENOMEM;
>
> - if (memcpy_fromiovec(msg_data, msg->msg_iov, len)) {
> - kfree(msg_data);
> - return -EFAULT;
> - }
> -
> remaining_len = len;
> msg_ptr = msg_data;
>
> do {
> - remote_miu = sock->remote_miu > LLCP_MAX_MIU ?
> - local->remote_miu : sock->remote_miu;
> -
> frag_len = min_t(size_t, remote_miu, remaining_len);
>
> pr_debug("Fragment %zd bytes remaining %zd",
> frag_len, remaining_len);
>
> + if (memcpy_fromiovec(msg_data, msg->msg_iov, frag_len)) {
> + kfree(msg_data);
> + return -EFAULT;
> + }
> +
> pdu = nfc_alloc_send_skb(sock->dev, &sock->sk, MSG_DONTWAIT,
> frag_len + LLCP_HEADER_SIZE, &err);
> if (pdu == NULL) {
>
prev parent reply other threads:[~2014-08-04 19:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-20 3:23 [PATCH] NFC: Read frag at a time when sending packets Sasha Levin
2014-08-04 19:39 ` Sasha Levin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53DFE175.5040602@oracle.com \
--to=sasha.levin@oracle.com \
--cc=aloisio.almeida@openbossa.org \
--cc=davem@davemloft.net \
--cc=lauro.venancio@openbossa.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfc@ml01.01.org \
--cc=linux-wireless@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sameo@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.