Skip to contentSkip to conversation

selftests/landlock: Add tests for audit flags and domain IDs

bug report Dan Carpenter 1 participant 1 message May 28, 2025 Kselftest

lore
Share & tools
lore
#0 lore raw

Hello Mickaël Salaün,

Commit 6a500b22971c ("selftests/landlock: Add tests for audit flags and domain IDs") from Mar 20, 2025 (linux-next), leads to the following Smatch static checker warning:

	tools/testing/selftests/landlock/audit.h:408 audit_init_filter_exe()
	warn: unsigned 'filter->exe_len' is never less than zero.

tools/testing/selftests/landlock/audit.h

    399 static int audit_init_filter_exe(struct audit_filter *filter, const char *path)
    400 {
    401         char *absolute_path = NULL;
    402 
    403         /* It is assume that there is not already filtering rules. */
    404         filter->record_type = AUDIT_EXE;
    405         if (!path) {
    406                 filter->exe_len = readlink("/proc/self/exe", filter->exe,
    407                                            sizeof(filter->exe) - 1);

--> 408 if (filter->exe_len < 0)

size_t can't be negative.

    409                         return -errno;
    410 
    411                 return 0;
    412         }
    413 
    414         absolute_path = realpath(path, NULL);
    415         if (!absolute_path)
    416                 return -errno;
    417 
    418         /* No need for the terminating NULL byte. */
    419         filter->exe_len = strlen(absolute_path);
    420         if (filter->exe_len > sizeof(filter->exe))
    421                 return -E2BIG;
    422 
    423         memcpy(filter->exe, absolute_path, filter->exe_len);
    424         free(absolute_path);
    425         return 0;
    426 }

regards,
dan carpenter