[LTP] [PATCH v2 4/7] Add lsm_get_self_attr03 test
Cyril Hrubis
chrubis@suse.cz
Mon Apr 28 16:50:35 CEST 2025
Hi!
> >> + count = TST_EXP_POSITIVE(
> >> + lsm_get_self_attr(LSM_ATTR_CURRENT, ctx, &size, 0));
> > ^
> > This does not
> > look right.
> >
> >
> > Shouldn't we pass size initialized to size of the ctx->ctx[] there?
> >
> > You are mixing the size of the attr[] array and the size of the ctx
> > into a single variable which isn't right at all. The attr[] size can
> > also be much smaller, since it's just a single string.
>
> This is how kselftests are working as well, so I'm a bit confused.
> According to the documentation of lsm_get_self_attr:
>
> * @size: pointer to the size of space available to receive the data
>
> I guess kselftests are giving a bare minimum size according to the
> memory pages.
No the kselftests work, your code does not. The kselftests use the
struct lsm_ctx from /usr/include/linux/lsm.h:
struct lsm_ctx {
__u64 id;
__u64 flags;
__u64 len;
__u64 ctx_len;
__u8 ctx[] __counted_by(ctx_len);
};
Where the ctx array is dynamically sized.
While your fallback declares the structure with the ctx to be statically
sized (lapi/lsm.h):
struct lsm_ctx {
uint64_t id;
uint64_t flags;
uint64_t len;
uint64_t ctx_len;
uint8_t ctx[4096];
};
This is simply wrong because:
- the deifitiontions does not match
- the size of ctx->ctx in case from the system definition is 0
- and page_size != 4k in all cases
So the only good solution is to:
- match the definition of the fallback to the system structure
- define the size in the header somewhere
- use the defined size both for allocation and size initialization
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list