[LTP] [PATCH v2] Add listxattr04 reproducer
Wei Gao
wegao@suse.com
Wed Jul 9 17:25:16 CEST 2025
On Mon, Jul 07, 2025 at 11:46:29AM +0200, Cyril Hrubis wrote:
> Hi!
> > > + tst_res(TFAIL, "listxattr() failed to read attributes length: ERANGE");
> > > + return;
> > Why ERANGE is Checked Separately?
> > Such as tst_res(TFAIL | TERRNO, "listxattr() error") will also report
> > errno.
>
> Because with ERANGE we reproduced the bug and return TFAIL while with
> any other errno we report TBROK.
>
> > > + }
> > > +
> > > + tst_res(TPASS, "listxattr() correctly read attributes length");
> > > +}
> > > +
> > > +static void run(void)
> > > +{
> > > + int size;
> > > +
> > > + size = listxattr(TEST_FILE, NULL, 0);
> > > + if (size == -1)
> > > + tst_brk(TBROK | TERRNO, "listxattr() error");
> > > +
> > > + verify_xattr(size);
> > > +}
> > > +
> > > +static int selinux_enabled(void)
> > > +{
> > > + uint32_t lsm_num;
> > > + uint64_t ids[32];
> > > + uint32_t page_size;
> > > + int available = 0;
> > > +
> > > + page_size = SAFE_SYSCONF(_SC_PAGESIZE);
> > > +
> > > + lsm_num = lsm_list_modules(ids, &page_size, 0);
> > > + if (!lsm_num)
> > > + return 0;
> > > +
> > > + for (uint32_t i = 0; i < lsm_num; i++) {
> > > + if (ids[i] == LSM_ID_SELINUX) {
> > > + available = 1;
> > > + break;
> > > + }
> > > + }
> > > +
> > > + return available;
> > > +}
> > > +
> > > +static void setup(void)
> > > +{
> > > + int res;
> > > +
> > > + if (!selinux_enabled())
> > Mabye we can use is_selinux_enabled instead of self build function?
>
> That mean that we have to compile the test again one more library. I
> would rather add tst_selinux_enabled() into the test library. We already
> have tst_selinux_enforcing() there anyways. That should be as easy as
> reading another file in /sys/fs/selinux/.
Got it. Also agree with using an easy way to check selinux status.
>
> --
> Cyril Hrubis
> chrubis@suse.cz
More information about the ltp
mailing list