From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (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 EDF8D416D0C for ; Tue, 9 Jun 2026 12:26:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781008016; cv=none; b=lFcoEtKq0sSwnaa6sCrHMwDrC8nBzOWLUjnRndmC4/djOet8S5NTN3scW5wWWUKBA5QktQ1L80TjHCpH5yQH+IPjgyAWPaM9yNXZfnpWKcvWsRW4BPGQQQYu33jDJq/CfH/otv5WvSUkc8+ZPoeGt/cR5fxkKHiHvcSfrwvj4Go= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781008016; c=relaxed/simple; bh=VFoF5DQlSbS5V+oNvEguNMpshhkJmMJvM/OjwwToQxk=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=PodwJnNGduR/aqrxToXWZ6+x2Xar/P3sLzgC2XWKVgquV2Sy3e/8+t2//zDVtPhaOcpu1mt06kA0PP1UuxFI0QBv0AfS2YcJgW/3KYwTjlhNQ4y6m7XyQTRZv3sQ4KrvoMrIlrwxB0CRp1KtGNbqP/MVnmAgTyIHiy47V7dwg/8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yuyanghuang.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=U+J6Tjvy; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yuyanghuang.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="U+J6Tjvy" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-8422b1354edso6447058b3a.2 for ; Tue, 09 Jun 2026 05:26:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781008011; x=1781612811; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Nh4uo1ID0r54L4hLgT4uJy+Sb68L6GnZjfZbUG2JV88=; b=U+J6TjvyHRLjZcroQY+/bM6j9hN7d0pGl3eofIl6ZDuZ93lF6HfgyfJA3J34ok1QSy 46so9FHKLVkZlXFw22X3a9JKRzDd+yxYepgfkS4ruYru+tHDfd7jsbGFAdlhhoiPtmD0 9oDr0/kxW5/VG1wFFF5wM45PGYce6IrU+LlV5U/yOREPaINbVoT7SRu9+rpmLQyVmU+5 I6XlEx9X5JELDfYucbi+1+p8XJdI2ZJ0RoWGYC/9CxcGqgttPkUcbz9Tm4Agq+SR1u/O wG4+bHHzwZB3LCAIFBOyUiyXSu79780+MYFdKwe96pZAzw9Cd+BZzX2AtxEsGHnQkirF FUxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781008011; x=1781612811; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Nh4uo1ID0r54L4hLgT4uJy+Sb68L6GnZjfZbUG2JV88=; b=CKvDqF3+uixPRvPGj00Efjv5MtW2NRg2ChjXynbTUlLZsXBFGl8QObXyiXSFNO9W1O cbOt0aiTpwH9jD5DX0GEFt8IiGxr1RgDNgfxb44Ew0AhX/yWWcEG/69sVSjvfbuD5F9v Pv7uYpP9soDl/Q8xGFElmPmuaxYobSzY2Yh4ZtMRRdElVrFLBmNZ5mRY2Xy70LFbiDUe IC2kA/KLN+YSzuNK6Q2hP3d88S4O9lsFJvSrrGCQZS9g54tMofNhalsB9q9KVu+O9d98 x/SjeqmpZisNKqkQwGgMR/GeWSH/SFbG+dbntk2NiYNphI/WwvmAshqFkqCK9Y9T+5eb XWWA== X-Forwarded-Encrypted: i=1; AFNElJ+Rvt5bF6lOqSqtDulawrzhbC9epMlCJuzrvvA2pVCkYuY32oA6ZuCd7e34/O8d08Ak3ziERstJlXmgdG8=@vger.kernel.org X-Gm-Message-State: AOJu0Yyw3Cw9reZ3c2EgEfRRdE4w82/JxmY+exB0TxO/IUyFpf6/o+l8 vgdUkEeNL6HMW4z/EWLOjqx67LhUFRXMH6TZ1as95RSYKv1JVHtp/g9JQPiqH7FdV5qODaAjsZM oZnfia73Ib1OqElrLkQnLuHA0eg== X-Received: from pfbeh14.prod.google.com ([2002:a05:6a00:808e:b0:82f:c134:e67c]) (user=yuyanghuang job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:3e07:b0:842:6419:3ed2 with SMTP id d2e1a72fcca58-842b0eecc85mr20522482b3a.33.1781008010894; Tue, 09 Jun 2026 05:26:50 -0700 (PDT) Date: Tue, 9 Jun 2026 21:26:46 +0900 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.54.0.1099.g489fc7bff1-goog Message-ID: <20260609122646.2297540-1-yuyanghuang@google.com> Subject: [PATCH net-next] ipv4: igmp: remove multicast group from hash table on device destruction From: Yuyang Huang To: Yuyang Huang Cc: "David S. Miller" , David Ahern , Eric Dumazet , Ido Schimmel , Jakub Kicinski , Paolo Abeni , Simon Horman , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" When a device is destroyed under RTNL, ip_mc_destroy_dev() iterates through the multicast list and calls ip_ma_put() on each membership, scheduling them for RCU reclamation. However, they are not unlinked from the device's multicast hash table (mc_hash). Since the device remains published in dev->ip_ptr until after ip_mc_destroy_dev() completes, concurrent RCU readers traversing mc_hash can still locate and access the multicast group after its refcount is decremented. If the RCU callback runs and frees the group while a reader is accessing it, a use-after-free occurs. Fix this by unlinking the multicast group from mc_hash using ip_mc_hash_remove() before scheduling it for reclamation. Signed-off-by: Yuyang Huang --- net/ipv4/igmp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c index b6337a47c141..af38073a822d 100644 --- a/net/ipv4/igmp.c +++ b/net/ipv4/igmp.c @@ -1923,6 +1923,7 @@ void ip_mc_destroy_dev(struct in_device *in_dev) while ((i = rtnl_dereference(in_dev->mc_list)) != NULL) { in_dev->mc_list = i->next_rcu; + ip_mc_hash_remove(in_dev, i); WRITE_ONCE(in_dev->mc_count, in_dev->mc_count - 1); ip_mc_clear_src(i); ip_ma_put(i); -- 2.54.0.1099.g489fc7bff1-goog