Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3701339pxk; Tue, 29 Sep 2020 04:12:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQkIwqyJX7OaZNrv/xhGs2PXzUyjYrfH6AGkNgIx8uINVEGk0X0VIC38oeESP+JEWsoVRl X-Received: by 2002:a05:6402:164d:: with SMTP id s13mr2592909edx.222.1601377940776; Tue, 29 Sep 2020 04:12:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601377940; cv=none; d=google.com; s=arc-20160816; b=VcEG4e/CmRzF2SL+uSNbssTHkEOJHS1pA6DYlP8ZiyodWGt2aEkR8cCOBLnFUA/zow WNUMaLCAgngPUC6v5uBnib2XPglmqnWAuUUZlp+vtkrprRMxbX0/e3eVh9BfK8VcTbQ7 IceTHZRNtaXf3oHVac+3t2H4G3G14SHdT2KTxVFp59HdD1IGCH87YXYD9TvvAv+JIb0y Bux15iVpsazM6VpRnhh9k6T/+mY7/9SO+Mov91AyfHnwpGJUModuTU6vGz7XB0UOjxDW WKcmOpy/cc0jXqu2PBFFcHIkZvfuo6rhRb2oOe28bOdkvtMCpu2DBCActEvn9OkgFwPS CtZg== 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=ZoiEAJIp8iUhYw2h/Rm0uHF0RR0hHvnkbTMj6VZW5Tx4BhgjGs/cem/8cIUgwhemgx RHCG9xpc0lOzOTK2CD26yrf7SkH4KW3zXKs6ImJFlJhBeH2rQu3/HWE478Do2tIjCzkn 3zxbQymWpOaQXX0KuOY2hm9JvE/ngxWLiw+aoywnUA8R2pAjW9Lz2PyqEp6GDEi2hkux J5kHq453yj9QvQJJrM7ETBB575ytl96E8FVcIWWDUOBIXJS4co0lBy/GWe4KzWGEwUuC nTONDrbXcgrrRwZwZR3Z92dI99cn2cMyQsD65lVy7Hf0clEYVbHbTn+X0pKTg2xTOCnt kmug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gs9ASzkZ; 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.11.57; Tue, 29 Sep 2020 04:12:20 -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=gs9ASzkZ; 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 S1728960AbgI2LHq (ORCPT + 99 others); Tue, 29 Sep 2020 07:07:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:46102 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728592AbgI2LHc (ORCPT ); Tue, 29 Sep 2020 07:07:32 -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 79E6122204; Tue, 29 Sep 2020 11:07:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601377651; bh=FoBam2veeWQfEGkz6ViIW5Dqs9nvjPiWZ1sa5WoABDE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gs9ASzkZLQ0Cp6rDyrc5IINwTrIk+xTSk2BPwNy/6arOW+6tGhcfdPtjrEb42oC2o 034npsPQH4Rgi2xIcNfBZgA4E2wCBAo/NypgdkK9yK8HeXWvcToCaa+hOWb3Q0UkXs JUYHq1Z7z/Ij35tvs6zDzYdHKVPx2yXhPvHBzutk= 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.9 008/121] tipc: use skb_unshare() instead in tipc_buf_append() Date: Tue, 29 Sep 2020 12:59:12 +0200 Message-Id: <20200929105930.597355843@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929105930.172747117@linuxfoundation.org> References: <20200929105930.172747117@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;