Creating and performing tests for a KasperskyOS-based solution security policy
A solution security policy is tested to verify whether or not the policy actually allows what should be allowed and denies what should be denied.
To create a set of tests for a solution security policy, use the following declaration:
You can create multiple sets of tests by using several of these declarations.
A set of tests can optionally include the initial part of the tests and/or the final part of the tests. The execution of each test from the set begins with whatever is described in the initial part of the test and ends with whatever is described in the final part of the test. This lets you describe the repeated initial and/or final parts of tests in each test.
After completing each test, all modifications in the Kaspersky Security Module related to the execution of this test are rolled back.
Each test includes one or more test cases.
Test cases
A test case associates a security event description and values of interface method parameters with an expected decision of the Kaspersky Security Module. If the actual security module decision matches the expected decision, the test case passes. Otherwise it fails.
When a test is run, the test cases are executed in the same sequence in which they are described. In other words, the test demonstrates how the security module handles a sequence of security events.
If all test cases within a test pass, the test passes. If even one test case fails to pass, the test fails. A test is terminated on the first failing test case. Each test from the set is run regardless of whether the previous test passed or failed.
A test case description in the PAL language is comprised of the following construct:
The expected decision of the security module can be indicated as grant
("granted"), deny
("denied") or any
("any decision"). You are not required to indicate the expected decision of the security module. The "granted" decision is expected by default. If the any
value is specified, the security module decision does not have any influence on whether or not the test case passes. In this case, the test case may fail due to errors that occur when the security module processes an IPC message (for example, when the IPC message has an invalid structure).
The name of the test case can be specified if only the expected decision of the security module is specified.
For information about the types and selectors of security events, and about the limitations when using selectors, see Binding methods of security models to security events. Selectors must ensure that the security event description corresponds to IPC messages of the same type. (When security model methods are bound to security events, selectors may not ensure this.)
In security event descriptions, you need to specify the SID instead of the process class name (and the KasperskyOS kernel). However, this requirement does not apply to execute
events for which the SID of the started process (or kernel) is unknown. To save the SID of the process or kernel to a variable, you need to use the <-
operator in the test case description in the following format:
The SID value will be assigned to the variable even if startup of the process of the defined class (or kernel) is denied by the tested policy but the "denied" decision is expected.
The PAL language supports abbreviated forms of security event descriptions:
security
: <Process SID
>!
<qualified name of security interface method
> corresponds tosecurity src=
<process SID
>method=
<qualified name of security interface method
>.request
: <client SID
>~>
<kernel/server SID
>:
<qualified name of endpoint.method name
> corresponds torequest src=
<client SID
>dst=
<kernel/server SID
>endpoint=
<qualified name of endpoint
>method=
<method name
>.response
: <client SID
><~
<kernel/server SID
>:
<qualified name of endpoint.method name
> corresponds toresponse src=
<kernel/server SID
>dst=
<client SID
>endpoint=
<qualified name of endpoint
>method=
<method name
>.
The values of interface method parameters must be defined for all types of security events except execute
. If the interface method has no parameters, specify {}
. You cannot specify {}
for security events of the execute
type.
Interface method parameters and their values must be defined by comma-separated constructs that look as follows:
The names and types of parameters must comply with the IDL description. The sequence order of parameters is not important.
Example definition of parameter values:
In this example, the number is passed through the param1
parameter. The string buffer is passed through the param2
parameter. A structure consisting of two fields is passed through the param3
parameter. The collection
field contains an array or sequence of three numeric elements. The filehandle
field contains the SID. A union or structure containing one field is passed through the param4
parameter. The name
field contains an array or sequence of two string buffers.
Currently, only an SID can be indicated as the value of a Handle
parameter, and there is no capability to indicate the SID together with a handle permissions mask. For this reason, it is not possible to properly test a solution security policy when the permissions masks of handles influence the security module decisions.
The values of parameters (or elements of parameters) do not have to be specified. If they are not specified, the system automatically applies the default values corresponding to the IDL types of parameters (and elements of parameters):
- The default values for numerical types and the
Handle
type are zero. - A zero-sized byte- or string buffer is the default value for byte- or string buffers.
- The default value for sequences is a sequence with zero elements.
- The default value for arrays is an array of elements with the default values.
- The default value for structures is a structure consisting of fields with the default values.
- For unions, the default value of the first member of the union is applied by default.
Example of applying the default value for a parameter and parameter element:
Example tests
See "Examples of tests for KasperskyOS-based solution security policies".
Test procedure
The test procedure includes the following steps:
- Save the tests in one or multiple PSL files (
*.psl
or*.psl.in
)
. - Add the
CMake
commandadd_kss_pal_qemu_tests()
to one of theCMakeLists.txt
files of the project.Use the
PSL_FILES
parameter to define the paths to PSL files containing tests. Use theDEPENDS
parameter to define theCMake
targets whose execution will cause the PSL file-dependent IDL, CDL, and EDL files to be put into the directories where thenk-psl-gen-c
compiler can find them. If*.psl.in
files are utilized, use theENTITIES
parameter to define the names of process classes of system programs. (These system programs are included in a KasperskyOS-based solution that requires security policy testing.)Example use of the
CMake
commandadd_kss_pal_qemu_tests()
in the fileeinit/CMakeLists.txt
:add_kss_pal_qemu_tests ( PSL_FILES src/security.psl.in DEPENDS kos-qemu-image ENTITIES ${ENTITIES}) - Build and run the tests.
You must run the Bash build script
cross-build.sh
with the parameter--target pal-test
<N
> (N is the index of the PSL file in the list of PSL files defined through thePSL_FILES
parameter of theCMake
commandadd_kss_pal_qemu_tests()
at step 2. For example,--target pal-test0
will create a KasperskyOS-based solution image corresponding to the first PSL file defined through thePSL_FILES
parameter of the CMake
commandadd_kss_pal_qemu_tests()
and then run that image in QEMU. (Instead of applications and system programs, this solution will contain the program that runs tests.)Example:
./cross-build.sh --target pal-test0
Example test results:
The test results contain information about whether or not each test passed or failed. If a test failed, information indicating the location of the description of the failed test example will be displayed in the PSL file.