Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753236AbdLAOs2 (ORCPT ); Fri, 1 Dec 2017 09:48:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:63859 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753183AbdLAOs1 (ORCPT ); Fri, 1 Dec 2017 09:48:27 -0500 Date: Fri, 1 Dec 2017 16:48:25 +0200 From: "Michael S. Tsirkin" To: wexu@redhat.com Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, jasowang@redhat.com, mjrosato@linux.vnet.ibm.com Subject: Re: [PATCH 3/3] tap: free skb if flags error Message-ID: <20171201164821-mutt-send-email-mst@kernel.org> References: <1512123038-15773-1-git-send-email-wexu@redhat.com> <1512123038-15773-4-git-send-email-wexu@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1512123038-15773-4-git-send-email-wexu@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 01 Dec 2017 14:48:27 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1672 Lines: 55 On Fri, Dec 01, 2017 at 05:10:38AM -0500, wexu@redhat.com wrote: > From: Wei Xu > > tap_recvmsg() supports accepting skb by msg_control after > commit 3b4ba04acca8 ("tap: support receiving skb from msg_control"), > the skb if presented should be freed within the function, otherwise > it would be leaked. > > Signed-off-by: Wei Xu > Reported-by: Matthew Rosato Acked-by: Michael S. Tsirkin > --- > drivers/net/tap.c | 14 ++++++++++---- > 1 file changed, 10 insertions(+), 4 deletions(-) > > diff --git a/drivers/net/tap.c b/drivers/net/tap.c > index e9489b8..0a886fda 100644 > --- a/drivers/net/tap.c > +++ b/drivers/net/tap.c > @@ -829,8 +829,11 @@ static ssize_t tap_do_read(struct tap_queue *q, > DEFINE_WAIT(wait); > ssize_t ret = 0; > > - if (!iov_iter_count(to)) > + if (!iov_iter_count(to)) { > + if (skb) > + kfree_skb(skb); > return 0; > + } > > if (skb) > goto put; > @@ -1154,11 +1157,14 @@ static int tap_recvmsg(struct socket *sock, struct msghdr *m, > size_t total_len, int flags) > { > struct tap_queue *q = container_of(sock, struct tap_queue, sock); > + struct sk_buff *skb = m->msg_control; > int ret; > - if (flags & ~(MSG_DONTWAIT|MSG_TRUNC)) > + if (flags & ~(MSG_DONTWAIT|MSG_TRUNC)) { > + if (skb) > + kfree_skb(skb); > return -EINVAL; > - ret = tap_do_read(q, &m->msg_iter, flags & MSG_DONTWAIT, > - m->msg_control); > + } > + ret = tap_do_read(q, &m->msg_iter, flags & MSG_DONTWAIT, skb); > if (ret > total_len) { > m->msg_flags |= MSG_TRUNC; > ret = flags & MSG_TRUNC ? ret : total_len; > -- > 1.8.3.1