public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* Patch "ipv4: fix NULL dereference in free_fib_info_rcu()" has been added to the 4.9-stable tree
@ 2017-08-25  0:45 gregkh
  0 siblings, 0 replies; only message in thread
From: gregkh @ 2017-08-25  0:45 UTC (permalink / raw)
  To: edumazet, davem, dvyukov, gregkh; +Cc: stable, stable-commits


This is a note to let you know that I've just added the patch titled

    ipv4: fix NULL dereference in free_fib_info_rcu()

to the 4.9-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     ipv4-fix-null-dereference-in-free_fib_info_rcu.patch
and it can be found in the queue-4.9 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@vger.kernel.org> know about it.


>From foo@baz Thu Aug 24 17:44:02 PDT 2017
From: Eric Dumazet <edumazet@google.com>
Date: Tue, 15 Aug 2017 05:26:17 -0700
Subject: ipv4: fix NULL dereference in free_fib_info_rcu()

From: Eric Dumazet <edumazet@google.com>


[ Upstream commit 187e5b3ac84d3421d2de3aca949b2791fbcad554 ]

If fi->fib_metrics could not be allocated in fib_create_info()
we attempt to dereference a NULL pointer in free_fib_info_rcu() :

    m = fi->fib_metrics;
    if (m != &dst_default_metrics && atomic_dec_and_test(&m->refcnt))
            kfree(m);

Before my recent patch, we used to call kfree(NULL) and nothing wrong
happened.

Instead of using RCU to defer freeing while we are under memory stress,
it seems better to take immediate action.

This was reported by syzkaller team.

Fixes: 3fb07daff8e9 ("ipv4: add reference counting to metrics")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 net/ipv4/fib_semantics.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -1044,15 +1044,17 @@ struct fib_info *fib_create_info(struct
 	fi = kzalloc(sizeof(*fi)+nhs*sizeof(struct fib_nh), GFP_KERNEL);
 	if (!fi)
 		goto failure;
-	fib_info_cnt++;
 	if (cfg->fc_mx) {
 		fi->fib_metrics = kzalloc(sizeof(*fi->fib_metrics), GFP_KERNEL);
-		if (!fi->fib_metrics)
-			goto failure;
+		if (unlikely(!fi->fib_metrics)) {
+			kfree(fi);
+			return ERR_PTR(err);
+		}
 		atomic_set(&fi->fib_metrics->refcnt, 1);
-	} else
+	} else {
 		fi->fib_metrics = (struct dst_metrics *)&dst_default_metrics;
-
+	}
+	fib_info_cnt++;
 	fi->fib_net = net;
 	fi->fib_protocol = cfg->fc_protocol;
 	fi->fib_scope = cfg->fc_scope;


Patches currently in stable-queue which might be from edumazet@google.com are

queue-4.9/ipv4-fix-null-dereference-in-free_fib_info_rcu.patch
queue-4.9/tcp-when-rearming-rto-if-rto-time-is-in-past-then-fire-rto-asap.patch
queue-4.9/ipv4-better-ip_max_mtu-enforcement.patch
queue-4.9/dccp-defer-ccid_hc_tx_delete-at-dismantle-time.patch
queue-4.9/tipc-fix-use-after-free.patch
queue-4.9/af_key-do-not-use-gfp_kernel-in-atomic-contexts.patch
queue-4.9/ipv6-repair-fib6-tree-in-failure-case.patch
queue-4.9/dccp-purge-write-queue-in-dccp_destroy_sock.patch
queue-4.9/ipv6-reset-fn-rr_ptr-when-replacing-route.patch
queue-4.9/ptr_ring-use-kmalloc_array.patch
queue-4.9/net_sched-sfq-update-hierarchical-backlog-when-drop-packet.patch

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-08-25  0:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-25  0:45 Patch "ipv4: fix NULL dereference in free_fib_info_rcu()" has been added to the 4.9-stable tree gregkh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox