public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Mark Salyzyn <salyzyn@android.com>
Cc: linux-kernel@vger.kernel.org, "Arad,
	Ronen" <ronen.arad@intel.com>,
	"David S . Miller" <davem@davemloft.net>,
	Dmitry Safonov <dima@arista.com>, David Ahern <dsahern@gmail.com>,
	Kirill Tkhai <ktkhai@virtuozzo.com>,
	Andrei Vagin <avagin@virtuozzo.com>,
	Li RongQing <lirongqing@baidu.com>, YU Bo <tsu.yubo@gmail.com>,
	Denys Vlasenko <dvlasenk@redhat.com>,
	netdev@vger.kernel.org, stable@vger.kernel.org,
	Eric Dumazet <edumazet@google.com>,
	Alexander Potapenko <glider@google.com>
Subject: Re: [stable 3.18 backport v2] netlink: Trim skb to alloc size to avoid MSG_TRUNC
Date: Mon, 25 Feb 2019 16:30:11 +0100	[thread overview]
Message-ID: <20190225153011.GG16015@kroah.com> (raw)
In-Reply-To: <20190222160330.34237-1-salyzyn@android.com>

On Fri, Feb 22, 2019 at 08:03:28AM -0800, Mark Salyzyn wrote:
> From: "Arad, Ronen" <ronen.arad@intel.com>
> 
> Direct this upstream db65a3aaf29ecce2e34271d52e8d2336b97bd9fe sha to
> stable 3.18.  This patch addresses a race condition where a call to
> 
>  nlk->max_recvmsg_len = max(nlk->max_recvmsg_len, len);
>  nlk->max_recvmsg_len = min_t(size_t, nlk->max_recvmsg_len,
> 
> one thread in-between another thread:
> 
>  skb = netlink_alloc_skb(sk,
> 
> and
> 
>  skb_reserve(skb, skb_tailroom(skb) -
>              nlk->max_recvmsg_len);
> 
> in netlink_dump.  The result can be a negative value and will cause
> a kernel panic ad BUG at net/core/skbuff.c because the negative value
> turns into an extremely large positive value.
> 
> Original commit:
> 
> netlink_dump() allocates skb based on the calculated min_dump_alloc or
> a per socket max_recvmsg_len.
> min_alloc_size is maximum space required for any single netdev
> attributes as calculated by rtnl_calcit().
> max_recvmsg_len tracks the user provided buffer to netlink_recvmsg.
> It is capped at 16KiB.
> The intention is to avoid small allocations and to minimize the number
> of calls required to obtain dump information for all net devices.
> 
> netlink_dump packs as many small messages as could fit within an skb
> that was sized for the largest single netdev information. The actual
> space available within an skb is larger than what is requested. It could
> be much larger and up to near 2x with align to next power of 2 approach.
> 
> Allowing netlink_dump to use all the space available within the
> allocated skb increases the buffer size a user has to provide to avoid
> truncaion (i.e. MSG_TRUNG flag set).
> 
> It was observed that with many VLANs configured on at least one netdev,
> a larger buffer of near 64KiB was necessary to avoid "Message truncated"
> error in "ip link" or "bridge [-c[ompressvlans]] vlan show" when
> min_alloc_size was only little over 32KiB.
> 
> This patch trims skb to allocated size in order to allow the user to
> avoid truncation with more reasonable buffer size.
> 
> Signed-off-by: Ronen Arad <ronen.arad@intel.com>
> Signed-off-by: David S. Miller <davem@davemloft.net>
> 
> (cherry pick commit db65a3aaf29ecce2e34271d52e8d2336b97bd9fe)
> Signed-off-by: Mark Salyzyn <salyzyn@android.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Ronen Arad <ronen.arad@intel.com>
> Cc: "David S . Miller" <davem@davemloft.net>
> Cc: Dmitry Safonov <dima@arista.com>
> Cc: David Ahern <dsahern@gmail.com>
> Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
> Cc: Andrei Vagin <avagin@virtuozzo.com>
> Cc: Li RongQing <lirongqing@baidu.com>
> Cc: YU Bo <tsu.yubo@gmail.com>
> Cc: Denys Vlasenko <dvlasenk@redhat.com>
> Cc: netdev@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Cc: stable@vger.kernel.org # 3.18
> ---
>  net/netlink/af_netlink.c | 34 ++++++++++++++++++++++------------
>  1 file changed, 22 insertions(+), 12 deletions(-)

Now queued up, thanks.

greg k-h

      reply	other threads:[~2019-02-25 15:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-22 16:03 [stable 3.18 backport v2] netlink: Trim skb to alloc size to avoid MSG_TRUNC Mark Salyzyn
2019-02-25 15:30 ` Greg Kroah-Hartman [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=20190225153011.GG16015@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=avagin@virtuozzo.com \
    --cc=davem@davemloft.net \
    --cc=dima@arista.com \
    --cc=dsahern@gmail.com \
    --cc=dvlasenk@redhat.com \
    --cc=edumazet@google.com \
    --cc=glider@google.com \
    --cc=ktkhai@virtuozzo.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lirongqing@baidu.com \
    --cc=netdev@vger.kernel.org \
    --cc=ronen.arad@intel.com \
    --cc=salyzyn@android.com \
    --cc=stable@vger.kernel.org \
    --cc=tsu.yubo@gmail.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