From: Jason Wang <jasowang@redhat.com>
To: wexu@redhat.com, virtualization@lists.linux-foundation.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: mst@redhat.com, mjrosato@linux.vnet.ibm.com
Subject: Re: [PATCH 2/3] tun: free skb in early errors
Date: Fri, 1 Dec 2017 15:07:44 +0800 [thread overview]
Message-ID: <a079ad24-cf20-66bc-2f57-9d0df9534f22@redhat.com> (raw)
In-Reply-To: <1512107669-27572-3-git-send-email-wexu@redhat.com>
On 2017年12月01日 13:54, wexu@redhat.com wrote:
> From: Wei Xu <wexu@redhat.com>
>
> tun_recvmsg() supports accepting skb by msg_control after
> commit ac77cfd4258f ("tun: support receiving skb through msg_control"),
> the skb if presented should be freed within the function, otherwise it
> would be leaked.
>
> Signed-off-by: Wei Xu <wexu@redhat.com>
> Reported-by: Matthew Rosato <mjrosato@linux.vnet.ibm.com>
> ---
> drivers/net/tun.c | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index 6a7bde9..5563430 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -2067,14 +2067,17 @@ static int tun_recvmsg(struct socket *sock, struct msghdr *m, size_t total_len,
> {
> struct tun_file *tfile = container_of(sock, struct tun_file, socket);
> struct tun_struct *tun = tun_get(tfile);
> + struct sk_buff *skb = m->msg_control;
> int ret;
>
> - if (!tun)
> - return -EBADFD;
> + if (!tun) {
> + ret = -EBADFD;
> + goto out_free_skb;
Unfortunately, you can't to there since tun is NULL.
> + }
>
> if (flags & ~(MSG_DONTWAIT|MSG_TRUNC|MSG_ERRQUEUE)) {
> ret = -EINVAL;
> - goto out;
> + goto out_free_skb;
> }
> if (flags & MSG_ERRQUEUE) {
> ret = sock_recv_errqueue(sock->sk, m, total_len,
> @@ -2087,6 +2090,11 @@ static int tun_recvmsg(struct socket *sock, struct msghdr *m, size_t total_len,
> m->msg_flags |= MSG_TRUNC;
> ret = flags & MSG_TRUNC ? ret : total_len;
> }
> + goto out;
We usually don't use goto in the case of success, and you need deal with
the case skb != NULL but iov_iter_count(to) == 0 in tun_do_read().
Thanks
> +
> +out_free_skb:
> + if (skb)
> + kfree_skb(skb);
> out:
> tun_put(tun);
> return ret;
next prev parent reply other threads:[~2017-12-01 7:07 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-01 5:54 [PATCH net,stable v3] vhost: fix a few skb leaks wexu
2017-12-01 5:54 ` [PATCH 1/3] vhost: fix skb leak in handle_rx() wexu
2017-12-01 7:11 ` Jason Wang
2017-12-01 14:37 ` Michael S. Tsirkin
2017-12-04 7:18 ` Jason Wang
2017-12-01 5:54 ` [PATCH 2/3] tun: free skb in early errors wexu
2017-12-01 7:07 ` Jason Wang [this message]
2017-12-01 14:36 ` Michael S. Tsirkin
2017-12-01 5:54 ` [PATCH 3/3] tap: free skb if flags error wexu
2017-12-01 7:10 ` Jason Wang
2017-12-01 10:10 [PATCH net,stable v4 0/3] vhost: fix a few skb leaks wexu
2017-12-01 10:10 ` [PATCH 2/3] tun: free skb in early errors wexu
2017-12-01 14:48 ` Michael S. Tsirkin
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=a079ad24-cf20-66bc-2f57-9d0df9534f22@redhat.com \
--to=jasowang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mjrosato@linux.vnet.ibm.com \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=virtualization@lists.linux-foundation.org \
--cc=wexu@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®