From patchwork Fri Jul 10 11:51:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Khlebnikov X-Patchwork-Id: 493745 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 4A5081402D4 for ; Fri, 10 Jul 2015 21:52:08 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=yandex-team.ru header.i=@yandex-team.ru header.b=VmP0G87g; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754683AbbGJLwB (ORCPT ); Fri, 10 Jul 2015 07:52:01 -0400 Received: from forward-corp1m.cmail.yandex.net ([5.255.216.100]:49501 "EHLO forward-corp1m.cmail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754208AbbGJLvq (ORCPT ); Fri, 10 Jul 2015 07:51:46 -0400 Received: from smtpcorp1m.mail.yandex.net (smtpcorp1m.mail.yandex.net [77.88.61.150]) by forward-corp1m.cmail.yandex.net (Yandex) with ESMTP id 96FA861B48; Fri, 10 Jul 2015 14:51:41 +0300 (MSK) Received: from smtpcorp1m.mail.yandex.net (localhost [127.0.0.1]) by smtpcorp1m.mail.yandex.net (Yandex) with ESMTP id 4FE4E2CA05BD; Fri, 10 Jul 2015 14:51:41 +0300 (MSK) Received: from unknown (unknown [2a02:6b8:0:408:883f:1a2c:ff12:80cb]) by smtpcorp1m.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id ItF8m6vdzw-pfTqnZ3k; Fri, 10 Jul 2015 14:51:41 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1436529101; bh=DA0iMqUgMHtZ04NE9rKunzPsBJGLZNTAZ1nU+j5AnYc=; h=Subject:From:To:Cc:Date:Message-ID:User-Agent:MIME-Version: Content-Type:Content-Transfer-Encoding; b=VmP0G87giAbHltLIm48zUz7UXlLrsZ98dDxowajqFD3+tJ8AgI9MSJ68MFUZ4AEyl 26ERyjVXi78Uo5PijhspYdL36FRJvt+sOc2ZOsLuwP6jEnw4tbycvBXuaa73T3X1K/ RkVuUdPbQvcR3QywYpnWO7PJXrKfwHvGj9XA5rII= Authentication-Results: smtpcorp1m.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Subject: [PATCH] netlink: enable skb header refcounting before sending first broadcast From: Konstantin Khlebnikov To: netdev@vger.kernel.org, "David S. Miller" Cc: Eric Dumazet , Herbert Xu Date: Fri, 10 Jul 2015 14:51:41 +0300 Message-ID: <20150710115141.12980.88829.stgit@buzz> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This fixes race between non-atomic updates of adjacent bit-fields: skb->cloned could be lost because netlink broadcast clones skb after sending it to the first listener who sets skb->peeked at the same skb. As a result atomic refcounting of skb header stays disabled and skb_release_data() frees it twice. Race leads to double-free in kmalloc-xxx. Signed-off-by: Konstantin Khlebnikov Fixes: b19372273164 ("net: reorganize sk_buff for faster __copy_skb_header()") Acked-by: Eric Dumazet --- net/netlink/af_netlink.c | 6 ++++++ 1 file changed, 6 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index dea925388a5b..921e0d8dfe3a 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -2028,6 +2028,12 @@ int netlink_broadcast_filtered(struct sock *ssk, struct sk_buff *skb, u32 portid info.tx_filter = filter; info.tx_data = filter_data; + /* Enable atomic refcounting in skb_release_data() before first send: + * non-atomic set of that bit-field in __skb_clone() could race with + * __skb_recv_datagram() which touches the same set of bit-fields. + */ + skb->cloned = 1; + /* While we sleep in clone, do not allow to change socket list */ netlink_lock_table();