netfilter: compat: prepare xt_compat_init_offsets to return errors
authorFlorian Westphal <fw@strlen.de>
Tue, 27 Feb 2018 18:42:34 +0000 (19:42 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 26 Apr 2018 09:02:21 +0000 (11:02 +0200)
commit 9782a11efc072faaf91d4aa60e9d23553f918029 upstream.

should have no impact, function still always returns 0.
This patch is only to ease review.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/linux/netfilter/x_tables.h
net/bridge/netfilter/ebtables.c
net/ipv4/netfilter/arp_tables.c
net/ipv4/netfilter/ip_tables.c
net/ipv6/netfilter/ip6_tables.c
net/netfilter/x_tables.c

index 56c4ed8c91b8ef30b1242b749a913b9160f80629..54f346a45cd0aa57a9502919dfa92709a66ec1c6 100644 (file)
@@ -508,7 +508,7 @@ void xt_compat_unlock(u_int8_t af);
 
 int xt_compat_add_offset(u_int8_t af, unsigned int offset, int delta);
 void xt_compat_flush_offsets(u_int8_t af);
-void xt_compat_init_offsets(u_int8_t af, unsigned int number);
+int xt_compat_init_offsets(u8 af, unsigned int number);
 int xt_compat_calc_jump(u_int8_t af, unsigned int offset);
 
 int xt_compat_match_offset(const struct xt_match *match);
index 16eb99458df40667df3f180b98fc979eac38b4e7..014a73b46064c041d5173c760b2bd51177b7e82a 100644 (file)
@@ -1819,10 +1819,14 @@ static int compat_table_info(const struct ebt_table_info *info,
 {
        unsigned int size = info->entries_size;
        const void *entries = info->entries;
+       int ret;
 
        newinfo->entries_size = size;
 
-       xt_compat_init_offsets(NFPROTO_BRIDGE, info->nentries);
+       ret = xt_compat_init_offsets(NFPROTO_BRIDGE, info->nentries);
+       if (ret)
+               return ret;
+
        return EBT_ENTRY_ITERATE(entries, size, compat_calc_entry, info,
                                                        entries, newinfo);
 }
@@ -2257,7 +2261,9 @@ static int compat_do_replace(struct net *net, void __user *user,
 
        xt_compat_lock(NFPROTO_BRIDGE);
 
-       xt_compat_init_offsets(NFPROTO_BRIDGE, tmp.nentries);
+       ret = xt_compat_init_offsets(NFPROTO_BRIDGE, tmp.nentries);
+       if (ret < 0)
+               goto out_unlock;
        ret = compat_copy_entries(entries_tmp, tmp.entries_size, &state);
        if (ret < 0)
                goto out_unlock;
index e77ee449831c88c403f595e3ec01762de917e855..356ae7da4f1634e42e2c0b57c08d9d5770bb36d1 100644 (file)
@@ -768,7 +768,9 @@ static int compat_table_info(const struct xt_table_info *info,
        memcpy(newinfo, info, offsetof(struct xt_table_info, entries));
        newinfo->initial_entries = 0;
        loc_cpu_entry = info->entries;
-       xt_compat_init_offsets(NFPROTO_ARP, info->number);
+       ret = xt_compat_init_offsets(NFPROTO_ARP, info->number);
+       if (ret)
+               return ret;
        xt_entry_foreach(iter, loc_cpu_entry, info->size) {
                ret = compat_calc_entry(iter, info, loc_cpu_entry, newinfo);
                if (ret != 0)
@@ -1157,7 +1159,7 @@ static int translate_compat_table(struct xt_table_info **pinfo,
        struct compat_arpt_entry *iter0;
        struct arpt_replace repl;
        unsigned int size;
-       int ret = 0;
+       int ret;
 
        info = *pinfo;
        entry0 = *pentry0;
@@ -1166,7 +1168,9 @@ static int translate_compat_table(struct xt_table_info **pinfo,
 
        j = 0;
        xt_compat_lock(NFPROTO_ARP);
-       xt_compat_init_offsets(NFPROTO_ARP, compatr->num_entries);
+       ret = xt_compat_init_offsets(NFPROTO_ARP, compatr->num_entries);
+       if (ret)
+               goto out_unlock;
        /* Walk through entries, checking offsets. */
        xt_entry_foreach(iter0, entry0, compatr->size) {
                ret = check_compat_entry_size_and_hooks(iter0, info, &size,
index a7a3f1d66d0ae93907e9d1594d803287a1a92df9..1a925f2394ad3394b4b7b4408f0b9a7066a00960 100644 (file)
@@ -931,7 +931,9 @@ static int compat_table_info(const struct xt_table_info *info,
        memcpy(newinfo, info, offsetof(struct xt_table_info, entries));
        newinfo->initial_entries = 0;
        loc_cpu_entry = info->entries;
-       xt_compat_init_offsets(AF_INET, info->number);
+       ret = xt_compat_init_offsets(AF_INET, info->number);
+       if (ret)
+               return ret;
        xt_entry_foreach(iter, loc_cpu_entry, info->size) {
                ret = compat_calc_entry(iter, info, loc_cpu_entry, newinfo);
                if (ret != 0)
@@ -1407,7 +1409,9 @@ translate_compat_table(struct net *net,
 
        j = 0;
        xt_compat_lock(AF_INET);
-       xt_compat_init_offsets(AF_INET, compatr->num_entries);
+       ret = xt_compat_init_offsets(AF_INET, compatr->num_entries);
+       if (ret)
+               goto out_unlock;
        /* Walk through entries, checking offsets. */
        xt_entry_foreach(iter0, entry0, compatr->size) {
                ret = check_compat_entry_size_and_hooks(iter0, info, &size,
index fad6b384836d34f98f53552ee0b661b38df17109..c5fe42e6b7f7a78ab7767ffbe101adb360c315ee 100644 (file)
@@ -949,7 +949,9 @@ static int compat_table_info(const struct xt_table_info *info,
        memcpy(newinfo, info, offsetof(struct xt_table_info, entries));
        newinfo->initial_entries = 0;
        loc_cpu_entry = info->entries;
-       xt_compat_init_offsets(AF_INET6, info->number);
+       ret = xt_compat_init_offsets(AF_INET6, info->number);
+       if (ret)
+               return ret;
        xt_entry_foreach(iter, loc_cpu_entry, info->size) {
                ret = compat_calc_entry(iter, info, loc_cpu_entry, newinfo);
                if (ret != 0)
@@ -1415,7 +1417,7 @@ translate_compat_table(struct net *net,
        struct compat_ip6t_entry *iter0;
        struct ip6t_replace repl;
        unsigned int size;
-       int ret = 0;
+       int ret;
 
        info = *pinfo;
        entry0 = *pentry0;
@@ -1424,7 +1426,9 @@ translate_compat_table(struct net *net,
 
        j = 0;
        xt_compat_lock(AF_INET6);
-       xt_compat_init_offsets(AF_INET6, compatr->num_entries);
+       ret = xt_compat_init_offsets(AF_INET6, compatr->num_entries);
+       if (ret)
+               goto out_unlock;
        /* Walk through entries, checking offsets. */
        xt_entry_foreach(iter0, entry0, compatr->size) {
                ret = check_compat_entry_size_and_hooks(iter0, info, &size,
index 9c38627e09eab99f7eba04b6e1be90db99eebe46..7ad3d861cb83aaf4c1e1888f412289a482f42dd6 100644 (file)
@@ -605,10 +605,12 @@ int xt_compat_calc_jump(u_int8_t af, unsigned int offset)
 }
 EXPORT_SYMBOL_GPL(xt_compat_calc_jump);
 
-void xt_compat_init_offsets(u_int8_t af, unsigned int number)
+int xt_compat_init_offsets(u8 af, unsigned int number)
 {
        xt[af].number = number;
        xt[af].cur = 0;
+
+       return 0;
 }
 EXPORT_SYMBOL(xt_compat_init_offsets);