Skip to content

Commit 13e55fb

Browse files
IurmanJPaolo Abeni
authored andcommitted
net: ipv6: fix dst ref loop on input in rpl lwt
Prevent a dst ref loop on input in rpl_iptunnel. Fixes: a7a29f9 ("net: ipv6: add rpl sr tunnel") Cc: Alexander Aring <alex.aring@gmail.com> Cc: Ido Schimmel <idosch@nvidia.com> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Signed-off-by: Justin Iurman <justin.iurman@uliege.be> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent c64a072 commit 13e55fb

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

net/ipv6/rpl_iptunnel.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,18 @@ static int rpl_input(struct sk_buff *skb)
262262
{
263263
struct dst_entry *orig_dst = skb_dst(skb);
264264
struct dst_entry *dst = NULL;
265+
struct lwtunnel_state *lwtst;
265266
struct rpl_lwt *rlwt;
266267
int err;
267268

268-
rlwt = rpl_lwt_lwtunnel(orig_dst->lwtstate);
269+
/* We cannot dereference "orig_dst" once ip6_route_input() or
270+
* skb_dst_drop() is called. However, in order to detect a dst loop, we
271+
* need the address of its lwtstate. So, save the address of lwtstate
272+
* now and use it later as a comparison.
273+
*/
274+
lwtst = orig_dst->lwtstate;
275+
276+
rlwt = rpl_lwt_lwtunnel(lwtst);
269277

270278
local_bh_disable();
271279
dst = dst_cache_get(&rlwt->cache);
@@ -280,7 +288,9 @@ static int rpl_input(struct sk_buff *skb)
280288
if (!dst) {
281289
ip6_route_input(skb);
282290
dst = skb_dst(skb);
283-
if (!dst->error) {
291+
292+
/* cache only if we don't create a dst reference loop */
293+
if (!dst->error && lwtst != dst->lwtstate) {
284294
local_bh_disable();
285295
dst_cache_set_ip6(&rlwt->cache, dst,
286296
&ipv6_hdr(skb)->saddr);

0 commit comments

Comments
 (0)