Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2684478pxj; Mon, 31 May 2021 08:12:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmr6V/2YozPC5toOwhWBCAg9oTZkJhY8zyrtYbPOEWLniYEwU+MTUqvrVc3qqnWzZJn5yt X-Received: by 2002:a17:906:d0da:: with SMTP id bq26mr11412568ejb.287.1622473941845; Mon, 31 May 2021 08:12:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622473941; cv=none; d=google.com; s=arc-20160816; b=bq/m7tK64MIlrnToXaYrx6AIQ4b8UL581h585KOxCkqypRCPON69Y/GQhZidCD5c0f MyCEpATGQrlM21WrMg/MJSTamAOLLgZB9FpkRaHzXBxuWe8To5iatTquGtMFbhozvPJO xcCyTStZr4zxpvPrfekom5EYIK8umPUPRs28VGTwun4JLFxa6W75Em2IjLcl+OA2Hj5m 4zv7x6YbKeDdFkufDIGOJaCRCKf2WtSV7084059TNDdR2g6uhKfRxh7nlK9kAVH8cKZh hYAwC7Jg/X5idk2+7wv/Qd7IhrjbllgBHHkSSBVQL6KTEcf6EdgP7Z0LVy6HDJIcec2G T+Zw== 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=DNSxFK1GML4e5J3FT3pJDP4xXb9kSWgXskXz08YwBk9j5C+gyalCrR0h8jHHw4LgJs kp+UGWOSEgsr+1nPhwrFUuUse5Au9PtFP63lhaOdxMtL1K7eJlN8HRUMIJDZ2SeQQnHe B4jv2uHdG0GeIpJDwRGL0bqnIzuZhkye2Y0LslknKgIJ9Q511GsDgu5mefHnhxCdPDz6 czDLnaHE9jhNqDBFPaKifv3SOcmsXTporJe0qp7uxBsmP312bsyFQGyTdeiYe/5va/lF qKn84TJD3eD67I2MTOcFtGp3H6OB9ZpTBBIYKwEktfzTuj+Y8PBBkFYWg78X5hbKh7V7 I4tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MsAVt+4c; 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 a1si192102eje.497.2021.05.31.08.11.58; Mon, 31 May 2021 08:12:21 -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=MsAVt+4c; 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 S233734AbhEaPMe (ORCPT + 99 others); Mon, 31 May 2021 11:12:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:40090 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233088AbhEaOLH (ORCPT ); Mon, 31 May 2021 10:11:07 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1239860FEF; Mon, 31 May 2021 13:41:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468462; bh=95C73nfouQFTJ+QBHIZMzTYe7qD618sSkUDJj+FuyCc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MsAVt+4cRh+zZ8cbJ1Lit+Btr8GwdBDTz8m6omoo34nB4P9cfwU+1ws5ODZe+AIPB VDvPWHm9ERmYNjBc/Cz/kJo4iNjtezbN7uznWDHSp+cSlDREhOiJMRkG4aYx7PbbZw bNVuwQtMSJiiihjMqtZzHztIYdDR0oP+rpby2KDk= 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.10 251/252] neighbour: Prevent Race condition in neighbour subsytem Date: Mon, 31 May 2021 15:15:16 +0200 Message-Id: <20210531130706.514801757@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@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); }