Skip to contentSkip to conversation

crypto: Enable fuzz testing for arch code

PATCH In review Ard Biesheuvel 3 participants 5 messages Oct 16, 2024 – Oct 26, 2024

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

v2 cover crypto: Enable fuzz testing for arch code

From: Ard Biesheuvel <[email protected]>

Follow-up to [0].

crc32-generic and crc32c-generic are built around the architecture library code for CRC-32, and the lack of distinct drivers for this arch code means they are lacking test coverage.

Fix this by exposing the arch library code as a separate driver (with a higher priority) if it is different from the generic C code. Update the crc32-generic drivers to always use the generic C code.

Changes since [0]:
- make generic drivers truly generic, and expose the arch code as a separate driver

[0] https://lore.kernel.org/all/[email protected]/T/#u

Ard Biesheuvel (2):
crypto/crc32: Provide crc32-arch driver for accelerated library code crypto/crc32c: Provide crc32c-arch driver for accelerated library code

 crypto/Makefile         |  2 +
 crypto/crc32_generic.c  | 94 +++++++++++++++-----
 crypto/crc32c_generic.c | 94 +++++++++++++++-----
 lib/crc32.c             |  4 +
 4 files changed, 148 insertions(+), 46 deletions(-)
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog
#1 lore raw

PATCH v2 1/2 crypto/crc32: Provide crc32-arch driver for accelerated library code

From: Ard Biesheuvel <[email protected]>

crc32-generic is currently backed by the architecture's CRC-32 library code, which may offer a variety of implementations depending on the capabilities of the platform. These are not covered by the crypto subsystem's fuzz testing capabilities because crc32-generic is the reference driver that the fuzzing logic uses as a source of truth.

Fix this by providing a crc32-arch implementation which is based on the arch library code if available, and modify crc32-generic so it is always based on the generic C implementation. If the arch has no CRC-32 library code, this change does nothing.

---
 crypto/Makefile        |  1 +
 crypto/crc32_generic.c | 94 +++++++++++++++-----
 lib/crc32.c            |  2 +
 3 files changed, 73 insertions(+), 24 deletions(-)
crypto/Makefile +1 -0
index 4c99e5d376f6..2d4a3c0659fa 100644
@@ -152,6 +152,7 @@ obj-$(CONFIG_CRYPTO_DEFLATE) += deflate.o
 obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o
 obj-$(CONFIG_CRYPTO_CRC32C) += crc32c_generic.o
 obj-$(CONFIG_CRYPTO_CRC32) += crc32_generic.o
+CFLAGS_crc32_generic.o += -DARCH=$(ARCH)
 obj-$(CONFIG_CRYPTO_CRCT10DIF) += crct10dif_common.o crct10dif_generic.o
 obj-$(CONFIG_CRYPTO_CRC64_ROCKSOFT) += crc64_rocksoft_generic.o
 obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o authencesn.o
crypto/crc32_generic.c +70 -24

126 lines not on this page · raw message

lib/crc32.c +2 -0
index 5649847d0a8d..a54ba87b7073 100644
@@ -205,6 +205,8 @@ EXPORT_SYMBOL(crc32_le);
 EXPORT_SYMBOL(__crc32c_le);
 
 u32 __pure crc32_le_base(u32, unsigned char const *, size_t) __alias(crc32_le);
+EXPORT_SYMBOL(crc32_le_base);
+
 u32 __pure __crc32c_le_base(u32, unsigned char const *, size_t) __alias(__crc32c_le);
 u32 __pure crc32_be_base(u32, unsigned char const *, size_t) __alias(crc32_be);
 
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog
#2 lore raw

PATCH v2 2/2 crypto/crc32c: Provide crc32c-arch driver for accelerated library code

In reply to Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

crc32c-generic is currently backed by the architecture's CRC-32c library code, which may offer a variety of implementations depending on the capabilities of the platform. These are not covered by the crypto subsystem's fuzz testing capabilities because crc32c-generic is the reference driver that the fuzzing logic uses as a source of truth.

