Skip to content

Commit a291ab2

Browse files
committed
Merge tag 'mtd/fixes-for-4.19-rc8' of git://git.infradead.org/linux-mtd
Boris writes: "mdt: fix for 4.19-rc8 * Fix a stack overflow in lib/bch.c" * tag 'mtd/fixes-for-4.19-rc8' of git://git.infradead.org/linux-mtd: lib/bch: fix possible stack overrun
2 parents 62d2e53 + f0fe77f commit a291ab2

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ obj-$(CONFIG_ZLIB_INFLATE) += zlib_inflate/
119119
obj-$(CONFIG_ZLIB_DEFLATE) += zlib_deflate/
120120
obj-$(CONFIG_REED_SOLOMON) += reed_solomon/
121121
obj-$(CONFIG_BCH) += bch.o
122-
CFLAGS_bch.o := $(call cc-option,-Wframe-larger-than=4500)
123122
obj-$(CONFIG_LZO_COMPRESS) += lzo/
124123
obj-$(CONFIG_LZO_DECOMPRESS) += lzo/
125124
obj-$(CONFIG_LZ4_COMPRESS) += lz4/

lib/bch.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,19 @@
7979
#define GF_T(_p) (CONFIG_BCH_CONST_T)
8080
#define GF_N(_p) ((1 << (CONFIG_BCH_CONST_M))-1)
8181
#define BCH_MAX_M (CONFIG_BCH_CONST_M)
82+
#define BCH_MAX_T (CONFIG_BCH_CONST_T)
8283
#else
8384
#define GF_M(_p) ((_p)->m)
8485
#define GF_T(_p) ((_p)->t)
8586
#define GF_N(_p) ((_p)->n)
86-
#define BCH_MAX_M 15
87+
#define BCH_MAX_M 15 /* 2KB */
88+
#define BCH_MAX_T 64 /* 64 bit correction */
8789
#endif
8890

89-
#define BCH_MAX_T (((1 << BCH_MAX_M) - 1) / BCH_MAX_M)
90-
9191
#define BCH_ECC_WORDS(_p) DIV_ROUND_UP(GF_M(_p)*GF_T(_p), 32)
9292
#define BCH_ECC_BYTES(_p) DIV_ROUND_UP(GF_M(_p)*GF_T(_p), 8)
9393

9494
#define BCH_ECC_MAX_WORDS DIV_ROUND_UP(BCH_MAX_M * BCH_MAX_T, 32)
95-
#define BCH_ECC_MAX_BYTES DIV_ROUND_UP(BCH_MAX_M * BCH_MAX_T, 8)
9695

9796
#ifndef dbg
9897
#define dbg(_fmt, args...) do {} while (0)
@@ -202,6 +201,9 @@ void encode_bch(struct bch_control *bch, const uint8_t *data,
202201
const uint32_t * const tab3 = tab2 + 256*(l+1);
203202
const uint32_t *pdata, *p0, *p1, *p2, *p3;
204203

204+
if (WARN_ON(r_bytes > sizeof(r)))
205+
return;
206+
205207
if (ecc) {
206208
/* load ecc parity bytes into internal 32-bit buffer */
207209
load_ecc8(bch, bch->ecc_buf, ecc);
@@ -1285,6 +1287,13 @@ struct bch_control *init_bch(int m, int t, unsigned int prim_poly)
12851287
*/
12861288
goto fail;
12871289

1290+
if (t > BCH_MAX_T)
1291+
/*
1292+
* we can support larger than 64 bits if necessary, at the
1293+
* cost of higher stack usage.
1294+
*/
1295+
goto fail;
1296+
12881297
/* sanity checks */
12891298
if ((t < 1) || (m*t >= ((1 << m)-1)))
12901299
/* invalid t value */

0 commit comments

Comments
 (0)