Skip to content

Commit 241eb3f

Browse files
GustavoARSilvaummakynes
authored andcommitted
netfilter: ebtables: use array_size() helper in copy_{from,to}_user()
Use array_size() helper instead of the open-coded version in copy_{from,to}_user(). These sorts of multiplication factors need to be wrapped in array_size(). Link: KSPP/linux#160 Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent ab98bbe commit 241eb3f

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎net/bridge/netfilter/ebtables.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ static int do_replace_finish(struct net *net, struct ebt_replace *repl,
10711071
*/
10721072
if (repl->num_counters &&
10731073
copy_to_user(repl->counters, counterstmp,
1074-
repl->num_counters * sizeof(struct ebt_counter))) {
1074+
array_size(repl->num_counters, sizeof(struct ebt_counter)))) {
10751075
/* Silent error, can't fail, new table is already in place */
10761076
net_warn_ratelimited("ebtables: counters copy to user failed while replacing table\n");
10771077
}
@@ -1399,7 +1399,8 @@ static int do_update_counters(struct net *net, const char *name,
13991399
goto unlock_mutex;
14001400
}
14011401

1402-
if (copy_from_user(tmp, counters, num_counters * sizeof(*counters))) {
1402+
if (copy_from_user(tmp, counters,
1403+
array_size(num_counters, sizeof(*counters)))) {
14031404
ret = -EFAULT;
14041405
goto unlock_mutex;
14051406
}
@@ -1532,7 +1533,7 @@ static int copy_counters_to_user(struct ebt_table *t,
15321533
write_unlock_bh(&t->lock);
15331534

15341535
if (copy_to_user(user, counterstmp,
1535-
nentries * sizeof(struct ebt_counter)))
1536+
array_size(nentries, sizeof(struct ebt_counter))))
15361537
ret = -EFAULT;
15371538
vfree(counterstmp);
15381539
return ret;

0 commit comments

Comments
 (0)