From: Roopa Prabhu <roopa@cumulusnetworks.com>
To: dsahern@gmail.com, davem@davemloft.net
Cc: netdev@vger.kernel.org, nikolay@cumulusnetworks.com,
jiri@mellanox.com, idosch@mellanox.com, petrm@mellanox.com
Subject: [PATCH net-next 1/6] nexthop: dereference nh only once in nexthop_select_path
Date: Mon, 18 May 2020 19:14:29 -0700 [thread overview]
Message-ID: <1589854474-26854-2-git-send-email-roopa@cumulusnetworks.com> (raw)
In-Reply-To: <1589854474-26854-1-git-send-email-roopa@cumulusnetworks.com>
From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
the ->nh pointer might become suddenly null while we're selecting the
path and we may dereference it. Dereference it only once in the
beginning and use that if it's not null, we rely on the refcounting and
rcu to protect against use-after-free. (This is needed for later
vxlan patches that exposes the problem)
Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
---
net/ipv4/nexthop.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
index 3957364..992e841 100644
--- a/net/ipv4/nexthop.c
+++ b/net/ipv4/nexthop.c
@@ -490,28 +490,33 @@ struct nexthop *nexthop_select_path(struct nexthop *nh, int hash)
nhg = rcu_dereference(nh->nh_grp);
for (i = 0; i < nhg->num_nh; ++i) {
struct nh_grp_entry *nhge = &nhg->nh_entries[i];
+ struct nexthop *nhge_nh;
struct nh_info *nhi;
if (hash > atomic_read(&nhge->upper_bound))
continue;
+ nhge_nh = READ_ONCE(nhge->nh);
+ if (unlikely(!nhge_nh))
+ continue;
+
/* nexthops always check if it is good and does
* not rely on a sysctl for this behavior
*/
- nhi = rcu_dereference(nhge->nh->nh_info);
+ nhi = rcu_dereference(nhge_nh->nh_info);
switch (nhi->family) {
case AF_INET:
if (ipv4_good_nh(&nhi->fib_nh))
- return nhge->nh;
+ return nhge_nh;
break;
case AF_INET6:
if (ipv6_good_nh(&nhi->fib6_nh))
- return nhge->nh;
+ return nhge_nh;
break;
}
if (!rc)
- rc = nhge->nh;
+ rc = nhge_nh;
}
return rc;
--
2.1.4
next prev parent reply other threads:[~2020-05-19 2:14 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-19 2:14 [PATCH net-next 0/6] Support for fdb ECMP nexthop groups Roopa Prabhu
2020-05-19 2:14 ` Roopa Prabhu [this message]
2020-05-19 3:25 ` [PATCH net-next 1/6] nexthop: dereference nh only once in nexthop_select_path David Ahern
2020-05-19 8:48 ` Nikolay Aleksandrov
2020-05-19 10:04 ` Nikolay Aleksandrov
2020-05-19 2:14 ` [PATCH net-next 2/6] nexthop: support for fdb ecmp nexthops Roopa Prabhu
2020-05-19 3:53 ` David Ahern
[not found] ` <CAJieiUjXO6h9HtwTn3fv7W=WovyUxzU2+EZ_Off6kxxRfgyUKQ@mail.gmail.com>
[not found] ` <CAJieiUgHqYo1UZ2VKHK=hTTLZjkScYisdRJ0be0kjtj6c-DRYA@mail.gmail.com>
2020-05-19 17:07 ` David Ahern
2020-05-19 2:14 ` [PATCH net-next 3/6] vxlan: ecmp support for mac fdb entries Roopa Prabhu
2020-05-19 3:57 ` David Ahern
2020-05-19 11:13 ` Nikolay Aleksandrov
2020-05-19 11:28 ` Nikolay Aleksandrov
2020-05-19 12:55 ` kbuild test robot
2020-05-19 13:31 ` kbuild test robot
2020-05-19 2:14 ` [PATCH net-next 4/6] nexthop: add support for notifiers Roopa Prabhu
2020-05-19 2:14 ` [PATCH net-next 5/6] vxlan: support for nexthop notifiers Roopa Prabhu
2020-05-19 2:14 ` [PATCH net-next 6/6] selftests: net: add fdb nexthop tests Roopa Prabhu
2020-05-19 4:00 ` David Ahern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1589854474-26854-2-git-send-email-roopa@cumulusnetworks.com \
--to=roopa@cumulusnetworks.com \
--cc=davem@davemloft.net \
--cc=dsahern@gmail.com \
--cc=idosch@mellanox.com \
--cc=jiri@mellanox.com \
--cc=netdev@vger.kernel.org \
--cc=nikolay@cumulusnetworks.com \
--cc=petrm@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).