syscalls/add_key05: add new test for the length of payload
PATCH 1/2 syscalls/add_key05: add new test for the length of payload
Seeing add_key manpages, the lenth of payload for "user"/"logon" is 32767, this value is up tp 1M for "big_key". For "keyring" type , this value is zero.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/add_key/.gitignore | 1 + testcases/kernel/syscalls/add_key/add_key05.c | 99 +++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 testcases/kernel/syscalls/add_key/add_key05.c
runtest/syscalls +1 -0
@@ -18,6 +18,7 @@ add_key01 add_key01 add_key02 add_key02 add_key03 add_key03 add_key04 add_key04 +add_key05 add_key05 adjtimex01 adjtimex01 adjtimex02 adjtimex02
testcases/kernel/syscalls/add_key/.gitignore +1 -0
@@ -2,3 +2,4 @@ /add_key02 /add_key03 /add_key04 +/add_key05
testcases/kernel/syscalls/add_key/add_key05.c new file +99 -0
99 lines not on this page · raw message
Signature · 1 line
2.18.0
PATCH 2/2 syscalls/add_key01: remove duplicated case
Since add_key05.c has covered this test point, remove it.
--- runtest/syscalls | 1 - testcases/kernel/syscalls/add_key/.gitignore | 1 - testcases/kernel/syscalls/add_key/add_key01.c | 26 ------------------- 3 files changed, 28 deletions(-) delete mode 100644 testcases/kernel/syscalls/add_key/add_key01.c
runtest/syscalls +0 -1
@@ -14,7 +14,6 @@ access04 access04 acct01 acct01 acct02 acct02 -add_key01 add_key01 add_key02 add_key02 add_key03 add_key03 add_key04 add_key04
testcases/kernel/syscalls/add_key/.gitignore +0 -1
@@ -1,4 +1,3 @@ -/add_key01 /add_key02 /add_key03 /add_key04
testcases/kernel/syscalls/add_key/add_key01.c deleted +0 -26
@@ -1,26 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* -* Copyright (c) Crackerjack Project., 2007 -* Porting from Crackerjack to LTP is done by -* Manas Kumar Nayak [email protected]> -* -* Basic test for the add_key() syscall. -*/ - -#include <errno.h> - -#include "tst_test.h" -#include "lapi/keyctl.h" - -static void verify_add_key (void ) -{ -TEST (add_key ("keyring" ,"wjkey" ,NULL ,0 ,KEY_SPEC_THREAD_KEYRING )); -if (TST_RET ==-1 ) -tst_res (TFAIL |TTERRNO ,"add_key call failed" ); -else -tst_res (TPASS ,"add_key call succeeded" ); -} - -static struct tst_test test = { - .test_all = verify_add_key, -};
Signature · 1 line
2.18.0
PATCH 2/2 syscalls/add_key01: remove duplicated case
Hi!
Can't we just change the test instead of creating add_key05 then removing add_key01?
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/2 syscalls/add_key05: add new test for the length of payload
In reply to Yang XuHi!
Quoted 89 lines
Seeing
add_keymanpages, the lenth of payload for "user"/"logon" is 32767, this value is up tp 1M for "big_key". For "keyring" type , this value is zero.Signed-off-by Yang Xu <[email protected]>--- runtest/syscalls | 1 + testcases/kernel/syscalls/add_key/.gitignore | 1 + testcases/kernel/syscalls/add_key/add_key05.c | 99 +++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 testcases/kernel/syscalls/add_key/add_key05.cruntest/syscalls +1
-0@@ -18,6 +18,7 @@ add_key01 add_key01 add_key02 add_key02 add_key03 add_key03 add_key04 add_key04 +add_key05 add_key05 adjtimex01 adjtimex01 adjtimex02 adjtimex02testcases/kernel/syscalls/add_key/.gitignore +1
-0@@ -2,3 +2,4 @@ /add_key02 /add_key03 /add_key04 +/add_key05testcases/kernel/syscalls/add_key/add_key05.c new file +50
-0@@ -0,0 +1,99 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. +* Author: Yang Xu <[email protected]> +* +* This case test various key type can support how many long +* bytes payload. +* keyring: 0 bytes +* user/logon: 32767 bytes +* big_key: 1M -1byte +*/ + +#include <errno.h> +#include "tst_test.h" +#include "lapi/keyctl.h" + +struct tcase { +const char *type; +const char *desc; +size_t plen; +int pass_flag; +char *message; +} tcases[] = { + {"keyring" ,"abc" ,0 ,1 , +"The key type is keyrings and plen is 0" }, + + {"keyring" ,"bcd" ,1 ,0 , +"the key type is keyrings and plen is 1" }, + + {"user" ,"cde" ,32767 ,1 , +"The key type is user and plen is 32767" }, + + {"user" ,"def" ,32768 ,0 , +"The key type is user and plen is 32768" }, + + {"logon" ,"ef:g" ,32767 ,1 , +"The key type is logon and plen is 32767" }, + + {"logon" ,"fg:h" ,32768 ,0 , +"The key type is logon and plen is 32768" }, + + {"big_key" ,"ghi" , (1 <<20 ) -1 ,1 , +"The key type is big_key and plen is 1048575" }, + + {"big_key" ,"hij" ,1 <<20 ,0 , +"The key type is big_key and plen is 1048576" }, +}; + +static char *buf; +static unsigned int logon_nsup, big_key_nsup;
testcases/kernel/syscalls/add_key/add_key05.c line 60
Quoted 10 lines
testcases/kernel/syscalls/add_key/add_key05.c new file +10
-0+ +static void verify_add_key (unsigned int n) +{ +struct tcase *tc = &tcases[n]; + +tst_res (TINFO ,"%s" , tc->message); + +if (!strcmp (tc->type,"logon" ) && logon_nsup) { +tst_res (TINFO , +"current system doesn't support logon key type, skip it" );
This should be TCONF and the message could be much shorther and to the point, something as:
tst_res(TCONF, "skipping unsupported logon key");
testcases/kernel/syscalls/add_key/add_key05.c line 65
Quoted 6 lines
testcases/kernel/syscalls/add_key/add_key05.c new file +6
-0+return ; + } + +if (!strcmp (tc->type,"big_key" ) && big_key_nsup) { +tst_res (TINFO , +"current system doesn't support big_key key type, skip it" );
Here as well.
testcases/kernel/syscalls/add_key/add_key05.c line 74
Quoted 9 lines
testcases/kernel/syscalls/add_key/add_key05.c new file +9
-0+return ; + } + +TEST (add_key (tc->type, tc->desc, buf, tc->plen,KEY_SPEC_THREAD_KEYRING )); +if (TST_RET ==-1 ) { +if (TST_ERR ==EINVAL ) +tst_res (tc->pass_flag ?TFAIL :TPASS ,"add_key call failed as expected" ); +else +tst_res (TFAIL |TTERRNO ,"add_key call failed expected EINVAL but got" );
This is a bit confusing, we may get the messages even in a case that the key is supposed to be successfully created, right?
I guess that message "TFAIL: add_key call failed as expected" is not right.
Can we separate the negative a positive messages so that they are less confusing?
Quoted 12 lines
testcases/kernel/syscalls/add_key/add_key05.c new file +12
-0+return ; + } +tst_res (tc->pass_flag ?TPASS :TFAIL ,"add_key call succeeded" ); +} + +static void setup (void ) +{ +TEST (add_key ("logon" ,"test:sup_logon" , buf,64 ,KEY_SPEC_THREAD_KEYRING )); +if (TST_RET ==-1 ) + logon_nsup =1 ; + +TEST (add_key ("big_key" ,"sup_big_key" , buf,64 ,KEY_SPEC_THREAD_KEYRING ));
testcases/kernel/syscalls/add_key/add_key05.c line 96
Quoted 10 lines
testcases/kernel/syscalls/add_key/add_key05.c new file +10
-0+if (TST_RET ==-1 ) + big_key_nsup =1 ; +} + +static struct tst_test test = { + .setup = setup, + .tcnt =ARRAY_SIZE (tcases), + .test = verify_add_key, + .bufs = (struct tst_buffers []) { + {&buf, .size =1 <<20 },
We actually need different buffer for each different plen size, because the sole purpose of the buffer is to map a unaccessible page right after the end of the buffer to catch off-by-one accesses.
Quoted 11 lines
testcases/kernel/syscalls/add_key/add_key05.c new file +3
-0+ {} + } +};Signature · 7 lines
2.18.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/2 syscalls/add_key05: add new test for the length of payload
Hi
Quoted 103 lines
Hi!
Quoted 89 lines
Seeing
add_keymanpages, the lenth of payload for "user"/"logon" is 32767, this value is up tp 1M for "big_key". For "keyring" type , this value is zero.Signed-off-by Yang Xu <[email protected]>--- runtest/syscalls | 1 + testcases/kernel/syscalls/add_key/.gitignore | 1 + testcases/kernel/syscalls/add_key/add_key05.c | 99 +++++++++++++++++++ 3 files changed, 101 insertions(+)create mode 100644
testcases/kernel/syscalls/add_key/add_key05.cruntest/syscalls +1
-0@@ -18,6 +18,7 @@ add_key01 add_key01 add_key02 add_key02 add_key03 add_key03 add_key04 add_key04 +add_key05 add_key05 adjtimex01 adjtimex01 adjtimex02 adjtimex02testcases/kernel/syscalls/add_key/.gitignore +1
-0@@ -2,3 +2,4 @@ /add_key02 /add_key03 /add_key04 +/add_key05testcases/kernel/syscalls/add_key/add_key05.c new file +50
-0@@ -0,0 +1,99 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. +* Author: Yang Xu <[email protected]> +* +* This case test various key type can support how many long +* bytes payload. +* keyring: 0 bytes +* user/logon: 32767 bytes +* big_key: 1M -1byte +*/ + +#include <errno.h> +#include "tst_test.h" +#include "lapi/keyctl.h" + +struct tcase { +const char *type; +const char *desc; +size_t plen; +int pass_flag; +char *message; +} tcases[] = { + {"keyring" ,"abc" ,0 ,1 , +"The key type is keyrings and plen is 0" }, + + {"keyring" ,"bcd" ,1 ,0 , +"the key type is keyrings and plen is 1" }, + + {"user" ,"cde" ,32767 ,1 , +"The key type is user and plen is 32767" }, + + {"user" ,"def" ,32768 ,0 , +"The key type is user and plen is 32768" }, + + {"logon" ,"ef:g" ,32767 ,1 , +"The key type is logon and plen is 32767" }, + + {"logon" ,"fg:h" ,32768 ,0 , +"The key type is logon and plen is 32768" }, + + {"big_key" ,"ghi" , (1 <<20 ) -1 ,1 , +"The key type is big_key and plen is 1048575" }, + + {"big_key" ,"hij" ,1 <<20 ,0 , +"The key type is big_key and plen is 1048576" }, +}; + +static char *buf; +static unsigned int logon_nsup, big_key_nsup;testcases/kernel/syscalls/add_key/add_key05.c line 60
Quoted 10 lines
testcases/kernel/syscalls/add_key/add_key05.c new file +10
-0+ +static void verify_add_key (unsigned int n) +{ +struct tcase *tc = &tcases[n]; + +tst_res (TINFO ,"%s" , tc->message); + +if (!strcmp (tc->type,"logon" ) && logon_nsup) { +tst_res (TINFO , +"current system doesn't support logon key type, skip it" );This should be TCONF and the message could be much
shorther and to the point, something as:
Quoted 1 line
tst_res(TCONF, "skipping unsupported logon key");
OK.
Quoted 8 lines
testcases/kernel/syscalls/add_key/add_key05.c line 65
Quoted 6 lines
testcases/kernel/syscalls/add_key/add_key05.c new file +6
-0+return ; + } + +if (!strcmp (tc->type,"big_key" ) && big_key_nsup) { +tst_res (TINFO , +"current system doesn't support big_key key type, skip it" );Here as well.
OK.
Quoted 14 lines
testcases/kernel/syscalls/add_key/add_key05.c line 74
Quoted 10 lines
testcases/kernel/syscalls/add_key/add_key05.c new file +9
-0+return ; + } + +TEST (add_key (tc->type, tc->desc, buf, tc->plen,KEY_SPEC_THREAD_KEYRING )); +if (TST_RET ==-1 ) { +if (TST_ERR ==EINVAL ) +tst_res (tc->pass_flag ?TFAIL :TPASS ,"add_key call failed as expected" ); +else +tst_res (TFAIL |TTERRNO ,"add_key call failed expected EINVAL but got" );This is a bit confusing, we may get the messages even in a case that the key is supposed to be successfully created, right?
Quoted 5 lines
I guess that message "TFAIL:
add_keycall failed as expected" is not right.Can we separate the negative a positive messages so that they are less confusing?
Of course. I will separate them.
Quoted 19 lines
Quoted 19 lines
testcases/kernel/syscalls/add_key/add_key05.c new file +18
-0+return ; + } +tst_res (tc->pass_flag ?TPASS :TFAIL ,"add_key call succeeded" ); +} + +static void setup (void ) +{ +TEST (add_key ("logon" ,"test:sup_logon" , buf,64 ,KEY_SPEC_THREAD_KEYRING )); +if (TST_RET ==-1 ) + logon_nsup =1 ; + +TEST (add_key ("big_key" ,"sup_big_key" , buf,64 ,KEY_SPEC_THREAD_KEYRING )); +if (TST_RET ==-1 ) + big_key_nsup =1 ; +} + +static struct tst_test test = { + .setup = setup,
Quoted 8 lines
testcases/kernel/syscalls/add_key/add_key05.c line 96
Quoted 4 lines
testcases/kernel/syscalls/add_key/add_key05.c new file +4
-0+ .tcnt = ARRAY_SIZE(tcases), + .test = verify_add_key, + .bufs = (struct tst_buffers []) { + {&buf, .size =1 <<20 },We actually need different buffer for each different plen size, because the sole purpose of the buffer is to map a unaccessible page right after the end of the buffer to catch off-by-one accesses.
Agree. I will use different buffers. Also, I will modify add_key01.c code as you advised instead of creating a new add_key05.>
Quoted 12 lines
Quoted 11 lines
testcases/kernel/syscalls/add_key/add_key05.c new file +3
-0+ {} + } +};Signature · 7 lines
2.18.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/1 syscalls/add_key01: test the length of payload
In reply to Cyril HrubisSeeing add_key manpages, the length of payload for "user"/"logon" is 32767, this value is up tp 1M for "big_key". For "keyring" type , this value is zero.
---------v1->v2:
1. use different buffers for different length
2. split pass and fail message, make code less confusing
---------
--- testcases/kernel/syscalls/add_key/add_key01.c | 110 ++++++++++++++++-- 1 file changed, 102 insertions(+), 8 deletions(-)
testcases/kernel/syscalls/add_key/add_key01.c +102 -8
@@ -4,23 +4,117 @@* Porting from Crackerjack to LTP is done by * Manas Kumar Nayak [email protected]> * -* Basic test for the add_key() syscall. +* This case test various key type can support how many long +* bytes payload. +* keyring: 0 bytes +* user/logon: 32767 bytes +* big_key: 1M -1byte */ #include <errno.h> -#include "tst_test.h" #include "lapi/keyctl.h" -static void verify_add_key (void ) +static char *keyring_buf, *keyring_buf1; +static char *user_buf, *user_buf1; +static char *logon_buf, *logon_buf1; +static char *big_key_buf, *big_key_buf1; +static unsigned int logon_nsup, big_key_nsup; + +struct tcase { +const char *type; +const char *desc; +char **buf; +size_t plen; +int pass_flag; +char *message; +} tcases[] = { + {"keyring" ,"abc" , &keyring_buf,0 ,1 , +"The key type is keyrings and plen is 0" }, + + {"keyring" ,"bcd" , &keyring_buf,1 ,0 , +"the key type is keyrings and plen is 1" }, + + {"user" ,"cde" , &user_buf,32767 ,1 , +"The key type is user and plen is 32767" }, + + {"user" ,"def" , &user_buf1,32768 ,0 , +"The key type is user and plen is 32768" }, + + {"logon" ,"ef:g" , &logon_buf,32767 ,1 , +"The key type is logon and plen is 32767" }, + + {"logon" ,"fg:h" , &logon_buf1,32768 ,0 , +"The key type is logon and plen is 32768" }, + + {"big_key" ,"ghi" , &big_key_buf, (1 <<20 ) -1 ,1 , +"The key type is big_key and plen is 1048575" }, + + {"big_key" ,"hij" , &big_key_buf1,1 <<20 ,0 , +"The key type is big_key and plen is 1048576" }, +}; + +static void verify_add_key (unsigned int n) { -TEST (add_key ("keyring" ,"wjkey" ,NULL ,0 ,KEY_SPEC_THREAD_KEYRING )); +struct tcase *tc = &tcases[n]; + +tst_res (TINFO ,"%s" , tc->message); + +if (!strcmp (tc->type,"logon" ) && logon_nsup) { +tst_res (TCONF ,"skipping unsupported logon key" ); +return ; + } +if (!strcmp (tc->type,"big_key" ) && big_key_nsup) { +tst_res (TCONF ,"skipping unsupported big_key key" ); +return ; + } + +TEST (add_key (tc->type, tc->desc, *tc->buf, tc->plen,KEY_SPEC_THREAD_KEYRING )); +if (tc->pass_flag) { +if (TST_RET ==-1 ) +tst_res (TFAIL |TTERRNO ,"add_key call failed unexpectedly" ); +else +tst_res (TPASS ,"add_key call succeeded as expected" ); + }else { +if (TST_RET ==-1 ) { +if (TST_ERR ==EINVAL ) +tst_res (TPASS |TTERRNO ,"add_key call failed as expected" ); +else +tst_res (TFAIL |TTERRNO ,"add_key call failed expected EINVAL but got" ); + }else +tst_res (TFAIL ,"add_key call succeeded unexpectedly" ); + } +} + +static void setup (void ) +{ +char *logon_sup_buf, *big_key_sup_buf; + + logon_sup_buf =tst_alloc (64 ); + big_key_sup_buf =tst_alloc (64 ); + +TEST (add_key ("logon" ,"test:sup_logon" , logon_sup_buf,64 ,KEY_SPEC_THREAD_KEYRING )); +if (TST_RET ==-1 ) + logon_nsup =1 ; + +TEST (add_key ("big_key" ,"sup_big_key" , big_key_sup_buf,64 ,KEY_SPEC_THREAD_KEYRING ));if (TST_RET ==-1 ) -tst_res (TFAIL |TTERRNO ,"add_key call failed" ); -else -tst_res (TPASS ,"add_key call succeeded" ); + big_key_nsup =1 ; }static struct tst_test test = { - .test_all = verify_add_key, + .setup = setup, + .tcnt =ARRAY_SIZE (tcases), + .test = verify_add_key, + .bufs = (struct tst_buffers []) { + {&keyring_buf, .size =1 }, + {&keyring_buf1, .size =1 }, + {&user_buf, .size =32767 }, + {&user_buf1, .size =32768 }, + {&logon_buf, .size =32767 }, + {&logon_buf1, .size =32768 }, + {&big_key_buf, .size = (1 <<20 ) -1 }, + {&big_key_buf1, .size =1 <<20 }, + {} + } };
Signature · 1 line
2.18.0
PATCH v2 1/1 syscalls/add_key01: test the length of payload
Hi!
Quoted 3 lines
Seeing
add_keymanpages, the length of payload for "user"/"logon" is 32767, this value is up tp 1M for "big_key". For "keyring" type , this value is zero.
This version is nearly good, there are a few minor things I can fix up before applying.
However the test fails for me unless I run it as root. Looks like any key that is bigger than certain threshold fails with EDQUOT for me. Have you tried to run the test as an unpriviledged user?
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/1 syscalls/add_key01: test the length of payload
Quoted 6 lines
Hi!
Quoted 3 lines
Seeing
add_keymanpages, the length of payload for "user"/"logon" is 32767, this value is up tp 1M for "big_key". For "keyring" type , this value is zero.
Quoted 6 lines
This version is nearly good, there are a few minor things I can fix up before applying.
However the test fails for me unless I run it as root. Looks like any key that is bigger than certain threshold fails with EDQUOT for me. Have you tried to run the test as an unpriviledged user?
Hi Cyril
I don't run this test under an unpriviledged user. Seeing keyrings manpages, it said "/proc/sys/kernel/keys/maxbytes (since Linux 2.6.26)
This is the maximum number of bytes of data that a nonroot user can
hold in the payloads of the keys owned by theuser.
The default value in this file is 20,000.
I perfer to add .needs_root in this flag and check this in a new case. What do you think about it?
Best Regards
Yang Xu
Quoted 1 line
PATCH v2 1/1 syscalls/add_key01: test the length of payload
Hi!
Quoted 6 lines
I don't run this test under an unpriviledged user. Seeing keyrings manpages, it said "
/proc/sys/kernel/keys/maxbytes(since Linux 2.6.26)
This is the maximum number of bytes of data that a nonroot user can
hold in the payloads of the keys owned by theuser.
The default value in this file is 20,000.
Hmm, that means that we should write a test for this limit as well.
Quoted 2 lines
I perfer to add .needs_root in this flag and check this in a new case. What do you think about it?
Sounds good, I was thinking the same. So I will fix this and a few minor things as well and push this patch.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/1 syscalls/add_key01: test the length of payload
In reply to Yang XuHi!
I've removed the save buffers from the test setup, since I do not think that we should use them for the syscall availability check, added the .needs_root flag and pushed. Thanks.
Signature · 2 lines
Cyril Hrubis [email protected]