Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp216610ybi; Fri, 26 Jul 2019 08:36:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqxafDT7wjsIlegWsH00iBRw9g5/r5OUKdFEvGvWRSSKyKjIt/JvjeDc/73hOw9X5xjkq3LF X-Received: by 2002:a17:902:9a49:: with SMTP id x9mr97666764plv.282.1564155400919; Fri, 26 Jul 2019 08:36:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564155400; cv=none; d=google.com; s=arc-20160816; b=g3Fokn4rdnwOjno9pkYwtFaYFC3oKkHW9rD07urRFcBBjw9YQPXtR2272qrOQ37MIi Tsmmzb+oYGTis/nDZK/RHNMptCO1+N836TndvlDmorBmVczq3IfqhC+ttBWsJwfI+2Ki ipNX+FQ+8bm/TXEc2Bm1eKjHlJnjFbG8TOUUkV+jREgoyHNzw6O/nlXpvyTKDc53hWvZ yRzOk9DpVSv/jGf8rs/qdFxMsBNOGxdjeevTA3/4flAUOJjBQ2vE/y0ffLvLKsqdBKjl zsaDGjztM+YA8BVU6jQBlDbKhBq0MiKadNlbOKfAl2I21J2RihzyRbhbZJUFnToFXAzO NG5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bwcV/TrF9m9f5OKd89gzQT0uLhRzrrPdLJS0IRYjctY=; b=ftGn27jR9DtCPjFG0jpx2SUfKUsQDwpxdSrPwEmUuI8U87h02ROl6IbJsllJqCSOA+ UqyiKQceNx47afjhTqRGZmNLivy99bqdebO/qzOTE7LqO4/ds57iViN5s5Iqx8nz4wh/ wX0anZIJmmil7xnavssjgPm53i23A59tH7i4sJ/ac1UnFzGsJHqoWQxje8VTOvD3yHaH DqOkF3xGPHHohtodiJrcRVPcldSMEaEuutrBqU3ao97dNnW/tUyd+Go6k+t2GG5Fmnpo qaXfdCYkamNypNB+Qmt5Eal+7bl4cGh9fZjappE3fRV+OvAmMJwaMlucBGSmk0AmDVW7 eRAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=m8tOPS6C; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q23si21133713pfc.179.2019.07.26.08.36.26; Fri, 26 Jul 2019 08:36:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=m8tOPS6C; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389603AbfGZPdN (ORCPT + 99 others); Fri, 26 Jul 2019 11:33:13 -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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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);