Skip to contentSkip to conversation

lib: fix bitmap_parse() on 64-bit big endian archs

PATCH Applied Alexander Gordeev 2 participants 2 messages Jun 8, 2020 – Jun 9, 2020

Subsystems (4)
lore
Share & tools
lore

Alexander Gordeev

author maintainer
#0 lore raw

PATCH v2 1/1 lib: fix bitmap_parse() on 64-bit big endian archs

Commit 2d6261583be0 ("lib: rework bitmap_parse()") does not take into account order of halfwords on 64-bit big endian architectures. As result (at least) Receive Packet Steering, IRQ affinity masks and runtime kernel test "test_bitmap" get broken on s390.

Fixes 2d6261583be0 ("lib: rework bitmap_parse()")
Cc Andrew Morton <[email protected]>
Cc Yury Norov <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Amritha Nambiar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Chris Wilson <[email protected]>
Cc Kees Cook <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Miklos Szeredi <[email protected]>
Cc Rasmus Villemoes <[email protected]>
Cc Steffen Klassert <[email protected]>
Cc "Tobin C . Harding" <[email protected]>
Cc Vineet Gupta <[email protected]>
Cc Will Deacon <[email protected]>
Cc Willem de Bruijn <[email protected]>
---
 lib/bitmap.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
lib/bitmap.c +7 -1
index 89260aa342d6..80d26b183248 100644
@@ -739,6 +739,7 @@ int bitmap_parse(const char *start, unsigned int buflen,
 	const char *end = strnchrnul(start, buflen, '\n') - 1;
 	int chunks = BITS_TO_U32(nmaskbits);
 	u32 *bitmap = (u32 *)maskp;
+	int chunk = 0;
 	int unset_bit;
 
 	while (1) {
@@ -749,9 +750,14 @@ int bitmap_parse(const char *start, unsigned int buflen,
 		if (!chunks--)
 			return -EOVERFLOW;
 
-		end = bitmap_get_x32_reverse(start, end, bitmap++);
+#if defined(CONFIG_64BIT) && defined(__BIG_ENDIAN)
+		end = bitmap_get_x32_reverse(start, end, &bitmap[chunk ^ 1]);
+#else
+		end = bitmap_get_x32_reverse(start, end, &bitmap[chunk]);
+#endif
 		if (IS_ERR(end))
 			return PTR_ERR(end);
+		chunk++;
 	}
 
 	unset_bit = (BITS_TO_U32(nmaskbits) - chunks) * 32;
Signature · 1 line
2.23.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 lines · Alexander Gordeev

Commit 2d6261583be0 ("lib: rework bitmap_parse()") does not take into account order of halfwords on 64-bit big endian architectures. As result (at least) Receive Packet Steering, IRQ affinity masks and runtime kernel test "test_bitmap" get broken on s390.

LGTM (I would replace while loop, but it's style preference and one can consider worse than infinite loop)

Quoted 54 lines
Fixes 2d6261583be0 ("lib: rework bitmap_parse()")
Cc Andrew Morton <[email protected]>
Cc Yury Norov <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Amritha Nambiar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Chris Wilson <[email protected]>
Cc Kees Cook <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Miklos Szeredi <[email protected]>
Cc Rasmus Villemoes <[email protected]>
Cc Steffen Klassert <[email protected]>
Cc "Tobin C . Harding" <[email protected]>
Cc Vineet Gupta <[email protected]>
Cc Will Deacon <[email protected]>
Cc Willem de Bruijn <[email protected]>
---
 lib/bitmap.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
lib/bitmap.c +7 -2
index 89260aa342d6..80d26b183248 100644
@@ -739,6 +739,7 @@ int bitmap_parse(const char *start, unsigned int buflen,
        const char *end = strnchrnul(start, buflen, '\n') - 1;
        int chunks = BITS_TO_U32(nmaskbits);
        u32 *bitmap = (u32 *)maskp;
+       int chunk = 0;
        int unset_bit;
 
        while (1) {
@@ -749,9 +750,14 @@ int bitmap_parse(const char *start, unsigned int buflen,
                if (!chunks--)
                        return -EOVERFLOW;
 
-               end = bitmap_get_x32_reverse(start, end, bitmap++);
+#if defined(CONFIG_64BIT) && defined(__BIG_ENDIAN)
+               end = bitmap_get_x32_reverse(start, end, &bitmap[chunk ^ 1]);
+#else
+               end = bitmap_get_x32_reverse(start, end, &bitmap[chunk]);
+#endif
                if (IS_ERR(end))
                        return PTR_ERR(end);
+               chunk++;
        }
 
        unset_bit = (BITS_TO_U32(nmaskbits) - chunks) * 32;
--

2.23.0

Signature · 2 lines
With Best Regards,
Andy Shevchenko