Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1085274pxk; Fri, 25 Sep 2020 06:00:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3P3PS+RTTY1tK418TQOu/hF3dmow44oNr8T+O0ad8KWwh9rRlgWWL6s34TUJurN3yTJJw X-Received: by 2002:a17:906:4a8c:: with SMTP id x12mr2653802eju.271.1601038832217; Fri, 25 Sep 2020 06:00:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601038832; cv=none; d=google.com; s=arc-20160816; b=0CVtufgJGQk6JBaFRHTzpxDMzmL5kGpodrhfWYUP2FDOWvMepxvQLqVXcDCUvuYTYn BWvsxP8iy24bbV2BlLUK82PtxDjFx1EnYTBSXkJBeDvgYI3/H5QFEbcksx2qXTzUw3aM SKU+6jLdr9aGl/z8+TpXjo0a6Od0lJvOz3hiMzi8qS87adtGKuPGGPKjtzl6OICXBYuS WFT0mEwgXE04B7g6uzUndl+03jD+Tetx3dfVZWQAyRK+aPBLkl24y3jmKwPCnZw22Cbq vubDU2i7zt+klP0HEw0C3UcsmcqV7/qC/zj2NnD6sMG28sA28b4lwy3PO0G/l6zmGd5A BX2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xs9OSMYXglH5ID19gaMBTB2n+xri8qap4XxTC3FU/RU=; b=VnbEXbd1kyFxqywmQG3OuxCQibdJBJiUMPEX0X/SWxqKHW8roi4xJ9YNtIZU6t4zEI 3WPEQqFJ/0JKW2EPh5jo/HctDLc3K7iGGXn53BmHLk7Nghrj1rdHx7M1ol4g29BCiRPS 9PaUbZYQQ/3sgsretfryf6hiKmeV0NZVa9IEFVQEDQoA6+Hdf3AGAlYtg/dadfXROyKh MY8mm0dpzozeXbZqQ1hhUNcBvGZKfk8ZrjU6bCgSS80kOlZeXB8l5hLAzZrNnTQp1tkW VHkvo+czut0ANFh7oqMoFL7s4UuAZqCYWSaE+g9gdnEqAilB7//yqvxnba9z3SOohFTx oqZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rH2WEt2Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q26si1704834ejz.749.2020.09.25.06.00.09; Fri, 25 Sep 2020 06:00:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rH2WEt2Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729230AbgIYM4A (ORCPT + 99 others); Fri, 25 Sep 2020 08:56:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:60042 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729463AbgIYMxy (ORCPT ); Fri, 25 Sep 2020 08:53:54 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EE13721741; Fri, 25 Sep 2020 12:53:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601038433; bh=FoBam2veeWQfEGkz6ViIW5Dqs9nvjPiWZ1sa5WoABDE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rH2WEt2ZxQkq5uBOamTq7JABPsrreALr2756RXjaZ+kIpGNnaGqD9ewtW66H3QP6E nOrHczSWWzhFV08JMJk3lPTpPxv9VfVV0GTkCBmbnyn2Kn2rRCOKWkRAoO0cEQrlGk bKTYhZwimJrYPqJ5TlzhkTN/0M440zFGGWGbfoy4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shuang Li , Xin Long , "David S. Miller" Subject: [PATCH 4.19 17/37] tipc: use skb_unshare() instead in tipc_buf_append() Date: Fri, 25 Sep 2020 14:48:45 +0200 Message-Id: <20200925124723.531829400@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200925124720.972208530@linuxfoundation.org> References: <20200925124720.972208530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xin Long [ Upstream commit ff48b6222e65ebdba5a403ef1deba6214e749193 ] In tipc_buf_append() it may change skb's frag_list, and it causes problems when this skb is cloned. skb_unclone() doesn't really make this skb's flag_list available to change. Shuang Li has reported an use-after-free issue because of this when creating quite a few macvlan dev over the same dev, where the broadcast packets will be cloned and go up to the stack: [ ] BUG: KASAN: use-after-free in pskb_expand_head+0x86d/0xea0 [ ] Call Trace: [ ] dump_stack+0x7c/0xb0 [ ] print_address_description.constprop.7+0x1a/0x220 [ ] kasan_report.cold.10+0x37/0x7c [ ] check_memory_region+0x183/0x1e0 [ ] pskb_expand_head+0x86d/0xea0 [ ] process_backlog+0x1df/0x660 [ ] net_rx_action+0x3b4/0xc90 [ ] [ ] Allocated by task 1786: [ ] kmem_cache_alloc+0xbf/0x220 [ ] skb_clone+0x10a/0x300 [ ] macvlan_broadcast+0x2f6/0x590 [macvlan] [ ] macvlan_process_broadcast+0x37c/0x516 [macvlan] [ ] process_one_work+0x66a/0x1060 [ ] worker_thread+0x87/0xb10 [ ] [ ] Freed by task 3253: [ ] kmem_cache_free+0x82/0x2a0 [ ] skb_release_data+0x2c3/0x6e0 [ ] kfree_skb+0x78/0x1d0 [ ] tipc_recvmsg+0x3be/0xa40 [tipc] So fix it by using skb_unshare() instead, which would create a new skb for the cloned frag and it'll be safe to change its frag_list. The similar things were also done in sctp_make_reassembled_event(), which is using skb_copy(). Reported-by: Shuang Li Fixes: 37e22164a8a3 ("tipc: rename and move message reassembly function") Signed-off-by: Xin Long Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/tipc/msg.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/net/tipc/msg.c +++ b/net/tipc/msg.c @@ -140,7 +140,8 @@ int tipc_buf_append(struct sk_buff **hea if (fragid == FIRST_FRAGMENT) { if (unlikely(head)) goto err; - if (unlikely(skb_unclone(frag, GFP_ATOMIC))) + frag = skb_unshare(frag, GFP_ATOMIC); + if (unlikely(!frag)) goto err; head = *headbuf = frag; *buf = NULL;