linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: diskonchip: work around ubsan link failure
@ 2024-04-05 14:30 Arnd Bergmann
  2024-04-09  6:41 ` Miquel Raynal
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2024-04-05 14:30 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra
  Cc: Arnd Bergmann, stable, Dinghao Liu, linux-mtd, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

I ran into a randconfig build failure with UBSAN using gcc-13.2:

arm-linux-gnueabi-ld: error: unplaced orphan section `.bss..Lubsan_data31' from `drivers/mtd/nand/raw/diskonchip.o'

I'm not entirely sure what is going on here, but I suspect this has something
to do with the check for the end of the doc_locations[] array that contains
an (unsigned long)0xffffffff element, which is compared against the signed
(int)0xffffffff. If this is the case, we should get a runtime check for
undefined behavior, but we instead get an unexpected build-time error.

I would have expected this to work fine on 32-bit architectures despite the
signed integer overflow, though on 64-bit architectures this likely won't
ever work.

Changing the contition to instead check for the size of the array makes the
code safe everywhere and avoids the ubsan check that leads to the link
error. The loop code goes back to before 2.6.12.

Cc: stable@vger.kernel.org
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/mtd/nand/raw/diskonchip.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/raw/diskonchip.c b/drivers/mtd/nand/raw/diskonchip.c
index 5243fab9face..8db7fc424571 100644
--- a/drivers/mtd/nand/raw/diskonchip.c
+++ b/drivers/mtd/nand/raw/diskonchip.c
@@ -53,7 +53,7 @@ static unsigned long doc_locations[] __initdata = {
 	0xe8000, 0xea000, 0xec000, 0xee000,
 #endif
 #endif
-	0xffffffff };
+};
 
 static struct mtd_info *doclist = NULL;
 
@@ -1554,7 +1554,7 @@ static int __init init_nanddoc(void)
 		if (ret < 0)
 			return ret;
 	} else {
-		for (i = 0; (doc_locations[i] != 0xffffffff); i++) {
+		for (i = 0; i < ARRAY_SIZE(doc_locations); i++) {
 			doc_probe(doc_locations[i]);
 		}
 	}
-- 
2.39.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mtd: diskonchip: work around ubsan link failure
  2024-04-05 14:30 [PATCH] mtd: diskonchip: work around ubsan link failure Arnd Bergmann
@ 2024-04-09  6:41 ` Miquel Raynal
  0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2024-04-09  6:41 UTC (permalink / raw)
  To: Arnd Bergmann, Miquel Raynal, Richard Weinberger, Vignesh Raghavendra
  Cc: Arnd Bergmann, stable, Dinghao Liu, linux-mtd, linux-kernel

On Fri, 2024-04-05 at 14:30:04 UTC, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> I ran into a randconfig build failure with UBSAN using gcc-13.2:
> 
> arm-linux-gnueabi-ld: error: unplaced orphan section `.bss..Lubsan_data31' from `drivers/mtd/nand/raw/diskonchip.o'
> 
> I'm not entirely sure what is going on here, but I suspect this has something
> to do with the check for the end of the doc_locations[] array that contains
> an (unsigned long)0xffffffff element, which is compared against the signed
> (int)0xffffffff. If this is the case, we should get a runtime check for
> undefined behavior, but we instead get an unexpected build-time error.
> 
> I would have expected this to work fine on 32-bit architectures despite the
> signed integer overflow, though on 64-bit architectures this likely won't
> ever work.
> 
> Changing the contition to instead check for the size of the array makes the
> code safe everywhere and avoids the ubsan check that leads to the link
> error. The loop code goes back to before 2.6.12.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/fixes, thanks.

Miquel

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-09  6:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-05 14:30 [PATCH] mtd: diskonchip: work around ubsan link failure Arnd Bergmann
2024-04-09  6:41 ` Miquel Raynal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).