[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Kernel key retention facility: can someone run this test for me?



Hi,

Could someone with access to a sparc host run the attached test case for
me, and send me the output? Getting porterbox access + package
installation as a non-DD seems overkill for just this test case.

Regards,
Christian

PS: Please CC: me as I am not subscribed to the list.
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <keyutils.h>

/*
 * Create a description with a length of PAGESIZE*2, and request a new keyring
 * with that description. According to the test definitions, this should fail.
 *
 * Within Debian, however, this succeeds on mips, mipsel, and sparc.
 * This has been observed with various kernel versions, from 3.2 to 3.14.
 *
 *   $ sudo apt-get install libkeyutils-dev
 *   $ gcc -o desclentest -lkeyutils overlong-desc-does-not-fail.c
 *   $ ./desclentest
 */

int main(int argc, char **argv)
{
	size_t pagesize, descsize;
	key_serial_t key;
	char *desc, *buffer;
	int dpos, n, ret;

	pagesize = sysconf(_SC_PAGESIZE);
	descsize = pagesize*2;

	if ((desc = malloc(descsize)) == NULL) {
		perror("malloc");
		exit(2);
	}
	memset(desc, 'a', descsize);
	desc[descsize-1] = '\0';

	key = add_key("keyring", desc, NULL, 0, KEY_SPEC_PROCESS_KEYRING);
	if (key < 0) {
		printf("Overlong description allocation failed as expected\n");
		exit(0);
	}

	printf("Created key with overlong description (pagesize x 2)\n");

	/* get key description */
	ret = keyctl_describe_alloc(key, &buffer);
	if (ret < 0) {
		perror("keyctl_describe_alloc");
		exit(1);
	}

	dpos = -1;
	n = sscanf(buffer, "%*[^;]%*n;%*d;%*d;%*x;%n", &dpos);
	if (n != 0) {
		fprintf(stderr, "Unparseable description obtained for key %d\n", key);
		exit(3);
	}
	printf("Read key with %d length\n", (int) strlen(buffer+dpos));
	exit(0);
}

Reply to: