[LTP] [PATCH 1/2] lib: Add checking of needs_root

Petr Vorel pvorel@suse.cz
Wed Oct 12 13:33:18 CEST 2022


Hi all,

The subject "lib: Add checking of needs_root" is a bit misleading
as it does not mention at all that it's for the loop device.

> We need to check needs_root is set when tst_test->needs_device or
> tst_test->mount_device is set since access the /dev/* need a
> privilege.

FYI we had some discussion about it, quoting Cyril [1]:

	Well technically you can be added into whatever group is set to
	/dev/loop-control e.g. disk group and then you can create devices
	without a need to be a root.

	So the most correct solution would be checking if we can access
	/dev/loop-control if tst_test.needs_device is set and if not we would
	imply needs_root. However this would need to be rethinked properly so
	that we do not end up creating something complex and not really
	required.

There is also possibility to add custom device via $LTP_DEV. That might allow to
add permissions which allow to test without root.

I'll write to automated-testing ML (and maybe to LKML ML) to see if people
prefers to test without non-root.

Also, if changed, we'd need the same change for C API.

Kind regards,
Petr

[1] https://lore.kernel.org/ltp/Yx8I0ponDUIFC8le@yuki/

> Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
> ---
>  lib/tst_test.c | 5 +++++
>  1 file changed, 5 insertions(+)

> diff --git a/lib/tst_test.c b/lib/tst_test.c
> index 8ccde1629..728a1d921 100644
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -1196,6 +1196,11 @@ static void do_setup(int argc, char *argv[])
>  		tst_brk(TBROK, "tst_test->mntpoint must be set!");
>  	}

> +	if ((tst_test->needs_device || tst_test->mount_device) &&
> +	     !tst_test->needs_root) {
> +		tst_brk(TBROK, "tst_test->needs_root must be set!");
> +	}
> +
>  	if (!!tst_test->needs_rofs + !!tst_test->needs_devfs +
>  	    !!tst_test->needs_device > 1) {
>  		tst_brk(TBROK,


More information about the ltp mailing list