Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2713795pxj; Mon, 31 May 2021 08:55:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzY5VKTEngnwgZVeqGM+9hztUvPyvcf0igdquXJYrz4LO7hwjk1A3M/2sVmKN3wB0qSR0K7 X-Received: by 2002:a05:6402:2215:: with SMTP id cq21mr26034122edb.28.1622476506231; Mon, 31 May 2021 08:55:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622476506; cv=none; d=google.com; s=arc-20160816; b=bnGp8ryUTnG5dlVsPTkk1TnYrCC9qjEyNlw1vI63knFOnz5iaQcWoOqjIkmEVl2O76 PJckNSiFJucITyE/ZcgUZC3G2yZZjlBqAYCLZ40FyRw7ps3h3oTXacwC/5fvMRaKwJiy 8rnE5Ld/Cn0IEu4qjNMxYQF1MsjT0loRrYyCPEx2GN1/y7jDOX9GpghsVzBeJNO6AVq/ mZJnKLWQtcJ9QkEov+wyIvK1M4b6mKJ9EPBmf9QEpvbt7aiVXnaV67UjV3PjEXIdOZz0 IXJmMlP3ChFLMIWSkiHZ5R54Z97cEru1YnXx6eM5hcQ0KB4Rskd6qGsHYunvjx6MUzdG XCiA== 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=HYGBIDySDCxfGfRugKuyr+xJwt1JQsM/w9KTeWLlEBM=; b=qn31ZCTDXYxPjmWoqgsAvKel5Y2yvCZD6rpxPVDO3mv/a7XzMvztAbI3xlQaqvOpwl in7pg+vKIC9s1DvhqXZGOffJstpp0o7CcAdWAaQ2nSKVTm7aRXcXyMIPHtl8PUB0JX+p 3C1HNy8Sv2GjbV+tD9qT09nwmJ/SdhSGvDiU6I3TLWsjIJD1uEQekNpzWs7HtFiL1nnT BUzhLxii6ES6VjaQ59YUy0JFUCE0fu82kmjH1S9/RIrn9XKxQSgch9uOCWB1eViIjBZL DbS+D7WYe9dgyCYGumYiu1Bnm8CCDsxqUCEHmevdFvVOsnBYsRt2YYNjQNnSUGEsO1V4 FDsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=khrdLc8C; 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 s18si15145942eji.59.2021.05.31.08.54.43; Mon, 31 May 2021 08:55:06 -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=khrdLc8C; 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 S234423AbhEaPzI (ORCPT + 99 others); Mon, 31 May 2021 11:55:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:56238 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233985AbhEaO3g (ORCPT ); Mon, 31 May 2021 10:29:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 14CF261C28; Mon, 31 May 2021 13:48:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468911; bh=95C73nfouQFTJ+QBHIZMzTYe7qD618sSkUDJj+FuyCc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=khrdLc8CiYYk+PMg2sntVr3U12REGwLNtBw9vIcEZF+VwGoLxCkGYdcXDQG8BgIAn cPTq7DyVBfOFO0PGX1o02IO/Ypm2fAuSHoXlapc6Vf3e8C+evHf+BgahxHqViYXRIp 41F8qOm7r15fYLkVi6o8Ja7hKVGZoIxY7/375fZ8= 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.4 176/177] neighbour: Prevent Race condition in neighbour subsytem Date: Mon, 31 May 2021 15:15:33 +0200 Message-Id: <20210531130654.013624997@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130647.887605866@linuxfoundation.org> References: <20210531130647.887605866@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 @@ -132,6 +132,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 */ @@ -148,6 +151,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); }