Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3761100pxk; Tue, 29 Sep 2020 05:45:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw77CVRwIbGlAWvoO68cmj/e33bzTXuN6b8QBC2EIvx3ENtdCcEHipopbjE4Pc8PXSh9ZD0 X-Received: by 2002:a17:906:aac7:: with SMTP id kt7mr3643966ejb.548.1601383522023; Tue, 29 Sep 2020 05:45:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601383522; cv=none; d=google.com; s=arc-20160816; b=iBCz6i0CtGCH1//BRbl/cTlWBQcGazlMv8a0TMzSzyiQm+50tsNh+wXrv+dYp7mViB gnQj3QWQfVgfQx222+u/rYCC10atH9kXAhMUOlw5xg1kaaBV7+xHchM4FtVUIdxKVVX5 m3uu/vApBPPQfCuFSATp2ZWcw1DAdzcENTl5C7obUysxRl/Y8vVRQZgKPe+laWvqztWy LIarGgaWIh41dgPeQEsSobnaKguHJGlWnvWuyXSE1x40qYxyUtuEhadv+0GAeF9dCS8Y ysR+yTRgCacXU5Dw7DQ5C8jEYn9DDkHzPZnlp6pnwSxURWV1SPuruKN21CH1Xg4U6Ma7 2tfw== 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=P1IgAxdwdaUqtttRV2TxUFyDapyarn59Pzm+A3KxQsM1t2L9nm+0a6uytAvB+VGbE/ Ci92d/EnmoDNCfpvDL5uLcDAnuvA355noWH4HBZ5+bDNm/Nq4+gT6JLwXVZt+ynmYaoZ K7YdGz84t3hQ8AmCnkn0b73dOKts7/qJzPsXgeFJs9adVUvQWbaL2NRYQEJv22uCIgZz n8KDmXKL7z2DL8uJVZdONKEJ/mQ9ufZjftEoFORSWmN47SEr04bqnqo4pjM23fL2dkYL 3mUy/42uMfepTBmOPKdUMAkAUUJrAXGb+ZEmrpBI65mggpv6MEQr2ymvpWKC77mWvNnk obUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YSjJyxWv; 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 h12si2937085ejx.608.2020.09.29.05.44.58; Tue, 29 Sep 2020 05:45:22 -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=YSjJyxWv; 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 S1732575AbgI2Ml5 (ORCPT + 99 others); Tue, 29 Sep 2020 08:41:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:54420 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729335AbgI2LMf (ORCPT ); Tue, 29 Sep 2020 07:12:35 -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 03848206A5; Tue, 29 Sep 2020 11:12:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601377954; bh=FoBam2veeWQfEGkz6ViIW5Dqs9nvjPiWZ1sa5WoABDE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YSjJyxWvQ/KQMdtKZpLeLfA8Z1256KoT2ABqjLgq+E051SdLnuc2nf+cgM6bJIcc2 XBu7BruusMNUyE+Xg21Pd6KVpQdTfau18HijMIPP37eUdXA7xPxBEX2dADUT+7KDJP 9T5Rpe9gSKXFze9UlLQU+lWZ0gqmZZrHKiCuWNus= 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.14 011/166] tipc: use skb_unshare() instead in tipc_buf_append() Date: Tue, 29 Sep 2020 12:58:43 +0200 Message-Id: <20200929105935.750982080@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929105935.184737111@linuxfoundation.org> References: <20200929105935.184737111@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;