Skip to content

Commit 49facff

Browse files
author
Florian Westphal
committed
netfilter: ebtables: split update_counters into two functions
allows to call do_update_counters() from upcoming CONFIG_COMPAT code instead of copy&pasting the same code. Signed-off-by: Florian Westphal <[email protected]>
1 parent 837395a commit 49facff

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

net/bridge/netfilter/ebtables.c

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,38 +1242,33 @@ void ebt_unregister_table(struct net *net, struct ebt_table *table)
12421242
}
12431243

12441244
/* userspace just supplied us with counters */
1245-
static int update_counters(struct net *net, const void __user *user,
1246-
unsigned int len)
1245+
static int do_update_counters(struct net *net, const char *name,
1246+
struct ebt_counter __user *counters,
1247+
unsigned int num_counters,
1248+
const void __user *user, unsigned int len)
12471249
{
12481250
int i, ret;
12491251
struct ebt_counter *tmp;
1250-
struct ebt_replace hlp;
12511252
struct ebt_table *t;
12521253

1253-
if (copy_from_user(&hlp, user, sizeof(hlp)))
1254-
return -EFAULT;
1255-
1256-
if (len != sizeof(hlp) + hlp.num_counters * sizeof(struct ebt_counter))
1257-
return -EINVAL;
1258-
if (hlp.num_counters == 0)
1254+
if (num_counters == 0)
12591255
return -EINVAL;
12601256

1261-
if (!(tmp = vmalloc(hlp.num_counters * sizeof(*tmp))))
1257+
tmp = vmalloc(num_counters * sizeof(*tmp));
1258+
if (!tmp)
12621259
return -ENOMEM;
12631260

1264-
t = find_table_lock(net, hlp.name, &ret, &ebt_mutex);
1261+
t = find_table_lock(net, name, &ret, &ebt_mutex);
12651262
if (!t)
12661263
goto free_tmp;
12671264

1268-
if (hlp.num_counters != t->private->nentries) {
1265+
if (num_counters != t->private->nentries) {
12691266
BUGPRINT("Wrong nr of counters\n");
12701267
ret = -EINVAL;
12711268
goto unlock_mutex;
12721269
}
12731270

1274-
if ( copy_from_user(tmp, hlp.counters,
1275-
hlp.num_counters * sizeof(struct ebt_counter)) ) {
1276-
BUGPRINT("Updata_counters && !cfu\n");
1271+
if (copy_from_user(tmp, counters, num_counters * sizeof(*counters))) {
12771272
ret = -EFAULT;
12781273
goto unlock_mutex;
12791274
}
@@ -1282,7 +1277,7 @@ static int update_counters(struct net *net, const void __user *user,
12821277
write_lock_bh(&t->lock);
12831278

12841279
/* we add to the counters of the first cpu */
1285-
for (i = 0; i < hlp.num_counters; i++) {
1280+
for (i = 0; i < num_counters; i++) {
12861281
t->private->counters[i].pcnt += tmp[i].pcnt;
12871282
t->private->counters[i].bcnt += tmp[i].bcnt;
12881283
}
@@ -1296,6 +1291,21 @@ static int update_counters(struct net *net, const void __user *user,
12961291
return ret;
12971292
}
12981293

1294+
static int update_counters(struct net *net, const void __user *user,
1295+
unsigned int len)
1296+
{
1297+
struct ebt_replace hlp;
1298+
1299+
if (copy_from_user(&hlp, user, sizeof(hlp)))
1300+
return -EFAULT;
1301+
1302+
if (len != sizeof(hlp) + hlp.num_counters * sizeof(struct ebt_counter))
1303+
return -EINVAL;
1304+
1305+
return do_update_counters(net, hlp.name, hlp.counters,
1306+
hlp.num_counters, user, len);
1307+
}
1308+
12991309
static inline int ebt_make_matchname(const struct ebt_entry_match *m,
13001310
const char *base, char __user *ubase)
13011311
{

0 commit comments

Comments
 (0)