• Arnd Bergmann's avatar
    lib/bch: fix possible stack overrun · f0fe77f6
    Arnd Bergmann authored
    The previous patch introduced very large kernel stack usage and a Makefile
    change to hide the warning about it.
    
    From what I can tell, a number of things went wrong here:
    
    - The BCH_MAX_T constant was set to the maximum value for 'n',
      not the maximum for 't', which is much smaller.
    
    - The stack usage is actually larger than the entire kernel stack
      on some architectures that can use 4KB stacks (m68k, sh, c6x), which
      leads to an immediate overrun.
    
    - The justification in the patch description claimed that nothing
      changed, however that is not the case even without the two points above:
      the configuration is machine specific, and most boards  never use the
      maximum BCH_ECC_WORDS() length but instead have something much smaller.
      That maximum would only apply to machines that use both the maximum
      block size and the maximum ECC strength.
    
    The largest value for 't' that I could find is '32', which in turn leads
    to a 60 byte array instead of 2048 bytes. Making it '64' for future
    extension seems also worthwhile, with 120 bytes for the array. Anything
    larger won't fit into the OOB area on NAND flash.
    
    With that changed, the warning can be enabled again.
    
    Only linux-4.19+ contains the breakage, so this is only needed
    as a stable backport if it does not make it into the release.
    
    Fixes: 02361bc7 ("lib/bch: Remove VLA usage")
    Reported-by: 's avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
    Cc: stable@vger.kernel.org
    Signed-off-by: 's avatarArnd Bergmann <arnd@arndb.de>
    Signed-off-by: 's avatarBoris Brezillon <boris.brezillon@bootlin.com>
    f0fe77f6
bch.c 36.1 KB