Fix this by providing a crc32c-arch implementation which is based on the arch library code if available, and modify crc32c-generic so it is always based on the generic C implementation. If the arch has no CRC-32c library code, this change does nothing.

---
 crypto/Makefile         |  1 +
 crypto/crc32c_generic.c | 94 +++++++++++++++-----
 lib/crc32.c             |  2 +
 3 files changed, 75 insertions(+), 22 deletions(-)
crypto/Makefile +1 -0
index 2d4a3c0659fa..a1ce3fa5298d 100644
@@ -152,6 +152,7 @@ obj-$(CONFIG_CRYPTO_DEFLATE) += deflate.o
 obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o
 obj-$(CONFIG_CRYPTO_CRC32C) += crc32c_generic.o
 obj-$(CONFIG_CRYPTO_CRC32) += crc32_generic.o
+CFLAGS_crc32c_generic.o += -DARCH=$(ARCH)
 CFLAGS_crc32_generic.o += -DARCH=$(ARCH)
 obj-$(CONFIG_CRYPTO_CRCT10DIF) += crct10dif_common.o crct10dif_generic.o
 obj-$(CONFIG_CRYPTO_CRC64_ROCKSOFT) += crc64_rocksoft_generic.o
crypto/crc32c_generic.c +72 -22

131 lines not on this page · raw message

lib/crc32.c +2 -0
index a54ba87b7073..ff587fee3893 100644
@@ -208,6 +208,8 @@ u32 __pure crc32_le_base(u32, unsigned char const *, size_t) __alias(crc32_le);
 EXPORT_SYMBOL(crc32_le_base);
 
 u32 __pure __crc32c_le_base(u32, unsigned char const *, size_t) __alias(__crc32c_le);
+EXPORT_SYMBOL(__crc32c_le_base);
+
 u32 __pure crc32_be_base(u32, unsigned char const *, size_t) __alias(crc32_be);
 
 /*
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog
Reviewed-by on the v2 series
#3 lore raw
In reply to Ard Biesheuvel
Quoted 22 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

Follow-up to [0].

crc32-generic and crc32c-generic are built around the architecture library code for CRC-32, and the lack of distinct drivers for this arch code means they are lacking test coverage.

Fix this by exposing the arch library code as a separate driver (with a higher priority) if it is different from the generic C code. Update the crc32-generic drivers to always use the generic C code.

Changes since [0]:
- make generic drivers truly generic, and expose the arch code as a separate driver

[0] https://lore.kernel.org/all/[email protected]/T/#u

Ard Biesheuvel (2):
crypto/crc32: Provide crc32-arch driver for accelerated library code crypto/crc32c: Provide crc32c-arch driver for accelerated library code

Quoted 5 lines
 crypto/Makefile         |  2 +
 crypto/crc32_generic.c  | 94 +++++++++++++++-----
 crypto/crc32c_generic.c | 94 +++++++++++++++-----
 lib/crc32.c             |  4 +
 4 files changed, 148 insertions(+), 46 deletions(-)

- Eric

maintainer
#4 lore raw
In reply to Ard Biesheuvel
Quoted 22 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

Follow-up to [0].

crc32-generic and crc32c-generic are built around the architecture library code for CRC-32, and the lack of distinct drivers for this arch code means they are lacking test coverage.

Fix this by exposing the arch library code as a separate driver (with a higher priority) if it is different from the generic C code. Update the crc32-generic drivers to always use the generic C code.

Changes since [0]:
- make generic drivers truly generic, and expose the arch code as a separate driver

[0] https://lore.kernel.org/all/[email protected]/T/#u

Ard Biesheuvel (2):
crypto/crc32: Provide crc32-arch driver for accelerated library code crypto/crc32c: Provide crc32c-arch driver for accelerated library code

Quoted 8 lines
 crypto/Makefile         |  2 +
 crypto/crc32_generic.c  | 94 +++++++++++++++-----
 crypto/crc32c_generic.c | 94 +++++++++++++++-----
 lib/crc32.c             |  4 +
 4 files changed, 148 insertions(+), 46 deletions(-)
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog

All applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt