]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
lib/bch: fix signed shift overflow in build_mod8_tables
authorJosh Law <objecting@objecting.org>
Wed, 18 Mar 2026 07:48:06 +0000 (07:48 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 28 Mar 2026 04:19:48 +0000 (21:19 -0700)
Cast loop variable to unsigned int before left-shifting to avoid undefined
behavior when i >= 128 and b == 3 (i << 24 overflows signed int).

Link: https://lkml.kernel.org/r/20260318074806.16527-3-objecting@objecting.org
Signed-off-by: Josh Law <objecting@objecting.org>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Ivan Djelic <ivan.djelic@parrot.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
lib/bch.c

index ef733f08082f7b684566a8c1b848163d08ae917b..c991c71c4cbdfbd0322491646579270de3f561f1 100644 (file)
--- a/lib/bch.c
+++ b/lib/bch.c
@@ -1116,7 +1116,7 @@ static void build_mod8_tables(struct bch_control *bch, const uint32_t *g)
                for (b = 0; b < 4; b++) {
                        /* we want to compute (p(X).X^(8*b+deg(g))) mod g(X) */
                        tab = bch->mod8_tab + (b*256+i)*l;
-                       data = i << (8*b);
+                       data = (unsigned int)i << (8*b);
                        while (data) {
                                d = deg(data);
                                /* subtract X^d.g(X) from p(X).X^(8*b+deg(g)) */