Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4141040pxb; Mon, 8 Feb 2021 08:53:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJzIXPfw4frzkhdRlw2SZUy80Kae8eTAzbiMNypIsMWPwEA4ISDaHC3v2ZVMGMFNYME3XDCh X-Received: by 2002:aa7:cd61:: with SMTP id ca1mr17556868edb.76.1612803197288; Mon, 08 Feb 2021 08:53:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612803197; cv=none; d=google.com; s=arc-20160816; b=XJI9F/j6AKAQgGQzBe3Do/30ljS22bss3hmiEgtqkeoNm2q+qaFX3RWuxi5+IW0TcB EFz8lZo0bB7NA7Ekl4Yahycg6rXLQmXOr5IQTiMSenr+XOhJjVRysH1bAGEnudHiWUFW pppAIY4lGpI+8RSxCLMzGVpSHm0GseUI78whl0ocy5aZOK5j1QXgbiso8qAgmvN6KoYH Czygvtd/nn41dGmotVrA9pNiTFFHP5BzMXsPfazDw+Liu2lM6Ez63maPXNuv+O/lYbnn xsAhO4ydJodG4+LcEOYZXLhkytY9fSU4Y43pG1CEgjj52RpraNCjqAXM9WRpnbnKZDul WELw== 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=gZPgCCwYdHyxgRFtC/hDHa81grOgSOkfJfrOMT4+gfk=; b=akmdf6Hd8y8KOYhZujbolaxvRXmW4cY3lkW3fG+CYU8OnWDAxhVJX5JgySo8XFx0BF St5oyElzEMTNIHPwua9TMPBgH+U7QVggOmM5/80EnfED6Akfou3Q2m6jFS095eeuzFLG PMFjXGTN1KE4iWpqvXlT5Er7UmxX6/KltvE7jEBisLKxXzFLQkvVKnbftkTZRXHVaKdZ nN0NmjG636KZyQsBivFawLEjyZG9WI1OqIRSB4w3FL9X508mBUCrQwyHoZ0U1ZN/t9Tm raUP0VAQgV4HZmoWjlVhu47HnGEd6/P0/s51y46u1xxF5zxj6mGnCrPP4IkstaGkJu7B COlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IpaMx5pK; 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 g26si11880745edy.55.2021.02.08.08.52.51; Mon, 08 Feb 2021 08:53:17 -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=IpaMx5pK; 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 S234572AbhBHQvo (ORCPT + 99 others); Mon, 8 Feb 2021 11:51:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:33700 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233349AbhBHPRa (ORCPT ); Mon, 8 Feb 2021 10:17:30 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 937B664EBE; Mon, 8 Feb 2021 15:11:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612797106; bh=LKo9ZrO5UM2oPV6T3WVJdK3dskGNrGC1mz/F6YR38OE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IpaMx5pKo3ESYNTJuJ3H8vf8MItHemLbhB4AkaTgofcxKvONKOcs0etl6uVD/oCDa 9+xO3qfZbaAGnRxpDuA/il15LUXeIEMDSr22enKxZtAXUu4p6tnhlkGeRqbWR1kudE Lsjnd2C+YnG77msDu5jOp+8HIbH0zhi51GkgUUkE= 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.4 61/65] neighbour: Prevent a dead entry from updating gc_list Date: Mon, 8 Feb 2021 16:01:33 +0100 Message-Id: <20210208145812.578790260@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208145810.230485165@linuxfoundation.org> References: <20210208145810.230485165@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 @@ -1244,13 +1244,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);