[LTP] [PATCH 6/7] Add lsm_list_modules02 test

Cyril Hrubis chrubis@suse.cz
Wed Jan 8 15:05:00 CET 2025


Hi!
> +		if (!name)
> +			tst_brk(TBROK, "Unsupported LSM: %lu", ids[i]);
> +
> +		if (strstr(name, lsm_list))

Again here the strstr() is not future proof. There is no lsm with the
name as a substring of a different lsm, but it's not entirely unlikely
that a lsm with name that contains one of the three letter names as a
substring in the future.

So I guess that we may as well break the lsm list into an array of
strings with strtok() in the setup and add a function that loops on the
array and does strcmp() for each entry in that array.

> +			tst_res(TFAIL, "'%s' has not been found", name);
> +		else
> +			tst_res(TPASS, "'%s' is enabled", name);
> +	}
> +
> +	TST_EXP_EQ_LI(*size, counter * sizeof(uint64_t));

So we get literal size in the size and number of elements as the return
value. Sounds good.

> +	TST_EXP_EQ_LI(lsm_num, counter);

Isn't this true by definition? We do tst_brk(TBROK, "") on unknown lsm
so if the counter is not increased on each lsm_num iteration we exit the
test with tst_brk() and never reach this line.

And hat is actually missing here is to compare the number of lsm names
in the /sys/kernel/security/lsm file with the lsm_num. But for that we
have to break the file content into tokens and count them, which we need
to do anyways.

> +}
> +
> +static void setup(void)
> +{
> +	int fd;
> +
> +	page_size = SAFE_SYSCONF(_SC_PAGESIZE);
> +	fd = SAFE_OPEN("/sys/kernel/security/lsm", O_RDONLY);
> +	SAFE_READ(0, fd, lsm_list, BUFSIZ);
> +	SAFE_CLOSE(fd);
> +}
> +
> +static struct tst_test test = {
> +	.test_all = run,
> +	.setup = setup,
> +	.min_kver = "6.8",
> +	.bufs = (struct tst_buffers []) {
> +		{&ids, .size = sizeof(uint64_t) * MAX_LSM_NUM},
> +		{&size, .size = sizeof(uint32_t)},
> +		{},
> +	},
> +};
> 
> -- 
> 2.43.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list