[LTP] [PATCH v2] landlock04: Fix false TFAIL in _test_truncate() deny path

Petr Vorel pvorel@suse.cz
Tue Aug 25 06:38:16 CEST 2026


Hi Avinesh,

Thanks for the fix, merged!

I'm sorry for introducing the regression (I tested whole landlock part, but
obviously wrongly when this one slipped in).
...
>  	TST_EXP_PASS_OR_FAIL(truncate(FILE_TRUNCATE, 10), exp_err);
> -	fd = TST_EXP_FD_OR_FAIL(open(FILE_TRUNCATE, O_WRONLY, PERM_MODE), exp_err);
> +
> +	if (!exp_err) {
> +		fd = SAFE_OPEN(FILE_TRUNCATE, O_WRONLY, PERM_MODE);
> +	} else {
> +		fd = open(FILE_TRUNCATE, O_WRONLY, PERM_MODE);
> +		if (fd == -1 && errno != EACCES)
> +			 tst_res(TFAIL | TERRNO, "open(%s, O_WRONLY) failed unexpectedly", FILE_TRUNCATE);

nit: there still could have been TST_EXP_FD_OR_FAIL() for else part:

fd = TST_EXP_FD_OR_FAIL(open(FILE_TRUNCATE, O_WRONLY, PERM_MODE), exp_err);

I personally prefer these shortening macros, but maybe they aren't that much
readable when others don't use it. Therefore merged as is.

Kind regards,
Petr

> +	}
>  	if (fd != -1) {
>  		TST_EXP_PASS_OR_FAIL(ftruncate(fd, 10), exp_err);
>  		SAFE_CLOSE(fd);
> @@ -262,7 +269,7 @@ static void _test_truncate(const int exp_err)

>  	fd = TST_EXP_FD_OR_FAIL(open(FILE_TRUNCATE, O_WRONLY | O_TRUNC, PERM_MODE), exp_err);
>  	if (fd != -1)
> -		SAFE_CLOSE(TST_RET);
> +		SAFE_CLOSE(fd);
>  }


More information about the ltp mailing list