From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6C4BDA0547; Wed, 16 Nov 2022 00:53:51 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0F70240E03; Wed, 16 Nov 2022 00:53:51 +0100 (CET) Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by mails.dpdk.org (Postfix) with ESMTP id 5E0A840DFB for ; Wed, 16 Nov 2022 00:53:49 +0100 (CET) Received: by mail-pg1-f169.google.com with SMTP id f3so8669215pgc.2 for ; Tue, 15 Nov 2022 15:53:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=EumMtVALrwjmyPQZ7S8d/5MM3yUtPO0U9n3+X9e/bZ8=; b=hgekNFhbwb7uXodaQBWdriR3gGTir5dfJu1Ihbe8/SrtYYyx6bzS1Y0fiJxKJyy7sx +xBwJ6O1jXl/rrcAmdngOC3SeLnCam7S9dThBSoI3wWHeAd/Pq5WSYDlQLdFc7dN7qDJ 6YW5UdL6/J5YRNzUIKn+mlsGtpslJoF71k4XxGge8+myLU7KF6uF/vmbtZBqX0tBVyC0 bZeNRT3kNzip0ZelBrgcO1+pUoz+Fqg/OPpgNPOcpR6HcjcUsDkYEqPrPHkywdaB/nWj Wdt44jq93kGt5h1Hkl6MCY97agFBBkOr5YPe8qUqdgv9U+fF/xNRlzgVFZNvBsn6KZVF JZPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EumMtVALrwjmyPQZ7S8d/5MM3yUtPO0U9n3+X9e/bZ8=; b=YThLqD/s/wPRCIbM6NMNqxovF7PG4txt9EHowz66+lO7RQFMm11Mm9UM/lO+hEpOw9 vJHCpRcTrliKuUOmf2I68I27KXY2eWQnow+F5x3EImogmcNQpui1AkzGHbWXnQjihb4G gK+Y82rxnS2C6eiuzemhmOBKUWHwklx66nlIxKbm0mBowHzHbuHlHYJXInQW9xOC08pF 8DSmPy4pKXYzqjOI+Z3zWneSNHi5JuW+Sfpb7602YCcKEAmcBRL8GIxjmEHfjbT1D+hy umXPW8zHDouKAggBeNlK24xX5EEfCLqyTYt1EYQIr4eS4NeNKXtj205SNdLSoOR5Ary5 Seyw== X-Gm-Message-State: ANoB5pm2/tEwM6Fko+KqJWCsRw4KafkFHF4Zk9H1l0tqItfUY42pYxL/ LXqaum8sWngNgO4OAIXaGDBSH5VsWBPxVw== X-Google-Smtp-Source: AA0mqf6ChT+H9bucZ0OEbrSS41PqC7/dgjiibsEwN9u+OMQu9mYETcyRKkBbEyIDwD/YVER072OKJg== X-Received: by 2002:a65:4d4b:0:b0:476:df56:b35e with SMTP id j11-20020a654d4b000000b00476df56b35emr1590699pgt.449.1668556428390; Tue, 15 Nov 2022 15:53:48 -0800 (PST) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id o68-20020a17090a0a4a00b002008d0e5cb5sm123306pjo.47.2022.11.15.15.53.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Nov 2022 15:53:48 -0800 (PST) Date: Tue, 15 Nov 2022 15:53:44 -0800 From: Stephen Hemminger To: Junxiao Shi Cc: dev@dpdk.org Subject: Re: [RFC PATCH] net/memif: change socket listener owner uid/gid Message-ID: <20221115155344.17a5ed4c@hermes.local> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Tue, 15 Nov 2022 20:44:41 +0000 Junxiao Shi 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; }