fib_trie: Fix shift by 32 in fib_table_lookup

The fib_table_lookup function had a shift by 32 that triggered a UBSAN
warning.  This was due to the fact that I had placed the shift first and
then followed it with the check for the suffix length to ignore the
undefined behavior.  If we reorder this so that we verify the suffix is
less than 32 before shifting the value we can avoid the issue.

Reported-by: Toralf Förster <toralf.foerster@gmx.de>
Signed-off-by: Alexander Duyck <aduyck@mirantis.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Alexander Duyck 2016-01-28 13:42:24 -08:00 коммит произвёл David S. Miller
Родитель 59a557be38
Коммит a5829f536b
1 изменённых файлов: 4 добавлений и 3 удалений

Просмотреть файл

@ -1396,9 +1396,10 @@ found:
struct fib_info *fi = fa->fa_info; struct fib_info *fi = fa->fa_info;
int nhsel, err; int nhsel, err;
if ((index >= (1ul << fa->fa_slen)) && if ((BITS_PER_LONG > KEYLENGTH) || (fa->fa_slen < KEYLENGTH)) {
((BITS_PER_LONG > KEYLENGTH) || (fa->fa_slen != KEYLENGTH))) if (index >= (1ul << fa->fa_slen))
continue; continue;
}
if (fa->fa_tos && fa->fa_tos != flp->flowi4_tos) if (fa->fa_tos && fa->fa_tos != flp->flowi4_tos)
continue; continue;
if (fi->fib_dead) if (fi->fib_dead)