From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 4E59C3C10B3 for ; Thu, 25 Jun 2026 07:05:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782371128; cv=none; b=ZhXlIZKF1USn3k9BXC9MO4Tigwxs3Zdnhy8+gi8Z3Tdy4UmTqUmDbAuuKeADfeN11E2SmIgWKpo8UbHYBtQqJRizqDQGzQqB0C0hJbJupAEVWWLB/jOfugnWcML6OGEJOu5kEVDeDKjjEJZjzdJUUcW7Lc24Mv6+k7CblEN8z1w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782371128; c=relaxed/simple; bh=sozevHDQszseOf1dQTv17dZ96y/NfOOSZzfBF4CtGIY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=ZuOu/3QHd29JWO9oa5kKqN7worzTDIrQ0gtyCbgSMncFAMgtAIxo+916xDRLb1Tn5xc6SAQjEsatNDl5mvWT7JOh54JDwZf8crlWiFBMCvTRxmdJuKM0za4sLuckmeZFe6rjdGJ8pHixExUfPsM8c+bE+H+MuZxWE2ujNVIT4qo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=rSFM7YCk; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rSFM7YCk" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2c7cfa17fedso14733715ad.3 for ; Thu, 25 Jun 2026 00:05:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782371124; x=1782975924; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3myBgouSemGQyy63uNOanLWZfrnwzbhR0El07JRzF80=; b=rSFM7YCkO4Oll8rFlcXWVmDVRECV4Es6Ua67Dzkasfjj6tOyC1GUhkIWaAFG1DNQqC 2k7pbFfIjGDxJn1Hke5VxmWUCHP1m56f3qhI9JdhBijmCk1pJ7soGIo044i2uZOHEFyT q02xrQuw+nmrp0b/jvJdfB5/RJp4Xr+pbcfz7QHe6ZJSRY9tEEfMZGb4jn+XinYEJkOe eCohWl7L8KVTtGnPK7mFFyJW6BNYIfzZfG0OnHvdPEoiSiFYEZyD8TW5wzGW1OvSZhF4 EVljw9+9gZThdgrwMlaPRN1IIxz/qwos5nUSZmCza6ufD4sgcFQUtGuHVVcxkclnM162 28mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782371124; x=1782975924; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=3myBgouSemGQyy63uNOanLWZfrnwzbhR0El07JRzF80=; b=rjHINKwZFTU1inEarUMOJw6V9mFt/8Qu/GDEFuBOLVXqBus6NSi84yfjWY4O7taAxO kkwP6K3+JL+ZpK5vEiqe0dNrtM002Idm1FSf5/A0ewINjt1vWbSHr2QdwIhdOaWuRtbN MaOLJocvS17ivjgCrKA90rZ8A5ikhz0NPfVxu7n/Rz97jJy7PzZOjcheAhWt+v5Mko/q wmd7d5SR7sPviq+GB7hcEJkU7+rZDrujEJ3n8ratMfqC/nbmpvZ7lQ+WNHRsTCq8tBig d6byQD9Uk1jN704Ur54vnEzWAKg6NiIggADCArSbhFWQIxt4E/s5UyU44AAVCG82WVKw iW0Q== X-Forwarded-Encrypted: i=1; AHgh+Rqo3e7AqmWaCg2jpkdbbJQCAQnTJhubLdfXgOK8fUGrZC9gCeLGWgdDfM3f56mqKEtKRjxt+3Dnw81Vno4=@vger.kernel.org X-Gm-Message-State: AOJu0YzxTgWPwhA2dN9I7HCV0S1C/X4MPC1fLOdtDMuZ7OtBWdeOlvIe 0+iTniaNlSUdq9VwMc83SAKQXXPy9Ng+XOSYlyE2mluP1+WeJEuklVtx X-Gm-Gg: AfdE7cmiG9hdxFFpzcD2n3unE6R+1vRiyqqK5hsTK8euIGQ7JTW4aYITovGkLBWgzev SPoHM6Kcsh3D/gk1bzlEB+USmFjFIciroTtemI7ckEG3jhohcCmS7DsWosddCHwxSIAjhBHw6rQ dkVaVGmSPbbJxH2mtrgjREXZVD48AR6yrPQLP6ujGY2DFgxT0M5bGTymd2WxNm0LjpqP4+CCydU ULkthiEnl9GwfousLTQ6XZauThiWDLIWiRsO4RdGJRKerjMjpWJih5lJGVI8QKBhWokBJVZ1mbG yOtRKLYy8DM9i2JbOJGv4W9H0fGGAW+hseTFrEu5yQX+zfPsLQmaJhf8CHT+JlbjMcTUg0RKnGD Wto3kQskE/VAfJSm6milTazzcfAWRGam16tNNPTyd4a1W/uPU5z62O0z6O4VJwumPLRFeByvN98 Ise6QNAEDtAXoB1AuJDoYnizdZJeA= X-Received: by 2002:a17:903:2286:b0:2c1:d49c:8397 with SMTP id d9443c01a7336-2c7fc68d9a2mr15417205ad.12.1782371124237; Thu, 25 Jun 2026 00:05:24 -0700 (PDT) Received: from online.mioffice.cn ([43.224.245.228]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c7f5ac8e3csm13539915ad.10.2026.06.25.00.05.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2026 00:05:23 -0700 (PDT) From: Pengfei Zhang To: dsahern@kernel.org, idosch@nvidia.com Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, chenzhangqi@xiaomi.com, baohua@kernel.org, Pengfei Zhang Subject: [PATCH v3 net] ipv6: fib6: fix NULL deref in fib6_walk_continue() on multi-batch dump Date: Thu, 25 Jun 2026 15:05:17 +0800 Message-Id: <20260625070517.965597-1-zhangfeionline@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit inet6_dump_fib() saves its progress in cb->args[1] as a positional index within the current hash chain. Between batches, a concurrent fib6_new_table() can insert a new table at the chain head, shifting all existing entries. The saved index then lands on a different table, causing fib6_dump_table() to set w->root to the wrong table while w->node still points into the previous one. fib6_walk_continue() dereferences w->node->parent (NULL) and panics: BUG: kernel NULL pointer dereference, address: 0000000000000008 RIP: 0010:fib6_walk_continue+0x6e/0x170 Call Trace: fib6_dump_table.isra.0+0xc5/0x240 inet6_dump_fib+0xf6/0x420 rtnl_dumpit+0x30/0xa0 netlink_dump+0x15b/0x460 netlink_recvmsg+0x1d6/0x2a0 ____sys_recvmsg+0x17a/0x190 Fix by storing tb->tb6_id in cb->args[1] instead of a positional index. On resume, skip entries until the id matches; a concurrent head-insert can never match the saved id, so the walker always resumes on the correct table. Fixes: 1b43af5480c3 ("[IPV6]: Increase number of possible routing tables to 2^32") Signed-off-by: Pengfei Zhang --- v3: - Fix Author/SOB email mismatch (use gmail for both) - Drop "RTNL lock is released" from commit message (RTNL removed from IPv6 FIB) - Reorder local variables to follow reverse xmas tree - Move blank line after continue for readability v2: - Add Fixes tag v2: https://lore.kernel.org/netdev/20260625044101.939070-1-zhangfeionline@gmail.com/ v1: https://lore.kernel.org/netdev/20260624171156.822055-1-zhangfeionline@gmail.com/ net/ipv6/ip6_fib.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c index fc95738de..a130cdfae 100644 --- a/net/ipv6/ip6_fib.c +++ b/net/ipv6/ip6_fib.c @@ -636,12 +636,12 @@ static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb) }; const struct nlmsghdr *nlh = cb->nlh; struct net *net = sock_net(skb->sk); - unsigned int e = 0, s_e; struct hlist_head *head; struct fib6_walker *w; struct fib6_table *tb; unsigned int h, s_h; int err = 0; + u32 s_id; rcu_read_lock(); if (cb->strict_check) { @@ -701,23 +701,22 @@ static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb) } s_h = cb->args[0]; - s_e = cb->args[1]; + s_id = cb->args[1]; - for (h = s_h; h < FIB6_TABLE_HASHSZ; h++, s_e = 0) { - e = 0; + for (h = s_h; h < FIB6_TABLE_HASHSZ; h++, s_id = 0) { head = &net->ipv6.fib_table_hash[h]; hlist_for_each_entry_rcu(tb, head, tb6_hlist) { - if (e < s_e) - goto next; + if (s_id && tb->tb6_id != s_id) + continue; + + s_id = 0; + cb->args[1] = tb->tb6_id; err = fib6_dump_table(tb, skb, cb); if (err != 0) goto out; -next: - e++; } } out: - cb->args[1] = e; cb->args[0] = h; unlock: -- 2.34.1