From patchwork Mon Jan 25 19:59:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chinmay Agarwal X-Patchwork-Id: 12044263 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4513CC433DB for ; Mon, 25 Jan 2021 20:05:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1BD8222597 for ; Mon, 25 Jan 2021 20:05:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732013AbhAYUFk (ORCPT ); Mon, 25 Jan 2021 15:05:40 -0500 Received: from a1.mail.mailgun.net ([198.61.254.60]:27141 "EHLO a1.mail.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732293AbhAYUAp (ORCPT ); Mon, 25 Jan 2021 15:00:45 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1611604821; h=Content-Type: MIME-Version: Message-ID: Subject: Cc: To: From: Date: Sender; bh=Gud41NJ96Erxd4slcT3VGJ5GJsjYT1kgQCvNOvQB01w=; b=FnnzY0iqpkROqjkLz5KRDz7cCB8UoX4exS77a03L2wbRYFzOmv3cDLNEG/aWt6OKMAfQX16O CW6OHEqFZwV8mI9s/gCOobfspaPVzm9k7pqdvPCvzF9TOwnBpfJgTlzUBgRdFY/qEY8N6AZJ pIVN86RVqo6emakseH92VIb4ZEk= X-Mailgun-Sending-Ip: 198.61.254.60 X-Mailgun-Sid: WyJiZjI2MiIsICJuZXRkZXZAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n01.prod.us-west-2.postgun.com with SMTP id 600f2333ad4c9e395b6fdd80 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Mon, 25 Jan 2021 19:59:47 GMT Sender: chinagar=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id A4187C43462; Mon, 25 Jan 2021 19:59:47 +0000 (UTC) Received: from chinagar-linux.qualcomm.com (unknown [202.46.22.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: chinagar) by smtp.codeaurora.org (Postfix) with ESMTPSA id AA4CCC43461; Mon, 25 Jan 2021 19:59:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org AA4CCC43461 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=chinagar@codeaurora.org Date: Tue, 26 Jan 2021 01:29:37 +0530 From: Chinmay Agarwal To: netdev@vger.kernel.org Cc: xiyou.wangcong@gmail.com, sharathv@codeaurora.org Subject: [PATCH] neighbour: Prevent a dead entry from updating gc_list Message-ID: <20210125195927.GA26972@chinagar-linux.qualcomm.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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. Signed-off-by: Chinmay Agarwal --- net/core/neighbour.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) -- diff --git a/net/core/neighbour.c b/net/core/neighbour.c index ff07358..cf8e3076 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -1244,13 +1244,14 @@ static int __neigh_update(struct neighbour *neigh, const u8 *lladdr, 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);