Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3698673pxk; Tue, 29 Sep 2020 04:08:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwb9VfOXr52cFWbd6fG8l9BE6QPD/quLisjTSOAohoGYZZDCknNfccsTVKSJY4CzWfiAL1r X-Received: by 2002:a17:906:1b58:: with SMTP id p24mr3417660ejg.77.1601377697427; Tue, 29 Sep 2020 04:08:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601377697; cv=none; d=google.com; s=arc-20160816; b=1CVi2iJnpMna6XFla/fgZkJwefzPk8Er+Mva+77W3fI8Lzn2RI0xduNLCpzMiO8Pz3 9UeyBYtByk7vwgB7icqjYS0MBkBTg22d21eZ3TwFSvZI0XwRfCOMR4mZewDy1f5gYcNP g/NXhIDs22fgbvq5REHiVmdpEuutCZTZ2fF4rOpprVuK9geATnaQTirakKYQKazmUzSh StWN0/kivaoj9lX6VqnEIiLd1dKgQfq0M4vSrsYCJxRyHYAIFk+wgqv3CLptIL4zpnni 0usqCEPNvXOM3jFS7OI03SpVTy3/ytkaKIX5uSDpMV6BAP3hW4zZg8z4NUYmM0v0EHuo 8KIQ== 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=ZhloHmIFtiEA5ZcRmfNertd/ojXEftKjBGbUBhFtK2A=; b=d8szEcGGDvmdu5YLr5VhiVnhD4n+tEvg2oFpMLFtsXFT3kM3NmYH3V/1cW8By2i26u UWBdqb6s3yFd2KemaOKZP7siMkxz0l2jF+YP2sqYH+tj/HyY+zFkK/DzJvugmFV4ZXgM Jvy/CsyPFM2uFLpOpcTsu47CMGeHTmdQZHGccodr5+pGaSp6Co1z1VXquv2xYowJsY5h Xa1SYu5NPXgIATVa34Zm8xs0jeH9iT+Kt0krk37DHV8HQ6W9E3os4hTUyLJJac6YXlA9 I0wWHWjKHiARVIjwGlVTwlAnXdU+PXX+nKUc2+TA1eaZEGqh6unBby1jtNCgHEPUF27w 1BJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sEX3H6Eu; 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 r14si2492846eja.660.2020.09.29.04.07.54; Tue, 29 Sep 2020 04:08:17 -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=sEX3H6Eu; 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 S1728563AbgI2LEL (ORCPT + 99 others); Tue, 29 Sep 2020 07:04:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:39762 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728510AbgI2LDv (ORCPT ); Tue, 29 Sep 2020 07:03:51 -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 7E9F720C09; Tue, 29 Sep 2020 11:03:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601377430; bh=ImMx++kpp07Hq0kepsuk/QTEl2u2P7t1iGvCh0958a8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sEX3H6Eug2HN9wW1VkNSL2sphnvCoEU50oC7X7i6+rnSZb05/anwL4DfT1XdnirrB aZqbG76vs9MvvLnJ9eCHjofL/bHL/AZL/HAqGt/aVxc7benhvkt9/JoXe5vXoCVOoI GWM3lZ9lGKOG2kXP9+2tvwxRYHv90DrEqS89dnfA= 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.4 08/85] tipc: use skb_unshare() instead in tipc_buf_append() Date: Tue, 29 Sep 2020 12:59:35 +0200 Message-Id: <20200929105928.633391461@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929105928.198942536@linuxfoundation.org> References: <20200929105928.198942536@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 @@ -138,7 +138,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;