Skip to content

Commit a8fe915

Browse files
dsaherngregkh
authored andcommitted
ipv4: Check attribute length for RTA_GATEWAY in multipath route
commit 7a3429b upstream. syzbot reported uninit-value: ============================================================ BUG: KMSAN: uninit-value in fib_get_nhs+0xac4/0x1f80 net/ipv4/fib_semantics.c:708 fib_get_nhs+0xac4/0x1f80 net/ipv4/fib_semantics.c:708 fib_create_info+0x2411/0x4870 net/ipv4/fib_semantics.c:1453 fib_table_insert+0x45c/0x3a10 net/ipv4/fib_trie.c:1224 inet_rtm_newroute+0x289/0x420 net/ipv4/fib_frontend.c:886 Add helper to validate RTA_GATEWAY length before using the attribute. Fixes: 4e902c5 ("[IPv4]: FIB configuration using struct fib_config") Reported-by: syzbot+d4b9a2851cc3ce998741@syzkaller.appspotmail.com Signed-off-by: David Ahern <dsahern@kernel.org> Cc: Thomas Graf <tgraf@suug.ch> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 786a335 commit a8fe915

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

‎net/ipv4/fib_semantics.c‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,19 @@ static int fib_count_nexthops(struct rtnexthop *rtnh, int remaining,
663663
return nhs;
664664
}
665665

666+
static int fib_gw_from_attr(__be32 *gw, struct nlattr *nla,
667+
struct netlink_ext_ack *extack)
668+
{
669+
if (nla_len(nla) < sizeof(*gw)) {
670+
NL_SET_ERR_MSG(extack, "Invalid IPv4 address in RTA_GATEWAY");
671+
return -EINVAL;
672+
}
673+
674+
*gw = nla_get_in_addr(nla);
675+
676+
return 0;
677+
}
678+
666679
/* only called when fib_nh is integrated into fib_info */
667680
static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
668681
int remaining, struct fib_config *cfg,
@@ -705,7 +718,11 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
705718
return -EINVAL;
706719
}
707720
if (nla) {
708-
fib_cfg.fc_gw4 = nla_get_in_addr(nla);
721+
ret = fib_gw_from_attr(&fib_cfg.fc_gw4, nla,
722+
extack);
723+
if (ret)
724+
goto errout;
725+
709726
if (fib_cfg.fc_gw4)
710727
fib_cfg.fc_gw_family = AF_INET;
711728
} else if (nlav) {
@@ -903,6 +920,7 @@ int fib_nh_match(struct net *net, struct fib_config *cfg, struct fib_info *fi,
903920
attrlen = rtnh_attrlen(rtnh);
904921
if (attrlen > 0) {
905922
struct nlattr *nla, *nlav, *attrs = rtnh_attrs(rtnh);
923+
int err;
906924

907925
nla = nla_find(attrs, attrlen, RTA_GATEWAY);
908926
nlav = nla_find(attrs, attrlen, RTA_VIA);
@@ -913,12 +931,17 @@ int fib_nh_match(struct net *net, struct fib_config *cfg, struct fib_info *fi,
913931
}
914932

915933
if (nla) {
934+
__be32 gw;
935+
936+
err = fib_gw_from_attr(&gw, nla, extack);
937+
if (err)
938+
return err;
939+
916940
if (nh->fib_nh_gw_family != AF_INET ||
917-
nla_get_in_addr(nla) != nh->fib_nh_gw4)
941+
gw != nh->fib_nh_gw4)
918942
return 1;
919943
} else if (nlav) {
920944
struct fib_config cfg2;
921-
int err;
922945

923946
err = fib_gw_from_via(&cfg2, nlav, extack);
924947
if (err)

0 commit comments

Comments
 (0)