]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: ipv6: check for validity before dereferencing cfg->fc_nlinfo.nlh
authorMuhammad Usama Anjum <musamaanjum@gmail.com>
Thu, 8 Apr 2021 22:01:29 +0000 (03:01 +0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 16 Apr 2021 10:00:20 +0000 (12:00 +0200)
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: <stable@vger.kernel.org>
Addresses-Coverity: ("NULL pointer dereference")
Signed-off-by: Muhammad Usama Anjum <musamaanjum@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/ipv6/route.c

index 50eba77f5a0d2b650a7e56ab82b25b84f99f3f70..f06a7687874600ed0697d4d4ef0be9b27c108c5c 100644 (file)
@@ -2980,9 +2980,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++;
        }