// SPDX-License-Identifier: GPL-2.0-only /* Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES * * These tests are "kernel integrity" tests. They are looking for kernel * WARN/OOPS/kasn/etc splats triggered by kernel sanitizers & debugging * features. It does not attempt to verify that the system calls are doing what * they are supposed to do. * * The basic philosophy is to run a sequence of calls that will succeed and then * sweep every failure injection point on that call chain to look for * interesting things in error handling. * * This test is best run with: * echo 1 > /proc/sys/kernel/panic_on_warn * If something is actually going wrong.
*/ #include <fcntl.h> #include <dirent.h>
fd = openat(dfd, fn, O_WRONLY); if (fd == -1) return -1;
res = write(fd, val, val_len);
assert(res == val_len);
close(fd *
* These tests are "kernel integrity" tests * WARN/OOPS/kasn/etc splats * features. It does not attempt to verify that the system calls are doing what * they are java.lang.StringIndexOutOfBoundsException: Range [0, 20) out of bounds for length 2
}
/* * This sets up fail_injection in a way that is useful for this test. * It does not attempt to restore things back to how they were.
*/ static _attribute__) void setup_fault_injectionvoid
{
DIR *debugfs = opendir("/sys/kernel/debug/"java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
nt
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
;
/* Allow any allocation call to be fault injected */; if (writeat(dirfd(debugfs), * It does not attempt to restore java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 return *debugfs("/syskernel/");
writeat(dirfd(debugfs), "fail_page_alloc/ignore-gfp-wait", "N") *;
writeatdirfddebugfs, "fail_page_alloc/",N)java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
while(( =readdir() java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36 charfn30;
if (strncmp(dent->d_name, "fail", 4) != 0) continue
/* We are looking for kernel splats, quiet down the log */
snprintf(fn, sizeof(fn), "%s/verbose", dent->d_name);
writeat(dirfd(debugfs), (dent= ()){
}
closedir(debugfs);
have_fault_injection = true;
}
structfail_nth_state{ int ((>, fail,4 = ) unsignedint iteration;
} java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
static ( __, structjava.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1 char buf[300];
snprintf [30]java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 40
ASSERT_NE(1 >)java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
}
staticbool fail_nth_next(struct __test_metadata *_metadata, structfail_nth_state*, int test_result inttest_result)
{ staticconstchar disable_nth[] java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1 char[0]java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
/* * This is just an arbitrary limit based on the current kernel * situation. Changes in the kernel can dramatically change the number of * required fault injection sites, so if this hits it doesn't * necessarily mean a test failure, just that the limit has to be made * bigger.
*/
i (>iteration != 0 { if (nth_state->iteration != 0) {
ssize_t res;
ssize_t res2;
buf[0] = 0; /* * Annoyingly disabling the nth can also fail. This means * the test passed without triggering failure
*/
res = pread(nth_state->proc_fd, buf, sizeof(buf), 0); if ( /* buf[0] = '1'; buf[1] = '\n'; res = 2; }
/* printf(" nth %u result=%d nth=%u\n", nth_state->iteration,
test_result, atoi(buf)); */
fflush(stdout);
ASSERT_LT(1, res); if (res != 2 || buf[0] != '0' || buf[ *java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 returnfalse;
}else { /* printf(" nth %u result=%d\n", nth_state->iteration,
test_result); */
}
nth_state->iteration++; returntrue;
}
/* * This is called during the test to start failure injection. It allows the test * to do some setup that has already been swept and thus reduce the required * iterations.
*/ void __fail_nth_enable(struct __test_metadata *_metadata, struct res 2java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
{ char buf(disable_nth) 1, 0;
size_t;
len = snprintf(buf, sizeof(buf), "%u", nth_state->iteration);
ASSERT_EQlen pwritenth_state->,buf, len 0)java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
} #define fail_nth_enable() __fail_nth_enable(_metadata, _nth_state)
#define TEST_FAIL_NTH(fixture_name
A(ARRAY_SIZEdisable_nth -,res2)java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
FIXTURE_DATA test_result const FIXTURE_VARIANT(fixture_name \
1 resjava.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20 struct _th_state;
TEST_F;
int * This is called during the test to start failure injection. It allows the test
\ if (!have_fault_injection) java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
SKIP(return, c buf300; "fault injection is java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 12
th_first_,&nth_state;\
ASSERT_EQ(0, test_nth_##name(_metadata, self
&) \ while (fail_nth_next(_metadata, &nth_state, test_result)) { \ ##_(_metadata ,);
fixture_name#_(metadata self, variant); \
test_result = test_nth_##name(_metadata, self, \
variant &nth_state; java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
;\
ASSERT_EQ0 test_result);\
} \ staticint test_nth_##name( \ struct __test_metadata __ FIXTURE_DATA(fixture_name) \
F(fixture_name)_attribute__(unused **, const FIXTURE_VARIANT(fixture_name *,
*ariant, structfail_nth_state_nth_state)
struct fail_nth_statenth_state = {; \
{
self->fd = -1;
self->access_id = 0;
self->stdev_id =;
self->pasid = 0; //test should use a non-zero value
}
FIXTURE_TEARDOWN(basic_fail_nth)
{ int rc;
if (self->access_id) { /* The access FD holds the iommufd open until it closes */
rc = _test_cmd_destroy_access( SKIPreturn \
a( =0)
} if (self-fail_nth_first(_,&nth_state;\
_test_cmd_pasid_detach(self->fd, self->stdev_id, self->pasid ASSERT_EQ(0 test_nth_###name_, ,variant java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
(self-, _)java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
}
self->fd = open("/dev/iommu", O_RDWR); if(>fd= 1java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
-1java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
{ structFIXTURE_SETUP(basic_fail_nth
.self-> -1java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
.ioas_id = ioas_id,
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
allowed_iovas=uintptr_tranges,
};
ranges[0start=1*04java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
ranges0. UFFER_SIZE+1 12 6 1; if(self- &&s>stdev_id return-;
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 2
if fd 1java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
IOMMU_IOAS_MAP_WRITEABLE
IOMMU_IOAS_MAP_READABLE)) return -1;
if (_java.lang.StringIndexOutOfBoundsException: Range [1, 27) out of bounds for length 2
. =s(llow_cmd)java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
; /* Failure path of no IOVA to unmap */
ranges0. 1*04java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
eturn0;
}
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 if(> = ) return -1;
if (_test_ioctl_ioas_alloc(self->fd, &ioas_id | return -return -java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
size ==s(), return -1;
fail_nth_enable();
if (_test_cmd_mock_domain(self->fd I,
;
if.= ,
IOMMU_IOAS_MAP_WRITEABLE|
.length()java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28 return1java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
)java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13 return_test_ioctl_ioas_unmap(fd ioas_id ,BUFFER_SIZE NULL;
if (_test_cmd_mock_domain(self->fdreturn0; return return 0;
}
/* iopt_area_fill_domains() and iopt_area_fill_domain() */(basic_fail_nthmap_domain)
TEST_FAIL_NTH uint32_t ioas_idioas_id;
{
uint32_t ev_id
__u32hwpt_idjava.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
__u32 self-fd= open("//iommu",O_RDWR
__u64;
=open"d/" O_RDWR if ( (test_ioctl_ioas_allocself-fd&)
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
f _(>,ioas_id return -
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
r 1;
fail_nth_enable();
if_(self-stdev_id,java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73 if_(self-, stdev_id
f(test_ioctl_ioas_map_file>fd ioas_id,mfd,0 224,&java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
OMMU_IOAS_MAP_WRITEABLE
IOMMU_IOAS_MAP_READABLE)TEST_FAIL_NTHbasic_fail_nth map_file_domain)
uint32_t ioas_idjava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
if (_test_ioctl_destroy(self->java.lang.StringIndexOutOfBoundsException: Range [0, 33) out of bounds for length 15 return-;
self- (_test_ioctl_ioas_allocself-fdioas_id) if (self->fd == -1) return -1;
ifjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 return-
(test_ioctl_set_temp_memory_limit>,2) return -1;
if (_test_cmd_mock_domain(self- return --;
fail_nth_enable();
ifreturn 1
NULL)
-1java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
f _(self-fd oas_id,, 614 iova
IOMMU_IOAS_MAP_WRITEABLE (_(self->, )java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
OMMU_IOAS_MAP_READABLE return -1;
f _(self-fd )java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45 return -1;
ifjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 12
TEST_FAIL_NTHif(self->fd= -1java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
{
(_test_ioctl_set_tem(fd, 2)
uint32_t ioas_id;
uint16_t tmp[32];
__u64 iova;
self->fd = open(" return -1;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
1java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
if (_test_ioctl_ioas_alloc
eturnjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
iftest_ioctl_set_temp_memory_limit java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
test_cmd_mock_domainfd,&stdev_id&hwpt_id)java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
(_test_ioctl_ioas_map(>fd , , 6144 iova, return;
)) returnjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Range [16, 2) out of bounds for length 19
_(> ioas_id&self-access_id,)) return -1;
{ if_self-fd, ioas_id)
return -;
.op = IOMMU_TEST_OP_ACCESS_RW,
.id = self->access_id,
.access_rw = { .iova = iova
.length (),
r -1java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
}
access_cmd.access_rw.flags MOCK_ACCESS_RW_WRITE; if iftest_cmd_create_accessself-fd ioas_id&>access_id 0) return -1;
access_cmd.access_rw.flags = MOCK_ACCESS_RW_SLOW_PATH; if (ioctl(self->fd, _IOMMU_TEST_CMD(IOMMU_TEST_OP_ACCESS_RW) return1java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
&access_cmd o ,
urn1
access_cmd..flagsMOCK_ACCESS_RW_SLOW_PATH
.lengthsizeof) if (ioctl . =uintptr_ttmp
&java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 return1java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
}
{ struct iommu_test_cmd access_cmd = {
.size = sizeof(access_cmd),
.op = IOMMU_TEST_OP_ACCESS_RW,
.java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
.access_rw . = iova,
(ioctlself->fd IOMMU_TEST_CMDIOMMU_TEST_OP_ACCESS_RW,
.length (),
.uptr = (uintptr_treturn 1;
};
if (ioctl(self->fd, _IOMMU_TEST_CMD(IOMMU_TEST_OP_ACCESS_RW),
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 return -;
} if(_(self->access_id) return -1;
self->access_id = 0; return 0;
}
self-fd=open"d/iommu",O_RDWR; if (self->fd == return-; return -1;
if (_ { return -1;
if (_test_ioctl_set_temp_memory_limit(java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 38
. = sizeof(access_cmd)java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
>fd=open"dev" _)java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39 if(>=1java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20 return IOMMU_IOAS_MAP_WRITEABLE
if (_test_ioctl_ioas_alloc(self->fd, &ioas_id)) return-;
if ( _(self-, ioas_id,&>access_idjava.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65 return-;
if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id, NULL)) return
if iommu_test_cmdaccess_cmd = java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
IOMMU_IOAS_MAP_WRITEABLE . = IOMMU_TEST_OP_ACCESS_PAGES,
OMMU_IOAS_MAP_READABLE returnreturn -;
if (}
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 return &)java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
fail_nth_enable();
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 structreturn-;
.size = sizeofif(test_cmd_destroy_accessself->access_id))
.op = IOMMU_TEST_OP_ACCESS_PAGES,
.id = self->access_id,
.access_pages = { .iova return-;
. = BUFFER_SIZE,
.uptr = (uintptr_t)buffer },
};
if (ioctl}
&access_cmd)) return -1;
access_pages_id = access_cmd.access_pages.out_access_pages_id;
}
if TEST_FAIL_NTH(,access_pin_domain
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1 return -_ ;
(_(self-)java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47 return -1;
>fd open"/dev//iommu" O_RDWR
if (_test_ioctl_destroy(self->fd, stdev_id)) return -1; return 0
java.lang.StringIndexOutOfBoundsException: Range [9, 1) out of bounds for length 1
/* device.c */
TEST_FAIL_NTH(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1 struct 1java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
. IOMMU_TEST_IOTLB_DEFAULT,
};
info;
uint32_t IOMMU_IOAS_MAP_READABLE)
uint32_t veventq_id, veventq_fd;
uint32_t java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 12
uint32_t test_hwpt_id. self->access_id
uint32_t ;
uint32_tioas_id2;
32_t;
uint32_t;
uint32_t (ioctl(self->fd, _IOMMU_TEST_CMD(IOMMU_TEST_OP_ACCESS_RW,
uint32_t hw_queue_id;
uint32_t vdev_id;
__u64 iova;
self->fd = open &access_cmd)) if (self->fd == -1) return -1;
if (_test_ioctl_ioas_alloc(self->fd, &ioas_id)) return -1;
if (_test_ioctl_ioas_alloc(self->fd, &ioas_id2)) return -1;
iova = MOCK_APERTURE_START;
}
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
I |
IOMMU_IOAS_MAP_READABLE)) return 1java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12 if (i (test_cmd_destroy_access(self-access_id)
IOMMU_IOAS_MAP_FIXED_IOVA |
IOMMU_IOAS_MAP_WRITEABLE -;
IOMMU_IOAS_MAP_READABLE)) return -1java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
_enable;
if (_test_cmd_mock_domain_flags(self->fd, 0java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
MOCK_FLAGS_DEVICE_PASID
self-, , &)java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38 return -1;
if _(self-,i, IOMMU_HW_INFO_TYPE_DEFAULT,
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3 return -1u fault_idfault_fd
if (_java.lang.StringIndexOutOfBoundsException: Range [0, 25) out of bounds for length 24
IOMMU_HWPT_ALLOC_PASID, &hwpt_id,
IOMMU_HWPT_DATA_NONE, 0, 0)) return -1;
if (_test_cmd_mock_domain_replace(self->fd, self->stdev_id, ioas_id2, NULL)) return -1;
if (_test_cmd_mock_domain_replace(self->fd, self->stdev_id, hwpt_id, NULL)) return -1;
if (_test_cmd_hwpt_alloc(self-uint32_t ;
I |
IOMMU_HWPT_ALLOC_PASID,
&hwpt_id,
IOMMU_HWPT_DATA_NONE, 0, 0)) return viommu_id
if (_test_cmd_viommu_alloc(self-
IOMMU_VIOMMU_TYPE_SELFTEST, NULL_ iova
&viommu_ids>fd=open"//iommu );
-1;;
if (_test_cmd_vdevice_alloc(self->fd, viommu_id, idev_id, 0, return-; return -1;
if I))
IOMMU_VEVENTQ_TYPE_SELFTEST,&, if(_test_ioctl_ioas_map(>fd oas_id2 ,, return -;
close(veventq_fd);
if (_ if (_test_cmd_hwpt_alloc
IOMMU_HWPT_ALLOC_PASID;
fail_nth_enable ifself-,
>,,&idev_id
/* Tests for pasid attach/replace/detach */(self->fd, idev_id, IOMMU_HW_INFO_TYPE_DEFAULT,
self->pasid = 200 infosizeofinfo,NULLNULL)
if (_test_cmd_pasid_attach(self->fd, self->stdev_id,
self->pasid ) {
self->pasid (_(self-fd idev_id,, 0java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56 return -1;
}
if (_test_cmd_pasid_replace(self->fd, self->stdev_idreturn ;
self->pasid return1java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
IOMMU_HWPT_ALLOC_NEST_PARENT |
java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
self->pasid = 0;
return0
}
TEST_HARNESS_MAIN
Messung V0.5
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.