Skip to content

Commit 92b4423

Browse files
committed
netfilter: fix IS_ERR_VALUE usage
This is a forward-port of the original patch from Andrzej Hajda, he said: "IS_ERR_VALUE should be used only with unsigned long type. Otherwise it can work incorrectly. To achieve this function xt_percpu_counter_alloc is modified to return unsigned long, and its result is assigned to temporary variable to perform error checking, before assigning to .pcnt field. The patch follows conclusion from discussion on LKML [1][2]. [1]: http://permalink.gmane.org/gmane.linux.kernel/2120927 [2]: http://permalink.gmane.org/gmane.linux.kernel/2150581" Original patch from Andrzej is here: http://patchwork.ozlabs.org/patch/582970/ This patch has clashed with input validation fixes for x_tables. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 6cd54fc commit 92b4423

4 files changed

Lines changed: 15 additions & 9 deletions

File tree

‎include/linux/netfilter/x_tables.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,16 +380,16 @@ static inline unsigned long ifname_compare_aligned(const char *_a,
380380
* allows us to return 0 for single core systems without forcing
381381
* callers to deal with SMP vs. NONSMP issues.
382382
*/
383-
static inline u64 xt_percpu_counter_alloc(void)
383+
static inline unsigned long xt_percpu_counter_alloc(void)
384384
{
385385
if (nr_cpu_ids > 1) {
386386
void __percpu *res = __alloc_percpu(sizeof(struct xt_counters),
387387
sizeof(struct xt_counters));
388388

389389
if (res == NULL)
390-
return (u64) -ENOMEM;
390+
return -ENOMEM;
391391

392-
return (u64) (__force unsigned long) res;
392+
return (__force unsigned long) res;
393393
}
394394

395395
return 0;

‎net/ipv4/netfilter/arp_tables.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,11 +513,13 @@ find_check_entry(struct arpt_entry *e, const char *name, unsigned int size)
513513
{
514514
struct xt_entry_target *t;
515515
struct xt_target *target;
516+
unsigned long pcnt;
516517
int ret;
517518

518-
e->counters.pcnt = xt_percpu_counter_alloc();
519-
if (IS_ERR_VALUE(e->counters.pcnt))
519+
pcnt = xt_percpu_counter_alloc();
520+
if (IS_ERR_VALUE(pcnt))
520521
return -ENOMEM;
522+
e->counters.pcnt = pcnt;
521523

522524
t = arpt_get_target(e);
523525
target = xt_request_find_target(NFPROTO_ARP, t->u.user.name,

‎net/ipv4/netfilter/ip_tables.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,10 +656,12 @@ find_check_entry(struct ipt_entry *e, struct net *net, const char *name,
656656
unsigned int j;
657657
struct xt_mtchk_param mtpar;
658658
struct xt_entry_match *ematch;
659+
unsigned long pcnt;
659660

660-
e->counters.pcnt = xt_percpu_counter_alloc();
661-
if (IS_ERR_VALUE(e->counters.pcnt))
661+
pcnt = xt_percpu_counter_alloc();
662+
if (IS_ERR_VALUE(pcnt))
662663
return -ENOMEM;
664+
e->counters.pcnt = pcnt;
663665

664666
j = 0;
665667
mtpar.net = net;

‎net/ipv6/netfilter/ip6_tables.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,10 +669,12 @@ find_check_entry(struct ip6t_entry *e, struct net *net, const char *name,
669669
unsigned int j;
670670
struct xt_mtchk_param mtpar;
671671
struct xt_entry_match *ematch;
672+
unsigned long pcnt;
672673

673-
e->counters.pcnt = xt_percpu_counter_alloc();
674-
if (IS_ERR_VALUE(e->counters.pcnt))
674+
pcnt = xt_percpu_counter_alloc();
675+
if (IS_ERR_VALUE(pcnt))
675676
return -ENOMEM;
677+
e->counters.pcnt = pcnt;
676678

677679
j = 0;
678680
mtpar.net = net;

0 commit comments

Comments
 (0)