lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 27 Sep 2016 18:23:50 +0800
From:   Liping Zhang <zlpnobody@...il.com>
To:     Vishwanath Pai <vpai@...mai.com>
Cc:     Pablo Neira Ayuso <pablo@...filter.org>,
        Patrick McHardy <kaber@...sh.net>,
        Jozsef Kadlecsik <kadlec@...ckhole.kfki.hu>, johunt@...mai.com,
        Netfilter Developer Mailing List 
        <netfilter-devel@...r.kernel.org>, coreteam@...filter.org,
        Linux Kernel Network Developers <netdev@...r.kernel.org>,
        Vishwanath Pai <pai.vishwain@...il.com>
Subject: Re: [PATCH] Fix link error in 32bit arch because of 64bit division

Hi  Vishwanath Pai,

2016-09-27 15:42 GMT+08:00 Vishwanath Pai <vpai@...mai.com>:
> Fix link error in 32bit arch because of 64bit division

This should be "netfilter: xt_hashlimit: fix ... "

>
> --- a/net/netfilter/xt_hashlimit.c
> +++ b/net/netfilter/xt_hashlimit.c
> @@ -465,19 +465,20 @@ static u64 user2credits(u64 user, int revision)
>  {
>         if (revision == 1) {
>                 /* If multiplying would overflow... */
> -               if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY_v1))
> +               if (user > div64_u64(0xFFFFFFFF, (HZ*CREDITS_PER_JIFFY_v1)))

Here divisor and dividend are all 32-bit integer, so covert "/" to div64_u64
seems unnecessary.

>                         /* Divide first. */
> -                       return (user / XT_HASHLIMIT_SCALE) *\
> +                       return div64_u64(user, XT_HASHLIMIT_SCALE) *\
>                                                 HZ * CREDITS_PER_JIFFY_v1;
>
> -               return (user * HZ * CREDITS_PER_JIFFY_v1) \
> -                                               / XT_HASHLIMIT_SCALE;
> +               return div64_u64((user * HZ * CREDITS_PER_JIFFY_v1),
> +                                 XT_HASHLIMIT_SCALE);
>         } else {
> -               if (user > 0xFFFFFFFFFFFFFFFF / (HZ*CREDITS_PER_JIFFY))
> -                       return (user / XT_HASHLIMIT_SCALE_v2) *\
> +               if (user > div64_u64(0xFFFFFFFFFFFFFFFF, (HZ*CREDITS_PER_JIFFY)))

0xFFFFFFFFFFFFFFFF and "HZ*CREDITS_PER_JIFFY" are both
constant, and GCC will do constant folding optimization, so I think
convert "/" to div64_u64 here is also unnecessary.

> +                       return div64_u64(user, XT_HASHLIMIT_SCALE_v2) *\
>                                                 HZ * CREDITS_PER_JIFFY;
>
> -               return (user * HZ * CREDITS_PER_JIFFY) / XT_HASHLIMIT_SCALE_v2;
> +               return div64_u64((user * HZ * CREDITS_PER_JIFFY),
> +                                XT_HASHLIMIT_SCALE_v2);
>         }
>  }
>

Powered by blists - more mailing lists