From a00612c6ad2df7116c6fc39e7c6c2009052b5c8d Mon Sep 17 00:00:00 2001 From: yixiangzhike Date: Wed, 26 Jan 2022 15:03:52 +0800 Subject: [PATCH] Enable test suite in check --- backport-Kern-5.8-fix-MSG_MORE-usage.patch | 166 ++++++++++++++++++ ...ng-in-fuzz-tests-with-recent-kernels.patch | 41 +++++ libkcapi.spec | 21 ++- 3 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 backport-Kern-5.8-fix-MSG_MORE-usage.patch create mode 100644 backport-kcapi-Fix-hang-in-fuzz-tests-with-recent-kernels.patch diff --git a/backport-Kern-5.8-fix-MSG_MORE-usage.patch b/backport-Kern-5.8-fix-MSG_MORE-usage.patch new file mode 100644 index 0000000..5ef55f4 --- /dev/null +++ b/backport-Kern-5.8-fix-MSG_MORE-usage.patch @@ -0,0 +1,166 @@ +From b612c52c5ccf021d01e6c786db1a31a697f21d97 Mon Sep 17 00:00:00 2001 +From: Stephan Mueller +Date: Thu, 13 Aug 2020 21:58:07 +0200 +Subject: [PATCH] Kern 5.8: fix MSG_MORE usage + +With kernel 5.8, a precise use of MSG_MORE is mandatory to support +a stream cipher approach (init -> update -> update -> ... -> final). +All but the last update operations must use MSG_MORE, the last update +operation must not use MSG_MORE. + +Reported-by: Ondrej Mosnacek +Signed-off-by: Stephan Mueller +--- + lib/kcapi-aead.c | 24 ++++++++++++++---------- + lib/kcapi-kernel-if.c | 6 ++---- + test/kcapi-main.c | 31 +++++++++++++++++-------------- + 3 files changed, 33 insertions(+), 28 deletions(-) + +diff --git a/lib/kcapi-aead.c b/lib/kcapi-aead.c +index d241618..45a0bd7 100644 +--- a/lib/kcapi-aead.c ++++ b/lib/kcapi-aead.c +@@ -210,13 +210,15 @@ _kcapi_aead_encrypt_aio_fallback(struct kcapi_handle *handle, + uint32_t iovlen, const uint8_t *iv) + { + uint32_t i; +- int32_t ret = kcapi_aead_stream_init_enc(handle, iv, NULL, 0); +- +- if (ret < 0) +- return ret; ++ int32_t ret = 0; + + for (i = 0; i < iovlen; i++) { +- int rc = kcapi_aead_stream_update_last(handle, iniov, 1); ++ int rc = kcapi_aead_stream_init_enc(handle, iv, NULL, 0); ++ ++ if (rc < 0) ++ return rc; ++ ++ rc = kcapi_aead_stream_update_last(handle, iniov, 1); + if (rc < 0) + return rc; + +@@ -271,13 +273,15 @@ _kcapi_aead_decrypt_aio_fallback(struct kcapi_handle *handle, + uint32_t iovlen, const uint8_t *iv) + { + uint32_t i; +- int32_t ret = kcapi_aead_stream_init_dec(handle, iv, NULL, 0); +- +- if (ret < 0) +- return ret; ++ int32_t ret = 0; + + for (i = 0; i < iovlen; i++) { +- int rc = kcapi_aead_stream_update_last(handle, iniov, 1); ++ int rc = kcapi_aead_stream_init_dec(handle, iv, NULL, 0); ++ ++ if (rc < 0) ++ return rc; ++ ++ rc = kcapi_aead_stream_update_last(handle, iniov, 1); + if (rc < 0) + return rc; + +diff --git a/lib/kcapi-kernel-if.c b/lib/kcapi-kernel-if.c +index bea994f..42cf1ad 100644 +--- a/lib/kcapi-kernel-if.c ++++ b/lib/kcapi-kernel-if.c +@@ -439,8 +439,7 @@ int _kcapi_aio_send_iov(struct kcapi_handle *handle, struct iovec *iov, + if (0 > ret) + return ret; + } else { +- ret = _kcapi_common_send_meta(handle, NULL, 0, enc, +- len ? MSG_MORE : 0); ++ ret = _kcapi_common_send_meta(handle, NULL, 0, enc, MSG_MORE); + if (0 > ret) + return ret; + ret = _kcapi_common_vmsplice_iov(handle, iov, iovlen, 0); +@@ -1246,8 +1245,7 @@ int32_t _kcapi_cipher_crypt(struct kcapi_handle *handle, const uint8_t *in, + if (0 > ret) + return ret; + } else { +- ret = _kcapi_common_send_meta(handle, NULL, 0, enc, +- inlen ? MSG_MORE : 0); ++ ret = _kcapi_common_send_meta(handle, NULL, 0, enc, MSG_MORE); + if (0 > ret) + return ret; + ret = _kcapi_common_vmsplice_chunk(handle, in, inlen, 0); +diff --git a/test/kcapi-main.c b/test/kcapi-main.c +index 51f6ec7..64e466c 100644 +--- a/test/kcapi-main.c ++++ b/test/kcapi-main.c +@@ -846,7 +846,7 @@ static int cavs_sym(struct kcapi_cavs *cavs_test, uint32_t loops, + goto out; + } + +- for(i = 0; i < loops; i++) { ++ for (i = 0; i < loops; i++) { + _get_time(&begin); + if (cavs_test->enc) { + ret = kcapi_cipher_encrypt(handle, +@@ -886,7 +886,7 @@ out: + } + + static void mt_sym_writer(struct kcapi_handle *handle, struct iovec *iov, +- int forking) ++ int forking, int last) + { + int ret; + +@@ -899,7 +899,10 @@ static void mt_sym_writer(struct kcapi_handle *handle, struct iovec *iov, + return; + } + +- ret = kcapi_cipher_stream_update_last(handle, iov, 1); ++ if (last) ++ ret = kcapi_cipher_stream_update_last(handle, iov, 1); ++ else ++ ret = kcapi_cipher_stream_update(handle, iov, 1); + if (0 > ret) + printf("Sending of data failed\n"); + +@@ -1004,7 +1007,7 @@ static int cavs_sym_stream(struct kcapi_cavs *cavs_test, uint32_t loops, + iov.iov_len = cavs_test->ctlen; + } + +- mt_sym_writer(handle_ptr, &iov, forking); ++ mt_sym_writer(handle_ptr, &iov, forking, i == (loops * 2 - 1)); + + outiov.iov_base = outbuf_ptr; + outiov.iov_len = outbuflen; +@@ -1636,21 +1639,21 @@ static int cavs_aead_stream(struct kcapi_cavs *cavs_test, uint32_t loops, + if (ret) + goto out; + +- if (cavs_test->enc) +- ret = kcapi_aead_stream_init_enc(handle, newiv, NULL, 0); +- +- else +- ret = kcapi_aead_stream_init_dec(handle, newiv, NULL, 0); +- if (0 > ret) { +- printf("Initialization of cipher buffer failed\n"); +- goto out; +- } +- + for (i = 0; i < loops; i++) { + int errsv = 0; + + memset(outbuf, 0, outbuflen); + ++ if (cavs_test->enc) ++ ret = kcapi_aead_stream_init_enc(handle, newiv, NULL, 0); ++ else ++ ret = kcapi_aead_stream_init_dec(handle, newiv, NULL, 0); ++ if (0 > ret) { ++ printf("Initialization of cipher buffer failed\n"); ++ goto out; ++ } ++ ++ + iov.iov_base = cavs_test->assoc; + iov.iov_len = cavs_test->assoclen; + if (cavs_test->enc) { +-- +1.8.3.1 + diff --git a/backport-kcapi-Fix-hang-in-fuzz-tests-with-recent-kernels.patch b/backport-kcapi-Fix-hang-in-fuzz-tests-with-recent-kernels.patch new file mode 100644 index 0000000..ffb44ce --- /dev/null +++ b/backport-kcapi-Fix-hang-in-fuzz-tests-with-recent-kernels.patch @@ -0,0 +1,41 @@ +From 62ff3409a0743863acbb6bb74c03afba8ad237ea Mon Sep 17 00:00:00 2001 +From: Ondrej Mosnacek +Date: Sat, 27 Mar 2021 13:46:45 +0100 +Subject: [PATCH] kcapi: Fix hang in fuzz tests with recent kernels + +After kernel commit f3c802a1f300 ("crypto: algif_aead - Only wake up +when..."), the fuzz tests hang indefinitely, because they request more +output data than the operation can produce. Fix this by requesting at +most the expected size of the output data. + +Signed-off-by: Ondrej Mosnacek +Signed-off-by: Stephan Mueller +--- + test/kcapi-main.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/test/kcapi-main.c b/test/kcapi-main.c +index 64e466c..975e8d1 100644 +--- a/test/kcapi-main.c ++++ b/test/kcapi-main.c +@@ -380,7 +380,7 @@ static int fuzz_cipher(struct kcapi_cavs *cavs_test, unsigned long flags, + } + + for (i = 0; i < sizeof(indata); i++) { +- unsigned int outlen = sizeof(outdata); ++ unsigned int outlen = i; + uint8_t *out = outdata; + uint8_t *iv = indata; + uint8_t *in = indata; +@@ -474,7 +474,7 @@ static int fuzz_aead(struct kcapi_cavs *cavs_test, unsigned long flags, + } + + for (i = 0; i < sizeof(indata); i++) { +- unsigned int outlen = sizeof(outdata); ++ unsigned int outlen = i; + uint8_t *out = outdata; + uint8_t *iv = indata; + uint8_t *in = indata; +-- +1.8.3.1 + diff --git a/libkcapi.spec b/libkcapi.spec index aacccae..43e16cd 100644 --- a/libkcapi.spec +++ b/libkcapi.spec @@ -4,7 +4,7 @@ Name: libkcapi Version: 1.2.0 -Release: 4 +Release: 5 Summary: libkcapi - Linux Kernel Crypto API User Space Interface Library License: BSD or GPLv2 @@ -13,6 +13,10 @@ Source0: http://www.chronox.de/%{name}/%{name}-%{version}.tar.xz Source1: http://www.chronox.de/%{name}/%{name}-%{version}.tar.xz.asc Patch0: libkcapi-1.1.1-lib_Fix_kcapi_handle_destroy_closing_FD_0.patch +# support kernel-5.8 and later +Patch1: backport-Kern-5.8-fix-MSG_MORE-usage.patch +# fix fuzz test with recent kernels +Patch2: backport-kcapi-Fix-hang-in-fuzz-tests-with-recent-kernels.patch BuildRequires: clang coreutils cppcheck docbook-utils-pdf gcc git hardlink BuildRequires: libtool openssl perl systemd xmlto kernel-headers >= 4.10.0 @@ -155,6 +159,15 @@ bin/kcapi-hasher -n fipshmac -d %{buildroot}/%{_lib}/fipscheck %{buildroot}/%{ ln -s libkcapi.so.%{version}.hmac %{buildroot}/%{_lib}/fipscheck/libkcapi.so.1.hmac %check +for t in cppcheck scan;do + %make_build $t +done + +pushd test +ENABLE_FUZZ_TEST=1 \ +NO_32BIT_TEST=1 \ +./test-invocation.sh ||: +popd %files %doc %dir %{_pkgdocdir} @@ -185,6 +198,12 @@ ln -s libkcapi.so.%{version}.hmac %{buildroot}/%{_lib}/fipscheck/libkcapi.so. %{_mandir}/man3/kcapi_*.3.* %changelog +* Wed Jan 26 2022 yixiangzhike - 1.2.0-5 +- Type:enhancement +- ID:NA +- SUG:NA +- DESC:enable test suite in check + * Fri Nov 20 2020 panxiaohe - 1.2.0-4 - Type:bugfix - ID:NA -- Gitee