[RFC PATCH] net/memif: change socket listener owner uid/gid
Stephen Hemminger
stephen at networkplumber.org
Wed Nov 16 00:53:44 CET 2022
On Tue, 15 Nov 2022 20:44:41 +0000
Junxiao Shi <git at mail1.yoursunny.com> wrote:
> +static int
> +memif_set_owner_uid(const char *key __rte_unused, const char *value, void *extra_args)
> +{
> + uid_t *uid = (uid_t *)extra_args;
> + *uid = strtoul(value, NULL, 10);
> + return 0;
> +}
> +
> +static int
> +memif_set_owner_gid(const char *key __rte_unused, const char *value, void *extra_args)
> +{
> + gid_t *gid = (gid_t *)extra_args;
> + *gid = strtoul(value, NULL, 10);
> + return 0;
> +}
> +
This should be one function and it should check for valid arguments.
Things like not a number, extra characters, and out of range.
Modern Linux allows 32 bits of uid. with some values like -1 reserved.
On a 64 bit system like most DPDK usage, sizeof(unsigned long) is 64 bits.
Since uid and gid have same restrictions, then something like this (untested):
static int strtouid(const char *value, uint32_t *id)
{
unsigned long val;
char *endp;
val = strtoul(value, &endp, 10);
if (*value == '\0' || *endp != '\0')
return -EINVAL;
if (val >= UINT32_MAX)
return -ERANGE;
*id = val;
return 0;
}
More information about the dev
mailing list