From 3e2edf8512d649872e5618fe6efa21814a4f7cb7 Mon Sep 17 00:00:00 2001 From: Muhammad Usama Anjum Date: Tue, 11 May 2021 17:16:54 +0800 Subject: [PATCH] net: ipv6: check for validity before dereferencing cfg->fc_nlinfo.nlh stable inclusion from linux-4.19.187 commit 426853f87e34c9945a655e8997d2f551b12ceb76 -------------------------------- commit 864db232dc7036aa2de19749c3d5be0143b24f8f upstream. nlh is being checked for validtity two times when it is dereferenced in this function. Check for validity again when updating the flags through nlh pointer to make the dereferencing safe. CC: Addresses-Coverity: ("NULL pointer dereference") Signed-off-by: Muhammad Usama Anjum Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman Signed-off-by: Yang Yingliang --- net/ipv6/route.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 800319e34178..1b37aea01a98 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -4525,9 +4525,11 @@ static int ip6_route_multipath_add(struct fib6_config *cfg, * nexthops have been replaced by first new, the rest should * be added to it. */ - cfg->fc_nlinfo.nlh->nlmsg_flags &= ~(NLM_F_EXCL | - NLM_F_REPLACE); - cfg->fc_nlinfo.nlh->nlmsg_flags |= NLM_F_CREATE; + if (cfg->fc_nlinfo.nlh) { + cfg->fc_nlinfo.nlh->nlmsg_flags &= ~(NLM_F_EXCL | + NLM_F_REPLACE); + cfg->fc_nlinfo.nlh->nlmsg_flags |= NLM_F_CREATE; + } nhn++; } -- GitLab