[{"id":1157,"web_url":"https://patchwork.libcamera.org/comment/1157/","msgid":"<20190401204142.GF4787@pendragon.ideasonboard.com>","date":"2019-04-01T20:41:42","subject":"Re: [libcamera-devel] [PATCH v2 4/4] libcamera: utils: Use internal\n\tsecure_getenv() implementation","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the patch.\n\nOn Mon, Apr 01, 2019 at 06:03:15PM +0700, Kieran Bingham wrote:\n> The secure_getenv() call is not provided by all toolchains. Support\n\ns/toolchains/C libraries/ ?\n\n> this feature by implementing our own version.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>  src/libcamera/include/utils.h |  2 ++\n>  src/libcamera/log.cpp         |  4 ++--\n>  src/libcamera/utils.cpp       | 20 ++++++++++++++++++++\n>  3 files changed, 24 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h\n> index 1b2a62c0fda7..79038a96feab 100644\n> --- a/src/libcamera/include/utils.h\n> +++ b/src/libcamera/include/utils.h\n> @@ -24,6 +24,8 @@ std::unique_ptr<T> make_unique(Args&&... args)\n>  \treturn std::unique_ptr<T>(new T(std::forward<Args>(args)...));\n>  }\n>  \n> +char *secure_getenv(const char *name);\n> +\n>  } /* namespace utils */\n>  \n>  } /* namespace libcamera */\n> diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp\n> index eb444c31857d..71cfbc422ba0 100644\n> --- a/src/libcamera/log.cpp\n> +++ b/src/libcamera/log.cpp\n> @@ -122,7 +122,7 @@ Logger::Logger()\n>   */\n>  void Logger::parseLogFile()\n>  {\n> -\tconst char *file = secure_getenv(\"LIBCAMERA_LOG_FILE\");\n> +\tconst char *file = utils::secure_getenv(\"LIBCAMERA_LOG_FILE\");\n>  \tif (!file)\n>  \t\treturn;\n>  \n> @@ -140,7 +140,7 @@ void Logger::parseLogFile()\n>   */\n>  void Logger::parseLogLevels()\n>  {\n> -\tconst char *debug = secure_getenv(\"LIBCAMERA_LOG_LEVELS\");\n> +\tconst char *debug = utils::secure_getenv(\"LIBCAMERA_LOG_LEVELS\");\n>  \tif (!debug)\n>  \t\treturn;\n>  \n> diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\n> index 70936e36c5d5..c49e65136514 100644\n> --- a/src/libcamera/utils.cpp\n> +++ b/src/libcamera/utils.cpp\n> @@ -6,6 +6,7 @@\n>   */\n>  \n>  #include <string.h>\n> +#include <sys/auxv.h>\n>  \n>  #include \"utils.h\"\n>  \n> @@ -35,6 +36,25 @@ const char *basename(const char *path)\n>         return base ? base + 1 : path;\n>  }\n>  \n> +/**\n> + * \\brief Get an environment variable\n> + *\n> + * The environment list is searched to find the variable 'name', and returns a\n> + * pointer to the corresponding string.\n\nThe first half of the sentence doesn't seem to provide a subject for\n\"returns\" in the second half.\n\n> + * If 'secure execution' is required then this function always returns NULL to\n> + * avoid vulnerabilities that could occur if the set-user-ID or set-group-ID\n\ns/if the/if/\n\n> + * programs accidentally trusted the environment.\n> + *\n> + * \\returns A pointer to the value in the environment or NULL if the match fails\n> + * or a secure environment is required.\n\n\"..., or NULL if the requested environment variable doesn't exist or if\nsecure execution is required.\" ?\n\n> + */\n> +char *secure_getenv(const char *name)\n> +{\n> +       if (getauxval(AT_SECURE))\n> +               return NULL;\n> +       else\n\nYou can drop the else.\n\nWith these small issues fixed,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +               return getenv(name);\n> +}\n>  \n>  /**\n>   * \\fn libcamera::utils::make_unique(Args &&... args)","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8D240610B3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  1 Apr 2019 22:41:54 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1F456542;\n\tMon,  1 Apr 2019 22:41:53 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1554151313;\n\tbh=qwBskeMdE96I526t4UsH4kCTgxo0ak0khMPTYd7YPQA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=iQRbNe+LiOZtUzxrdc20ldO8yErjCZK65Tyz6eOATW4yxBVBJXUNjjso3/yLXJGgz\n\tfaSBoBKI7BXQ+C7AAMEdBZ51IJpy79alcGGPx45R2sHzqBTiPP6z9PxgUdMyXHEWwq\n\t2mrUeikQv6b4M8qXNSrHsFdfELcNKBm+o4e2EgiM=","Date":"Mon, 1 Apr 2019 23:41:42 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Message-ID":"<20190401204142.GF4787@pendragon.ideasonboard.com>","References":"<20190401110315.4148-1-kieran.bingham@ideasonboard.com>\n\t<20190401110315.4148-5-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190401110315.4148-5-kieran.bingham@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v2 4/4] libcamera: utils: Use internal\n\tsecure_getenv() implementation","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Mon, 01 Apr 2019 20:41:54 -0000"}},{"id":1236,"web_url":"https://patchwork.libcamera.org/comment/1236/","msgid":"<6745935c-7771-c509-e260-de42bea244bf@ideasonboard.com>","date":"2019-04-03T03:54:28","subject":"Re: [libcamera-devel] [PATCH v2 4/4] libcamera: utils: Use internal\n\tsecure_getenv() implementation","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Laurent,\n\nOn 01/04/2019 21:41, Laurent Pinchart wrote:\n> Hi Kieran,\n> \n> Thank you for the patch.\n> \n> On Mon, Apr 01, 2019 at 06:03:15PM +0700, Kieran Bingham wrote:\n>> The secure_getenv() call is not provided by all toolchains. Support\n> \n> s/toolchains/C libraries/ ?\n\nSure. Also changed in the documentation of basename().\n\n>> this feature by implementing our own version.\n>>\n>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>> ---\n>>  src/libcamera/include/utils.h |  2 ++\n>>  src/libcamera/log.cpp         |  4 ++--\n>>  src/libcamera/utils.cpp       | 20 ++++++++++++++++++++\n>>  3 files changed, 24 insertions(+), 2 deletions(-)\n>>\n>> diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h\n>> index 1b2a62c0fda7..79038a96feab 100644\n>> --- a/src/libcamera/include/utils.h\n>> +++ b/src/libcamera/include/utils.h\n>> @@ -24,6 +24,8 @@ std::unique_ptr<T> make_unique(Args&&... args)\n>>  \treturn std::unique_ptr<T>(new T(std::forward<Args>(args)...));\n>>  }\n>>  \n>> +char *secure_getenv(const char *name);\n>> +\n>>  } /* namespace utils */\n>>  \n>>  } /* namespace libcamera */\n>> diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp\n>> index eb444c31857d..71cfbc422ba0 100644\n>> --- a/src/libcamera/log.cpp\n>> +++ b/src/libcamera/log.cpp\n>> @@ -122,7 +122,7 @@ Logger::Logger()\n>>   */\n>>  void Logger::parseLogFile()\n>>  {\n>> -\tconst char *file = secure_getenv(\"LIBCAMERA_LOG_FILE\");\n>> +\tconst char *file = utils::secure_getenv(\"LIBCAMERA_LOG_FILE\");\n>>  \tif (!file)\n>>  \t\treturn;\n>>  \n>> @@ -140,7 +140,7 @@ void Logger::parseLogFile()\n>>   */\n>>  void Logger::parseLogLevels()\n>>  {\n>> -\tconst char *debug = secure_getenv(\"LIBCAMERA_LOG_LEVELS\");\n>> +\tconst char *debug = utils::secure_getenv(\"LIBCAMERA_LOG_LEVELS\");\n>>  \tif (!debug)\n>>  \t\treturn;\n>>  \n>> diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\n>> index 70936e36c5d5..c49e65136514 100644\n>> --- a/src/libcamera/utils.cpp\n>> +++ b/src/libcamera/utils.cpp\n>> @@ -6,6 +6,7 @@\n>>   */\n>>  \n>>  #include <string.h>\n>> +#include <sys/auxv.h>\n>>  \n>>  #include \"utils.h\"\n>>  \n>> @@ -35,6 +36,25 @@ const char *basename(const char *path)\n>>         return base ? base + 1 : path;\n>>  }\n>>  \n>> +/**\n>> + * \\brief Get an environment variable\n>> + *\n>> + * The environment list is searched to find the variable 'name', and returns a\n>> + * pointer to the corresponding string.\n> \n> The first half of the sentence doesn't seem to provide a subject for\n> \"returns\" in the second half.\n\nReworded to:\n\n\n> /**\n>  * \\brief Get an environment variable\n>  * \\param[in] name The name of the variable to return\n>  *\n>  * The environment list is searched to find the variable 'name', and the\n>  * corresponding string is returned.\n>  *\n>  * If 'secure execution' is required then this function always returns NULL to\n>  * avoid vulnerabilities that could occur if set-user-ID or set-group-ID\n>  * programs accidentally trust the environment.\n>  *\n>  * \\returns A pointer to the value in the environment or NULL if the requested\n>  * environment variable doesn't exist or if secure execution is required.\n>  */\n> char *secure_getenv(const char *name)\n\n\nwhich also incorporates the comments below...\n\n> \n>> + * If 'secure execution' is required then this function always returns NULL to\n>> + * avoid vulnerabilities that could occur if the set-user-ID or set-group-ID\n> \n> s/if the/if/\n> \n>> + * programs accidentally trusted the environment.\n>> + *\n>> + * \\returns A pointer to the value in the environment or NULL if the match fails\n>> + * or a secure environment is required.\n> \n> \"..., or NULL if the requested environment variable doesn't exist or if\n> secure execution is required.\" ?\n> \n>> + */\n>> +char *secure_getenv(const char *name)\n>> +{\n>> +       if (getauxval(AT_SECURE))\n>> +               return NULL;\n>> +       else\n> \n> You can drop the else.\n\nDone.\n\n\n> With these small issues fixed,\n> \n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n>> +               return getenv(name);\n>> +}\n>>  \n>>  /**\n>>   * \\fn libcamera::utils::make_unique(Args &&... args)","headers":{"Return-Path":"<kieran.bingham@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1428D610B3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Apr 2019 05:54:38 +0200 (CEST)","from [10.71.11.124] (unknown [147.50.13.10])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4FB722F9;\n\tWed,  3 Apr 2019 05:54:35 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1554263677;\n\tbh=miTEe0rWzF1W6yWkMNylhfi7k0+iRcHX6uNBcz1AknE=;\n\th=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From;\n\tb=bTUwp4/s/mHFEs1KbRo/dwb9IdoiU6N76Ukja1Wzj//CT+G0js9ooxEXWB+KndK7J\n\tm7/OBbD9GGEAhsVw6/iWUDFJu5L8rgaOG7RSeBRb7me5e70AatwCpaEWdsnys4y54W\n\tiEg/azza6beKZAWRSinlKMnJGSrwz9qMrkefLkyE=","Reply-To":"kieran.bingham@ideasonboard.com","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","References":"<20190401110315.4148-1-kieran.bingham@ideasonboard.com>\n\t<20190401110315.4148-5-kieran.bingham@ideasonboard.com>\n\t<20190401204142.GF4787@pendragon.ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Openpgp":"preference=signencrypt","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\tmQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat\n\tV/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC\n\trRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C\n\tpotzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465sCsiQ\n\tcSAZRxqE49RTBq2+EQsbrQpIc8XiffAB8qexh5/QPzCmR4kJgCGeHIXBtgRj+nIkCJPZvZtf\n\tKr2EAbc6tgg6DkAEHJb+1okosV09+0+TXywYvtEop/WUOWQ+zo+Y/OBd+8Ptgt1pDRyOBzL8\n\tRXa8ZqRf0Mwg75D+dKntZeJHzPRJyrlfQokngAAs4PaFt6UfS+ypMAF37T6CeDArQC41V3ko\n\tlPn1yMsVD0p+6i3DPvA/GPIksDC4owjnzVX9kM8Zc5Cx+XoAN0w5Eqo4t6qEVbuettxx55gq\n\t8K8FieAjgjMSxngo/HST8TpFeqI5nVeq0/lqtBRQKumuIqDg+Bkr4L1V/PSB6XgQcOdhtd36\n\tOe9X9dXB8YSNt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NCsMTqeUkAKfbD8xW4LCay3r/dD2ckoxRxtMD9eOAyu5wYzo/ydIPTh1QEj9SYyvp8\n\tO0g6CpxEwyHUQtF5oh15O018z3ZLztFJKR3RD42VKVsrnNDKnoY0f4U0z7eJv2NeF8xHMuiU\n\tRCIzqxX1GVYaNkKTnb/Qja8hnYnkUzY1Lc+OtwiGmXTwYsPZjjAaDX35J/RSKAoy5wGo/YFA\n\tJxB1gWThL4kOTbsqqXj9GLcyOImkW0lJGGR3o/fV91Zh63S5TKnf2YGGGzxki+ADdxVQAm+Q\n\tsbsRB8KNNvVXBOVNwko86rQqF9drZuw=","Organization":"Ideas on Board","Message-ID":"<6745935c-7771-c509-e260-de42bea244bf@ideasonboard.com>","Date":"Wed, 3 Apr 2019 10:54:28 +0700","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101\n\tThunderbird/60.5.1","MIME-Version":"1.0","In-Reply-To":"<20190401204142.GF4787@pendragon.ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [PATCH v2 4/4] libcamera: utils: Use internal\n\tsecure_getenv() implementation","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Wed, 03 Apr 2019 03:54:38 -0000"}}]