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

Petr Vorel pvorel@suse.cz
Fri Sep 18 12:59:07 CEST 2026


Hi Li Cyril,

> > > 	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?

> Well we can always allocate large enough buffer in the test setup.

Do you agree with these changes?
BTW it'd be nice to get this merged before git freeze, but that's today night.

Kind regards,
Petr

+++ testcases/kernel/syscalls/keyctl/keyctl15.c
@@ -12,15 +12,16 @@
  *
  * [Algorithm]
  *
- * - read the label of a valid key into a large buffer, verify the return
- *   value is at least 1 and an empty string is returned when no label is set
+ * - read the label of a valid key into a large buffer
+ * - verify the return value is at least 1 and an empty string is returned when
+ *   no label is set
  */
 
 #include "keyctl_common.h"
 
 #define KEY_DESC	"ltpkeyctl15"
 #define PAYLOAD		"payload"
-#define BUF_SIZE	128
+#define BUF_SIZE	256
 
 static key_serial_t key;
 static char buf[BUF_SIZE];
@@ -42,20 +43,17 @@ static void run(void)
 
 	rc = SAFE_KEYCTL(KEYCTL_GET_SECURITY, key, (unsigned long)buf, sizeof(buf), 0);
 
-	if (buf[0] != '\0')
-		tst_res(TFAIL, "empty label is not NUL terminated");
-
-	if (rc < 1) {
-		tst_res(TFAIL, "returned %d, expected >= 1", rc);
+	if (rc == 0) {
+		tst_res(TFAIL, "empty security label not NUL terminated");
 		return;
 	}
 
-	if (rc == 1) {
-		tst_res(TPASS, "no label set, empty string returned");
+	if (buf[rc-1] != '\0') {
+		tst_res(TFAIL, "security label not NUL terminated");
 		return;
 	}
 
-	tst_res(TPASS, "security label returned, full length %d", rc);
+	tst_res(TPASS, "Security label was NUL terminated");
 }
 
 static struct tst_test test = {


More information about the ltp mailing list