Skip to contentSkip to conversation

arm64/crc-t10dif: fix use of out-of-scope array in crc_t10dif_arch()

PATCH Applied Eric Biggers 3 participants 7 messages Mar 26, 2025 – Mar 27, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64/crc-t10dif: fix use of out-of-scope array in crc_t10dif_arch()

From: Eric Biggers <[email protected]>

Fix a silly bug where an array was used outside of its scope.

---
 arch/arm64/lib/crc-t10dif-glue.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/arm64/lib/crc-t10dif-glue.c +1 -3
index a007d0c5f3fed..bacd18f231688 100644
@@ -43,13 +43,11 @@ u16 crc_t10dif_arch(u16 crc, const u8 *data, size_t length)
 
 			kernel_neon_begin();
 			crc_t10dif_pmull_p8(crc, data, length, buf);
 			kernel_neon_end();
 
-			crc = 0;
-			data = buf;
-			length = sizeof(buf);
+			return crc_t10dif_generic(0, buf, sizeof(buf));
 		}
 	}
 	return crc_t10dif_generic(crc, data, length);
 }
 EXPORT_SYMBOL(crc_t10dif_arch);

base-commit: 1e26c5e28ca5821a824e90dd359556f5e9e7b89f

Signature · 1 line
2.49.0
#1 lore raw

Hello there Eric,

Quoted 1 line

Fix a silly bug where an array was used outside of its scope.

I am surprised your C compiler doesn't find this bug. gcc 14.2 onwards should be able to, but clang not.

I will make an enhancement request in clang.

Regards

David Binderman

---
 arch/arm64/lib/crc-t10dif-glue.c | 4 +---

 1 file changed, 1 insertion(+), 3 deletions(-)
arch/arm64/lib/crc-t10dif-glue.c +0 -0
index a007d0c5f3fed..bacd18f231688 100644
@@ -43,13 +43,11 @@ u16 crc_t10dif_arch(u16 crc, const u8 *data, size_t length)


                         kernel_neon_begin(); crc_t10dif_pmull_p8(crc, data, length, buf); kernel_neon_end();

-                       crc = 0;
-                       data = buf;
-                       length = sizeof(buf);
+                       return crc_t10dif_generic(0, buf, sizeof(buf)); }
         }
         return crc_t10dif_generic(crc, data, length);
 }
 EXPORT_SYMBOL(crc_t10dif_arch);

base-commit: 1e26c5e28ca5821a824e90dd359556f5e9e7b89f --
2.49.0

#2 lore raw
Quoted 4 lines · David Binderman

Hello there Eric,

Quoted 1 line

Fix a silly bug where an array was used outside of its scope.

Quoted 9 lines

I am surprised your C compiler doesn't find this bug. gcc 14.2 onwards should be able to, but clang not.

I will make an enhancement request in clang.

Regards

David Binderman

Neither gcc 14.2.0 nor clang 19.1.7 found it, unfortunately. And the code still passed crc_kunit (even when run with have_pmull disabled so that the code is reached).

- Eric

#3 lore raw
In reply to Eric Biggers
Quoted 5 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Fix a silly bug where an array was used outside of its scope.

Yeah - mea culpa.

And the fact that we exit with a tail call means buf[] may be deallocated by the time crc_t10dif_generic() refers to it - I'm surprised this didn't already break in testing, but I suppose no tail call is issued for other reasons.

#4 lore raw
Quoted 10 lines · Ard Biesheuvel
Quoted 5 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Fix a silly bug where an array was used outside of its scope.

Yeah - mea culpa.

Ehmm - tua culpa, actually :-)

#5 lore raw
Quoted 6 lines · Ard Biesheuvel
Quoted 5 lines · Ard Biesheuvel
Quoted 3 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Fix a silly bug where an array was used outside of its scope.

Yeah - mea culpa.

Ehmm - tua culpa, actually :-)

Yep, your original code was correct and I messed it up.

- Eric

author Applied
#6 lore raw
In reply to Eric Biggers
Quoted 4 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Fix a silly bug where an array was used outside of its scope.

Quoted 8 lines
---
 arch/arm64/lib/crc-t10dif-glue.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Applied to https://web.git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=crc-next

- Eric