[LTP] [PATCH v3 09/36] keyctl15: Test KEYCTL_GET_SECURITY label retrieval

Li Wang li.wang@linux.dev
Fri Sep 18 07:01:54 CEST 2026


On Thu, Sep 17, 2026 at 01:50:39PM +0200, Cyril Hrubis wrote:
> Hi!
> > Maybe refine it like below:
> > 
> > static void run(void)
> > {
> > 	int rc;
> > 
> > 	memset(buf, 0, sizeof(buf));
> > 
> > 	rc = SAFE_KEYCTL(KEYCTL_GET_SECURITY, key, (unsigned long)buf, sizeof(buf), 0);
> > 
> > 	if (rc < 1) {
> > 		tst_res(TFAIL, "returned %d, expected >= 1", rc);
> > 		return;
> > 	}
> > 
> > 	if (rc == 1) {
> > 		if (buf[0] != '\0')
> > 			tst_res(TFAIL, "empty label is not NUL terminated");
> > 		else
> > 			tst_res(TPASS, "no label set, empty string returned");
> > 		return;
> > 	}
> > 
> > 	if (buf[0] == '\0')
> > 		tst_res(TFAIL, "non-empty label is NUL terminated");
> > 	else
> > 		tst_res(TPASS, "security label returned, full length %d", rc);
> > }
> 
> Shouldn't we check that the security label is NUL terminated as well?
> 
> The algorithm description in the doc comment actually says what should
> be done:

Yes, you're right.

> 
> 	if (rc == 0) {
> 		tst_res(TFAIL, "empty security label not NUL terminated");
> 		return;
> 	}
> 
> 	if (rc > sizeof(buf)) {
> 		tst_res(TFAIL, "buffer too small");
> 		return;
> 	}

My only concern is whether the TFAIL is correct when truncation
occurs. Shouldn't the test allocate a larger buffer instead?

The rest looks good.

-- 
Regards,
Li Wang


More information about the ltp mailing list