From patchwork Sat Jul 9 09:00:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Anastasov X-Patchwork-Id: 646638 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3rmlhW44SSz9sdn for ; Sat, 9 Jul 2016 19:01:15 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933100AbcGIJBJ (ORCPT ); Sat, 9 Jul 2016 05:01:09 -0400 Received: from ja.ssi.bg ([178.16.129.10]:39904 "EHLO ja.ssi.bg" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S932860AbcGIJBF (ORCPT ); Sat, 9 Jul 2016 05:01:05 -0400 Received: from ja.home.ssi.bg (localhost.localdomain [127.0.0.1]) by ja.ssi.bg (8.14.8/8.14.8) with ESMTP id u6990j9m024797; Sat, 9 Jul 2016 12:00:45 +0300 Received: (from root@localhost) by ja.home.ssi.bg (8.14.8/8.14.8/Submit) id u6990hPH024796; Sat, 9 Jul 2016 12:00:43 +0300 From: Julian Anastasov To: David Miller Cc: netdev@vger.kernel.org, Vegard Nossum , Andy Gospodarek , Dinesh Dutt , Scott Feldman Subject: [PATCH net] ipv4: reject RTNH_F_LINKDOWN for incompatible routes Date: Sat, 9 Jul 2016 12:00:15 +0300 Message-Id: <1468054815-24766-1-git-send-email-ja@ssi.bg> X-Mailer: git-send-email 1.9.3 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Vegard Nossum is reporting for a crash in fib_dump_info (fib_nhs==1) when nh_dev = NULL. Problem happens when RTNH_F_LINKDOWN is provided from user space for routes that do not use the flag, catched with netlink fuzzer. RTNH_F_LINKDOWN should be used only for link routes, not for local routes or for routes with error code. Do not complicate fast path with more checks, reject the flag early when configured for incompatible routes. Reported-by: Vegard Nossum Fixes: 0eeb075fad73 ("net: ipv4 sysctl option to ignore routes when nexthop link is down") Tested-by: Vegard Nossum Signed-off-by: Julian Anastasov Cc: Andy Gospodarek Cc: Dinesh Dutt Cc: Scott Feldman --- net/ipv4/fib_semantics.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) Note: works for all kernels: net, net-next, 4.4.14, 4.5.7, 4.6.3 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index d09173b..b642479 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -1113,7 +1113,8 @@ struct fib_info *fib_create_info(struct fib_config *cfg) } if (fib_props[cfg->fc_type].error) { - if (cfg->fc_gw || cfg->fc_oif || cfg->fc_mp) + if (cfg->fc_gw || cfg->fc_oif || cfg->fc_mp || + (fi->fib_nh->nh_flags & RTNH_F_LINKDOWN)) goto err_inval; goto link_it; } else { @@ -1136,7 +1137,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg) struct fib_nh *nh = fi->fib_nh; /* Local address is added. */ - if (nhs != 1 || nh->nh_gw) + if (nhs != 1 || nh->nh_gw || (nh->nh_flags & RTNH_F_LINKDOWN)) goto err_inval; nh->nh_scope = RT_SCOPE_NOWHERE; nh->nh_dev = dev_get_by_index(net, fi->fib_nh->nh_oif);