Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2754040pxj; Mon, 31 May 2021 09:54:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTJVfVsl/lV7xuQ3tgGdXDZgoEw2aWXpVYLy99tpe0jiDR2BgWfPFnPH5/YdvklB/apXLm X-Received: by 2002:a02:ac05:: with SMTP id a5mr21777265jao.89.1622480063795; Mon, 31 May 2021 09:54:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622480063; cv=none; d=google.com; s=arc-20160816; b=jFEI6PGl6sG/js92rWTiYMggHUbe4elx+yFB1WU6gTzZ2nACo1jN200UtxfA6NxVvt AMIArWYdnbEG7hjyfGbqTOtDeybWTdmdPpanMM0bvtmCKXS9ntzs8nDOns46tgzBUbsc t1HRzaI2JYmX5aoMxwOCgGlnoRpPcunxkcILl3x7EdHOsjEoqMEnN36cQP8zQb1ZTNNO LgToTgWuOZ/iFg7Lyiyy2p2pljk2plShGJTkM30lY3A9TpIK4QVl3FNVixd3rwfCahiY nNodOtfkbXxmQNH4ISVMAuJLrWbjXgoDPw3fvpZPNY/5LNrzinFduTWILjXTk2ajb06g 8PNQ== 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=CLv5tq/v/qIQA/o8iZdKQhPNgB4cz7xGom7wN+iSFhc=; b=clphVme5DGyNK4r+YnnVHQnlbEQM92mLIagh5fz0k4zn74KyhM2OWoX5L4U85+UUxX qfjltOUYpj3nwRJvwyr700Tjan7xYeFSK7wgQtcOpuZ4rO/5vVhSgkXy32gMA9+hutKr 65cZuNykA4FeW5fSjELu6gXHbOyvAsTgywJcrxJfUvypu8nlgq7rvSzkKMWct2GQqkpQ 1xT7DTow0hSVXkyrSy7m+kf0ZNA1SIW+JMuypgScLO/mE9zio9EmZW0Q4R7hRNaZV3O8 UkMTpuCh8kjfj3IR5nbn3ixsHyaxHhBMdlH2YQ9aA3+m6kIxIc4dRYBWWTEP9lqJEx1N cH5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=naZxqA7Q; 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 d15si3694807iln.114.2021.05.31.09.54.10; Mon, 31 May 2021 09:54:23 -0700 (PDT) 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=naZxqA7Q; 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 S231986AbhEaQxT (ORCPT + 99 others); Mon, 31 May 2021 12:53:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:51184 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234425AbhEaO7c (ORCPT ); Mon, 31 May 2021 10:59:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DC20461CD1; Mon, 31 May 2021 14:01:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469691; bh=7GLuG7p2PLEwJpRKZsrVU/cz+qEOp6Ra4vJBqINOQjk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=naZxqA7QIhi94E/9ZnfLzTNg6K3qToWnUaBEgbEK/Za7JTUZU6OMkt5VNQlt2DMqT Q2cqBJNsrgXO7Ap551loEhfDyS9xd8BYezoJlvLpRTtdL7Ea6mbjSgtO9pEkN7wa61 al/PqEEOtExWgCT99ZHWWMiaAmD2V3XFKd1qajy4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chinmay Agarwal , "David S. Miller" Subject: [PATCH 5.12 295/296] neighbour: Prevent Race condition in neighbour subsytem Date: Mon, 31 May 2021 15:15:50 +0200 Message-Id: <20210531130713.624469233@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@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 eefb45eef5c4c425e87667af8f5e904fbdd47abf upstream. Following Race Condition was detected: : 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, arp_process() and calls neigh_update()-> __neigh_update(). Neighbour entry is unlocked just before a call to neigh_update_gc_list. This unlocking paves way for another thread that may take a reference on the same and mark it dead and remove it from gc_list. - neigh_flush_dev() is under execution and calls neigh_mark_dead(n) marking the neighbour entry 'n' as dead. Also n will be removed from gc_list. Moves further along neigh_flush_dev() and calls neigh_cleanup_and_release(n), but since reference count increased in t1, 'n' couldn't be destroyed. - Code hits neigh_update_gc_list, with neighbour entry set as dead. - arp_process() finally calls neigh_release(n), destroying the neighbour entry and we have a destroyed ntry still part of gc_list. Fixes: eb4e8fac00d1("neighbour: Prevent a dead entry from updating gc_list") Signed-off-by: Chinmay Agarwal Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/core/neighbour.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -131,6 +131,9 @@ static void neigh_update_gc_list(struct write_lock_bh(&n->tbl->lock); write_lock(&n->lock); + if (n->dead) + goto out; + /* remove from the gc list if new state is permanent or if neighbor * is externally learned; otherwise entry should be on the gc list */ @@ -147,6 +150,7 @@ static void neigh_update_gc_list(struct atomic_inc(&n->tbl->gc_entries); } +out: write_unlock(&n->lock); write_unlock_bh(&n->tbl->lock); }