diff mbox series

SUNRPC: Fix failures of checksum Kunit tests

Message ID 168166470652.2679.10078886564885712799.stgit@bazille.1015granger.net (mailing list archive)
State New, archived
Headers show
Series SUNRPC: Fix failures of checksum Kunit tests | expand

Commit Message

Chuck Lever April 16, 2023, 5:05 p.m. UTC
From: Chuck Lever <chuck.lever@oracle.com>

Scott reports that when the new GSS krb5 Kunit tests are built as
a separate module and loaded, the RFC 6803 and RFC 8009 checksum
tests all fail, even though they pass when run under kunit.py.

It appears that passing a buffer backed by static const memory to
gss_krb5_checksum() is a problem. A printk in checksum_case() shows
the correct plaintext, but by the time the buffer has been converted
to a scatterlist and arrives at checksummer(), it contains all
zeroes.

Replacing this buffer with one that is dynamically allocated fixes
the issue.

Reported-by: Scott Mayhew <smayhew@redhat.com>
Fixes: 02142b2ca8fc ("SUNRPC: Add checksum KUnit tests for the RFC 6803 encryption types")
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 net/sunrpc/auth_gss/gss_krb5_test.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Scott Mayhew April 17, 2023, 1:30 p.m. UTC | #1
Thanks, Chuck.  That fixes the test for me.

Tested-by: Scott Mayhew <smayhew@redhat.com>

-Scott

On Sun, 16 Apr 2023, Chuck Lever wrote:

> From: Chuck Lever <chuck.lever@oracle.com>
> 
> Scott reports that when the new GSS krb5 Kunit tests are built as
> a separate module and loaded, the RFC 6803 and RFC 8009 checksum
> tests all fail, even though they pass when run under kunit.py.
> 
> It appears that passing a buffer backed by static const memory to
> gss_krb5_checksum() is a problem. A printk in checksum_case() shows
> the correct plaintext, but by the time the buffer has been converted
> to a scatterlist and arrives at checksummer(), it contains all
> zeroes.
> 
> Replacing this buffer with one that is dynamically allocated fixes
> the issue.
> 
> Reported-by: Scott Mayhew <smayhew@redhat.com>
> Fixes: 02142b2ca8fc ("SUNRPC: Add checksum KUnit tests for the RFC 6803 encryption types")
> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
> ---
>  net/sunrpc/auth_gss/gss_krb5_test.c |    5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/net/sunrpc/auth_gss/gss_krb5_test.c b/net/sunrpc/auth_gss/gss_krb5_test.c
> index aa6ec4e858aa..95ca783795c5 100644
> --- a/net/sunrpc/auth_gss/gss_krb5_test.c
> +++ b/net/sunrpc/auth_gss/gss_krb5_test.c
> @@ -73,7 +73,6 @@ static void checksum_case(struct kunit *test)
>  {
>  	const struct gss_krb5_test_param *param = test->param_value;
>  	struct xdr_buf buf = {
> -		.head[0].iov_base	= param->plaintext->data,
>  		.head[0].iov_len	= param->plaintext->len,
>  		.len			= param->plaintext->len,
>  	};
> @@ -99,6 +98,10 @@ static void checksum_case(struct kunit *test)
>  	err = crypto_ahash_setkey(tfm, Kc.data, Kc.len);
>  	KUNIT_ASSERT_EQ(test, err, 0);
>  
> +	buf.head[0].iov_base = kunit_kzalloc(test, buf.head[0].iov_len, GFP_KERNEL);
> +	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf.head[0].iov_base);
> +	memcpy(buf.head[0].iov_base, param->plaintext->data, buf.head[0].iov_len);
> +
>  	checksum.len = gk5e->cksumlength;
>  	checksum.data = kunit_kzalloc(test, checksum.len, GFP_KERNEL);
>  	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, checksum.data);
> 
>
diff mbox series

Patch

diff --git a/net/sunrpc/auth_gss/gss_krb5_test.c b/net/sunrpc/auth_gss/gss_krb5_test.c
index aa6ec4e858aa..95ca783795c5 100644
--- a/net/sunrpc/auth_gss/gss_krb5_test.c
+++ b/net/sunrpc/auth_gss/gss_krb5_test.c
@@ -73,7 +73,6 @@  static void checksum_case(struct kunit *test)
 {
 	const struct gss_krb5_test_param *param = test->param_value;
 	struct xdr_buf buf = {
-		.head[0].iov_base	= param->plaintext->data,
 		.head[0].iov_len	= param->plaintext->len,
 		.len			= param->plaintext->len,
 	};
@@ -99,6 +98,10 @@  static void checksum_case(struct kunit *test)
 	err = crypto_ahash_setkey(tfm, Kc.data, Kc.len);
 	KUNIT_ASSERT_EQ(test, err, 0);
 
+	buf.head[0].iov_base = kunit_kzalloc(test, buf.head[0].iov_len, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf.head[0].iov_base);
+	memcpy(buf.head[0].iov_base, param->plaintext->data, buf.head[0].iov_len);
+
 	checksum.len = gk5e->cksumlength;
 	checksum.data = kunit_kzalloc(test, checksum.len, GFP_KERNEL);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, checksum.data);