From mboxrd@z Thu Jan 1 00:00:00 1970 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=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 2D710C7618B for ; Fri, 26 Jul 2019 15:35:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0378E2054F for ; Fri, 26 Jul 2019 15:35:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564155318; bh=QES9UIyXj5twZIQAprQMZjZfdU3sm00oOsc3BxDN6dY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=k0042cVkW+ycEJBbIzuDTcGvDFBrP53r++3dJTeBUofemhLf6DN6zB77dFQfTjlwA ImQVYTts1Tt921FlspV8cYnOeQ+5xurc+UYFnBGB4Z1w3qrxdG4dPDHYWv7/vs5TnW ackptl2hXz6tKOorA0x8m7EvrBvOLe6YgYiyrgOY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388947AbfGZPdK (ORCPT ); Fri, 26 Jul 2019 11:33:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:48510 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388932AbfGZPdJ (ORCPT ); Fri, 26 Jul 2019 11:33:09 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AA8AB218D4; Fri, 26 Jul 2019 15:33:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564155189; bh=QES9UIyXj5twZIQAprQMZjZfdU3sm00oOsc3BxDN6dY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m8tOPS6Covet+Mi5Qyxg0EqYSqdfFBjz9h/+F6mfSavSCLOb/pOFPR8YCcBc4jN0a 3RrBpbKBF5bEmTXQHAkiWshqztJcbIhgodLQgJJHtnvyy9fW8f6/jNllUxVa+0bIqf x2200i2E7S4WBo6KFFUWVJBrmBGfM/1onCDCQ5Z8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ido Schimmel , Alexander Petrovskiy , David Ahern , "David S. Miller" Subject: [PATCH 4.19 07/50] ipv6: Unlink sibling route in case of failure Date: Fri, 26 Jul 2019 17:24:42 +0200 Message-Id: <20190726152301.419360355@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190726152300.760439618@linuxfoundation.org> References: <20190726152300.760439618@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Ido Schimmel [ Upstream commit 54851aa90cf27041d64b12f65ac72e9f97bd90fd ] When a route needs to be appended to an existing multipath route, fib6_add_rt2node() first appends it to the siblings list and increments the number of sibling routes on each sibling. Later, the function notifies the route via call_fib6_entry_notifiers(). In case the notification is vetoed, the route is not unlinked from the siblings list, which can result in a use-after-free. Fix this by unlinking the route from the siblings list before returning an error. Audited the rest of the call sites from which the FIB notification chain is called and could not find more problems. Fixes: 2233000cba40 ("net/ipv6: Move call_fib6_entry_notifiers up for route adds") Signed-off-by: Ido Schimmel Reported-by: Alexander Petrovskiy Reviewed-by: David Ahern Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv6/ip6_fib.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) --- a/net/ipv6/ip6_fib.c +++ b/net/ipv6/ip6_fib.c @@ -1081,8 +1081,24 @@ add: err = call_fib6_entry_notifiers(info->nl_net, FIB_EVENT_ENTRY_ADD, rt, extack); - if (err) + if (err) { + struct fib6_info *sibling, *next_sibling; + + /* If the route has siblings, then it first + * needs to be unlinked from them. + */ + if (!rt->fib6_nsiblings) + return err; + + list_for_each_entry_safe(sibling, next_sibling, + &rt->fib6_siblings, + fib6_siblings) + sibling->fib6_nsiblings--; + rt->fib6_nsiblings = 0; + list_del_init(&rt->fib6_siblings); + rt6_multipath_rebalance(next_sibling); return err; + } rcu_assign_pointer(rt->fib6_next, iter); atomic_inc(&rt->fib6_ref);