Skip to content

Commit

Permalink
request_key: Add negative tests for request_key
Browse files Browse the repository at this point in the history
Add negative tests for request_key(), when errno is EFAULT or EPERM

Signed-off-by: Ma Xinjian <[email protected]>
Reviewed-by: Petr Vorel <[email protected]>
Reviewed-by: Cyril Hrubis <[email protected]>
  • Loading branch information
Ma Xinjian via ltp authored and metan-ucw committed Sep 17, 2024
1 parent 83e8f4b commit efe1758
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions runtest/syscalls
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,7 @@ request_key02 request_key02
request_key03 request_key03
request_key04 request_key04
request_key05 request_key05
request_key06 request_key06

rmdir01 rmdir01
rmdir02 rmdir02
Expand Down
1 change: 1 addition & 0 deletions testcases/kernel/syscalls/request_key/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/request_key03
/request_key04
/request_key05
/request_key06
52 changes: 52 additions & 0 deletions testcases/kernel/syscalls/request_key/request_key06.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2024 FUJITSU LIMITED. All Rights Reserved.
* Author: Ma Xinjian <[email protected]>
*/

/*\
* [Description]
*
* Verify that request_key(2) fails with
*
* - EFAULT when type points outside the process's accessible address space
* - EFAULT when description points outside the process's accessible address space
* - EFAULT when callout_info points outside the process's accessible address space
* - EPERM when type argument started with a period '.'
*/

#include "tst_test.h"
#include "lapi/keyctl.h"

static struct test_case_t {
char *type;
char *description;
char *callout_info;
key_serial_t dest_keyring;
int expected_errno;
char *desc;
} tcases[] = {
{(char *)(-1), "description", NULL, KEY_SPEC_PROCESS_KEYRING, EFAULT,
"type points outside the process's accessible address space"},
{"type", (char *)(-1), NULL, KEY_SPEC_PROCESS_KEYRING, EFAULT,
"description points outside the process's accessible address space"},
{"type", "description", (char *)(-1), KEY_SPEC_PROCESS_KEYRING, EFAULT,
"callout_info points outside the process's accessible address space"},
{".type", "description", NULL, KEY_SPEC_PROCESS_KEYRING, EPERM,
"type argument started with a period '.'"},
};

static void verify_request_key(unsigned int i)
{
struct test_case_t *tc = &tcases[i];

TST_EXP_FAIL2(request_key(tc->type, tc->description, tc->callout_info,
tc->dest_keyring),
tc->expected_errno,
"%s", tc->desc);
}

static struct tst_test test = {
.tcnt = ARRAY_SIZE(tcases),
.test = verify_request_key,
};

0 comments on commit efe1758

Please sign in to comment.