public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: Fiona Ebner <f.ebner@proxmox.com>
Cc: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] applied-series: [PATCH pmg-api 1/2] cluster config: restrict slurp scope to avoid issue parsing network interfaces
Date: Tue, 11 Jul 2023 10:33:33 +0200	[thread overview]
Message-ID: <20230711103333.4c99fd9a@rosa.proxmox.com> (raw)
In-Reply-To: <20230710113647.53879-1-f.ebner@proxmox.com>

hi,

huge thanks for your persistence and patience while digging into this -
great find!

applied both patches to master and stable-7 (after verifying that it's
affected as well :)


On Mon, 10 Jul 2023 13:36:46 +0200
Fiona Ebner <f.ebner@proxmox.com> wrote:

> As reported in the community forum [0], there is an edge case, where
> querying the network interfaces would not work. In particular, this
> could happen if the hostname cannot be resolved to a non-loopback IP
> (when installing PMG on Debian and forgetting to adapt /etc/hosts for
> example).
> 
> The issue manifested as follows:
> - When setting up the RESTEnvironemnt, the cluster config is read.
> - This reader uses slurp mode by setting the line ending to undef
>   locally.
> - But the subroutine call PVE::Network::get_local_ip() is still part
>   of that local context.
> - When resolving the hostname to a non-loopback IP address failed, the
>   function would read (via the PVE::INotify module) the network
>   interfaces file.
> - As part of that, /proc/net/dev was read all at once, while the
>   interface parsing code expects it line-by-line.
> - The result for reading network interfaces was cached without having
>   detected the interfaces in /proc/net/dev.
> - When a new request came in, the cached result was used (even
>   changing the file to invalidate the cache would only work as long
>   as the cluster config file exists, because otherwise, there would be
>   an attempt to read the cluster config which would read the updated
>   version of the interfaces file while slurping again).
> 
> [0]: https://forum.proxmox.com/threads/129958/
> 
> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
> ---
>  src/PMG/ClusterConfig.pm | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/src/PMG/ClusterConfig.pm b/src/PMG/ClusterConfig.pm
> index 77b9e60..c52508d 100644
> --- a/src/PMG/ClusterConfig.pm
> +++ b/src/PMG/ClusterConfig.pm
> @@ -170,9 +170,7 @@ sub lock_config {
>  sub read_cluster_conf {
>      my ($filename, $fh) = @_;
>  
> -    local $/ = undef; # slurp mode
> -
> -    my $raw = defined($fh) ? <$fh> : undef;
> +    my $raw = defined($fh) ? do { local $/ = undef; <$fh> } : undef;
>  
>      my $cinfo = PMG::ClusterConfig::Base->parse_config($filename, $raw);
>  





      parent reply	other threads:[~2023-07-11  8:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-10 11:36 [pmg-devel] " Fiona Ebner
2023-07-10 11:36 ` [pmg-devel] [PATCH pmg-api 2/2] tree-wide: make slurp mode as local as possible for future-proofing Fiona Ebner
2023-07-11  8:33 ` Stoiko Ivanov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230711103333.4c99fd9a@rosa.proxmox.com \
    --to=s.ivanov@proxmox.com \
    --cc=f.ebner@proxmox.com \
    --cc=pmg-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal