From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71F8138B157 for ; Sun, 16 Aug 2026 08:20:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786868428; cv=none; b=VdQB2uif/XKZHd12MYPDkaFtzRzt5Y1YHMIcY+MpjNTToKnebdqkNi8reiDlCHHAcz5V+QbU8y/x9zm/PuGouXLfZzBDbnXa82+7nqQ6N2I7HDAFmlj/K5CONrhDJ4hEkn4zXq1t6eghTSPKfk9NMT2NVaymKjjV2a8Ci7d1GLw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786868428; c=relaxed/simple; bh=oqmqmq+uz6mm/NU80WHXIL/tdCLKQOzi8f9AE3QURdE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Ii9JBx7iws5gxlvOagP2qwwAeKVFT/zSsPVBqEOIwPJxZUO6o5qWi/RrFDnYrfAXeHPcr4MCN++tcyf6AKG5WlND6eOqqRGGijvEjAvKw0gdpQ6g2VS6sx6sM5UtsMiHXgEVtoX/OPzoxt98cNBTPJtmPPbFs6QpLVzy/BiAWsU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=blackwall.org; spf=none smtp.mailfrom=blackwall.org; dkim=pass (2048-bit key) header.d=blackwall.org header.i=@blackwall.org header.b=QhYP8WEH; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=blackwall.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=blackwall.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=blackwall.org header.i=@blackwall.org header.b="QhYP8WEH" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4954a9e8490so19815375e9.1 for ; Sun, 16 Aug 2026 01:20:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall.org; s=google; t=1786868421; x=1787473221; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=dWpc8mSAb0Ps+eqxqppAUahFxDXBRTVvYVd6wme8rOo=; b=QhYP8WEHRIwiEYPCJIkDWNepAXB6968UVtQGzZoLkdJdQKxIyst9kRXtHl8OywWl/a pj5vywKdyVRSbI0vc51EahTrGI1RT7anwbmNT3sSiFlVM1qWwi1cQUmeDRkXSkO20Qk9 Lzd+9s3r8PMd/yuVC8cdGWY+T+l9KyH/fbm6af1DodEC0aXsKiv3p5uyQkIqkvNofe3/ o9FsVGuvg3gyn0la72VdL257O5c30mjCLBpIoIi8dSDVhw4DnxPnLulbzeeXoI/EFM6W WZrbN7ZQ9+r/8oSgqSjSXB+q5QPr/+ela/6DLyzGKPpj46UJRUz3YoGN7vd2JMxdCREA tqNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786868421; x=1787473221; h=content-transfer-encoding:content-type:in-reply-to:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=dWpc8mSAb0Ps+eqxqppAUahFxDXBRTVvYVd6wme8rOo=; b=HuxrGNPa9f9WF3Rf4Ai0pP89r8iBbtRbkZtJ/Yq6inT0DxFP99yT3ufGX9N6RzjBhw avKnElcXXKn08Seprvb1ze9fl0+qmftV/CnnlXyg2Lcwd+z3ZPHKBdOcrnhzgFxeunj1 gWYwGAQM/IbP0V7pGcAmH1Nxq8XpxOt9EehSm9PukSfbmLnRRz0LKs3VjEnwhXKf9BdM NT5IHHthqsk0BI3xuJJYugjLrR8yh8pCYRWZHQ9tKwjLUz4vdVJYvF0n/m7ffArXW8N8 fN190UyG7qrTzrtN6vwG9AugjcrXjtfAvm3fJruAEKEAXvLEB7jR/lyvVUSTbO58vyc/ /znw== X-Forwarded-Encrypted: i=1; AHgh+RpGEnG0hhDmBJ4u8CdTg5uJLCgoBLHnmzQQS1/l3gqGGWUn3CwHK2cS8eYDqh0TSQ5fAuUTKsmgwTD7UdM=@vger.kernel.org X-Gm-Message-State: AOJu0Yz4uvct3RpmxzCEQeuv9YXUeOTA43UhCeDbfdHHChTap0+ZOh95 MIRVz4cetyK9af8boOmiWYiuM32kRu1B0h3ek2/6qSiP1j5qD/Fod9kmSCJJZ+H0BVI= X-Gm-Gg: AR+sD10HcF4Io3/zOjhrd25q7+Ki7ctS0a0+iqooJLdcnlI+m4jrzSOe/5kRPO2d+JA 5hEZRm566nPWcEUjlagUz/ch+Re7XRXRDASpCB0r8/wplBdszku4j0yj8IAkpDDQaWAKFRxphY4 PI4BwT1C6plhyrRaZBqnHnV8vl/NcV1JydE4hDtZGXoDDKEIjjX1qtbLBLuEehT/1Sr3fVldKDm arKTRmSTXyNXpE123F4QbIXEnAY+UmpMzOU670vSXzTClveIy8ZvP3jwMCjVeEMLcx0Ug1I8ReY qPDgHiMPlFzIJUE9+iG/pGi0vbG7vwTL9EKHoY1qFq3XTAcWM8PZgO8j5fs44zjhpdtC3tc7WOg ToKSc+uagrU+B4ox0FEePrY1w6hbwMmDkm6d03NEqiX0qX6E+VYXvo0f5KLbyGLmgQ/eoVdFHDz JplDlNojxN/iC9giRaaNynq3BxdJ7WYduJRGHAV1o+aAsTUqjQjgN4Q8ssBlB/oRRkkjzYqxTYu VofgZnZ7lL6a6Lufi4= X-Received: by 2002:a05:600c:4e14:b0:495:3bc6:d381 with SMTP id 5b1f17b1804b1-49987a4f03bmr274724285e9.2.1786868420491; Sun, 16 Aug 2026 01:20:20 -0700 (PDT) Received: from [192.168.0.161] (78-154-15-182.ip.btc-net.bg. [78.154.15.182]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49987b3a6dcsm85352655e9.1.2026.08.16.01.20.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 16 Aug 2026 01:20:20 -0700 (PDT) Message-ID: Date: Sun, 16 Aug 2026 11:20:19 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net] vxlan: mdb: Fix use-after-free in vxlan_mdb_flush() Content-Language: en-US, bg To: Baul Lee , andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: idosch@nvidia.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, federico.kirschbaum@xbow.com References: <20260814153547.29567-1-baul.lee@xbow.com> From: Nikolay Aleksandrov In-Reply-To: <20260814153547.29567-1-baul.lee@xbow.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 14/08/2026 18:35, Baul Lee wrote: > vxlan_mdb_flush() iterates over the MDB entries using > hlist_for_each_entry_safe(), which only tolerates the removal of the > current entry. Contrary to the comment above the loop, the removal of an > entry can trigger the removal of another entry. > > Flushing the remotes of a (*, G) entry also removes the (S, G) entries > that were created for its source list, once they are left without > remotes: > > vxlan_mdb_remotes_flush() > -> vxlan_mdb_remote_del() > -> vxlan_mdb_remote_srcs_del() > -> vxlan_mdb_remote_src_del() > -> vxlan_mdb_remote_src_fwd_del() > -> __vxlan_mdb_del() > -> vxlan_mdb_entry_put() > > Such an entry can be located after the (*, G) entry in the list, as > vxlan_mdb_entry_get() returns an existing entry without moving it to the > head of the list. This order is obtained by adding the (S, G) entry > before the (*, G) entry, the latter with NLM_F_REPLACE, as the addition > of the source otherwise fails with -EEXIST. The (S, G) entry is then the > entry saved by hlist_for_each_entry_safe() and it is freed while the > (*, G) entry is processed. The next iteration calls hlist_del() on it > again, writing LIST_POISON1 to LIST_POISON2 [1]. > > Besides device deletion, the flush is also reachable from RTM_DELMDB > with NLM_F_BULK. > > Fix by re-reading the next entry after the remotes were flushed. The > current entry cannot be removed by this flush, as source lists can only > be configured on (*, G) entries and the removed entries are (S, G) > entries. It is therefore still linked and its next pointer reflects the > removals. > > [1] > BUG: KASAN: wild-memory-access in vxlan_mdb_entry_put.part.0+0x328/0x588 > Write of size 8 at addr dead000000000122 by task ip/327 > > CPU: 3 UID: 1000 PID: 327 Comm: ip Not tainted 7.2.0-rc7 #2 PREEMPT > Call trace: > vxlan_mdb_entry_put.part.0+0x328/0x588 > vxlan_mdb_flush+0x1d8/0x25c > vxlan_mdb_fini+0x8c/0x100 > vxlan_uninit+0x1c/0x7c > unregister_netdevice_many_notify+0x954/0xd4c > rtnl_dellink+0x210/0x530 > rtnetlink_rcv_msg+0x434/0x4d0 > netlink_rcv_skb+0xc4/0x204 > rtnetlink_rcv+0x18/0x24 > netlink_unicast+0x4b8/0x548 > netlink_sendmsg+0x29c/0x560 > ____sys_sendmsg+0x390/0x3ec > ___sys_sendmsg+0x114/0x188 > __sys_sendmsg+0xf0/0x178 > __arm64_sys_sendmsg+0x48/0x60 > invoke_syscall.constprop.0+0x58/0x180 > el0_svc_common.constprop.0+0x74/0x140 > do_el0_svc+0x30/0x40 > el0_svc+0x38/0x98 > el0t_64_sync_handler+0xa0/0xe4 > el0t_64_sync+0x198/0x19c > > Fixes: a3a48de5eade ("vxlan: mdb: Add MDB control path support") > Signed-off-by: Baul Lee > --- > drivers/net/vxlan/vxlan_mdb.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/vxlan/vxlan_mdb.c b/drivers/net/vxlan/vxlan_mdb.c > index 055a4969f593..385889c001d1 100644 > --- a/drivers/net/vxlan/vxlan_mdb.c > +++ b/drivers/net/vxlan/vxlan_mdb.c > @@ -1422,14 +1422,17 @@ static void vxlan_mdb_flush(struct vxlan_dev *vxlan, > struct vxlan_mdb_entry *mdb_entry; > struct hlist_node *tmp; > > - /* The removal of an entry cannot trigger the removal of another entry > - * since entries are always added to the head of the list. > - */ > hlist_for_each_entry_safe(mdb_entry, tmp, &vxlan->mdb_list, mdb_node) { > if (desc->src_vni && desc->src_vni != mdb_entry->key.vni) > continue; > > vxlan_mdb_remotes_flush(vxlan, mdb_entry, desc); > + /* The flush can remove the (S, G) entries created for the > + * source list of this entry, including the one saved by > + * hlist_for_each_entry_safe(), so re-read it while this entry > + * is still linked. > + */ > + tmp = mdb_entry->mdb_node.next; > /* Entry will only be removed if its remotes list is empty. */ > vxlan_mdb_entry_put(vxlan, mdb_entry); > } The patch looks good to me, but I also think a selftest can be added. Reviewed-by: Nikolay Aleksandrov