Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4182416pxb; Mon, 8 Feb 2021 09:49:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJwS3UTXL+gOS6vIkH8Yg5pwwGpfzY5pgbzcHy1uHUz4sqZkbF6UKLDqkBdL+vZBWKNv/41c X-Received: by 2002:a50:d6c1:: with SMTP id l1mr18364555edj.336.1612806554970; Mon, 08 Feb 2021 09:49:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612806554; cv=none; d=google.com; s=arc-20160816; b=PgLKCRdPAIhM1WHX7+n4LFwlKoNpIoOklHoBK3axd/4PGBQxb5lByNydLiqga+KSIh OU76NvAdj+rfk12pGVjIMkupqwKdim2CzKosd3eKLjJ1EGa1eD/8KkVEFxuB1Req4T6O V4FIGKKRbA3EpyZitn1VXUGEIheC3nBVo2QLfoKS7/Es/GBTOoxCrzaBRh/zxajHRB61 Ml1lZtpXy+keg5SFlp5Y1lKZ6M4j1RMlmWH45q318ZVwkPpvEi9fI0Lj0Vy9uupE/8IJ 1t483YRAOZ+VCSh7kvXq0PtyFBnLcilHY4UJ74N59m7RC2ehrTN6S/b58EuqVhjl0dW+ y+Sw== 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=+RuLJzOO+W6t6OrgP0+v1Gkw8Kre404kB6eYnN33dGk=; b=gvXGQJH5GwA0GS9296b8JtRrr0FeUs/RmuUq58du0W3r6MhmG6UMsJBX4MHfTJEURb rmP/rAEcgUTDgJ3O/R5OsOioHiNhsRtigh/RTJbzd0v3LdA1MI558orOMnrJ8j3nDBZW 82Euu+ru0EGzZAt4/BFev7h3kCUDfetdT66i8JYsmjzyb3eBD4wdQbEgTlEWCEMVJeFX TfEu+SEJozSW1NF3wesZqR1l144CkfOkHgP+G1eoY1Ton/Os8ftS0gZddDRaQu5Rp+CQ 7vkk9jx3vfKzXilBZb9htELyNVo62xyjvL2t3XixRrml1KQgdJajLLcBzMPGKMz6yYWu Tl/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="L/tQYQzY"; 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=pass (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 j3si5376243ejy.648.2021.02.08.09.48.48; Mon, 08 Feb 2021 09:49:14 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b="L/tQYQzY"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235084AbhBHRr5 (ORCPT + 99 others); Mon, 8 Feb 2021 12:47:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:36948 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233911AbhBHPbi (ORCPT ); Mon, 8 Feb 2021 10:31:38 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id A290064F37; Mon, 8 Feb 2021 15:17:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612797456; bh=oGYFLcwBYUzIxPOwoh/aKsUxQYKMGRHnAS+QCYCIaTs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L/tQYQzYHVso8zMUzuQXom7trBXU8UiL/DSrzalit8eOMO6dCRL388s6bRIddpSu5 9Pp3D+BMjA3xTChhDSOiQrYArBWf8gdKWxud9XuPI6pOaa7wHqolBBzY2p3f2z5ERE kphBws32Wo5oDHNHqV++8cnx6iYbZRtpTxzeIq/0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chinmay Agarwal , Cong Wang , David Ahern , Jakub Kicinski Subject: [PATCH 5.10 116/120] neighbour: Prevent a dead entry from updating gc_list Date: Mon, 8 Feb 2021 16:01:43 +0100 Message-Id: <20210208145822.990723934@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208145818.395353822@linuxfoundation.org> References: <20210208145818.395353822@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: Chinmay Agarwal commit eb4e8fac00d1e01ada5e57c05d24739156086677 upstream. Following race condition was detected: - neigh_flush_dev() is under execution and calls neigh_mark_dead(n) marking the neighbour entry 'n' as dead. - Executing: __netif_receive_skb() -> __netif_receive_skb_core() -> arp_rcv() -> arp_process().arp_process() calls __neigh_lookup() which takes a reference on neighbour entry 'n'. - Moves further along neigh_flush_dev() and calls neigh_cleanup_and_release(n), but since reference count increased in t2, 'n' couldn't be destroyed. - Moves further along, arp_process() and calls neigh_update()-> __neigh_update() -> neigh_update_gc_list(), which adds the neighbour entry back in gc_list(neigh_mark_dead(), removed it earlier in t0 from gc_list) - arp_process() finally calls neigh_release(n), destroying the neighbour entry. This leads to 'n' still being part of gc_list, but the actual neighbour structure has been freed. The situation can be prevented from happening if we disallow a dead entry to have any possibility of updating gc_list. This is what the patch intends to achieve. Fixes: 9c29a2f55ec0 ("neighbor: Fix locking order for gc_list changes") Signed-off-by: Chinmay Agarwal Reviewed-by: Cong Wang Reviewed-by: David Ahern Link: https://lore.kernel.org/r/20210127165453.GA20514@chinagar-linux.qualcomm.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/core/neighbour.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -1245,13 +1245,14 @@ static int __neigh_update(struct neighbo old = neigh->nud_state; err = -EPERM; - if (!(flags & NEIGH_UPDATE_F_ADMIN) && - (old & (NUD_NOARP | NUD_PERMANENT))) - goto out; if (neigh->dead) { NL_SET_ERR_MSG(extack, "Neighbor entry is now dead"); + new = old; goto out; } + if (!(flags & NEIGH_UPDATE_F_ADMIN) && + (old & (NUD_NOARP | NUD_PERMANENT))) + goto out; ext_learn_change = neigh_update_ext_learned(neigh, flags, ¬ify);