public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Subject: Re: [PATCH 5/5] resolv: Fix ABA race in /etc/resolv.conf change detection [BZ #25420]
Date: Thu, 13 Feb 2020 21:59:00 -0000	[thread overview]
Message-ID: <0728f253-b851-d9d5-7c9b-a1a514600afc@linaro.org> (raw)
In-Reply-To: <95b81fd1ccd9d41c4f6a897a1c43d1298da0486e.1579631655.git.fweimer@redhat.com>



On 21/01/2020 15:42, Florian Weimer wrote:
> __resolv_conf_get_current should only record the initial file
> change data if after verifying that file just read matches the
> original measurement.  Fixes commit aef16cc8a4c670036d45590877
> ("resolv: Automatically reload a changed /etc/resolv.conf file
> [BZ #984]").

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

> ---
>  resolv/resolv_conf.c | 19 +++++++++++++------
>  1 file changed, 13 insertions(+), 6 deletions(-)
> 
> diff --git a/resolv/resolv_conf.c b/resolv/resolv_conf.c
> index bdd2ebb909..29a1f4fb94 100644
> --- a/resolv/resolv_conf.c
> +++ b/resolv/resolv_conf.c
> @@ -136,18 +136,25 @@ __resolv_conf_get_current (void)
>      {
>        /* Parse configuration while holding the lock.  This avoids
>           duplicate work.  */
> -      conf = __resolv_conf_load (NULL, NULL);
> +      struct file_change_detection after_load;
> +      conf = __resolv_conf_load (NULL, &after_load);
>        if (conf != NULL)
>          {
>            if (global_copy->conf_current != NULL)
>              conf_decrement (global_copy->conf_current);
>            global_copy->conf_current = conf; /* Takes ownership.  */
>  
> -          /* Update file modification stamps.  The configuration we
> -             read could be a newer version of the file, but this does
> -             not matter because this will lead to an extraneous reload
> -             later.  */
> -          global_copy->file_resolve_conf = initial;
> +          /* Update file change detection data, but only if it matches
> +             the initial measurement.  This avoids an ABA race in case
> +             /etc/resolv.conf is temporarily replaced while the file
> +             is read (after the initial measurement), and restored to
> +             the initial version later.  */
> +          if (file_is_unchanged (&initial, &after_load))
> +            global_copy->file_resolve_conf = after_load;
> +          else
> +            /* If there is a discrepancy, trigger a reload during the
> +               next use.  */
> +            global_copy->file_resolve_conf.size = -1;
>          }
>      }
>  
> 

Ok.

      reply	other threads:[~2020-02-13 21:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-21 18:41 [PATCH 0/5] Race condition in /etc/resolv.conf reloading (bug 25420) Florian Weimer
2020-01-21 18:41 ` [PATCH 1/5] Add internal <file_change_detection.h> header file Florian Weimer
2020-02-10 19:47   ` Adhemerval Zanella
2020-02-10 19:58     ` Florian Weimer
2020-02-10 20:57       ` Adhemerval Zanella
2020-01-21 18:42 ` [PATCH 2/5] resolv: Use <file_change_detection.h> in __resolv_conf_get_current Florian Weimer
2020-02-13 20:53   ` Adhemerval Zanella
2020-01-21 18:42 ` [PATCH 3/5] resolv: Fix file handle leak in __resolv_conf_load [BZ #25429] Florian Weimer
2020-02-13 21:01   ` Adhemerval Zanella
2020-02-13 21:08     ` Florian Weimer
2020-02-13 21:30       ` Adhemerval Zanella
2020-01-21 18:42 ` [PATCH 4/5] resolv: Enhance __resolv_conf_load to capture file change data Florian Weimer
2020-02-13 21:33   ` Adhemerval Zanella
2020-01-21 21:28 ` [PATCH 5/5] resolv: Fix ABA race in /etc/resolv.conf change detection [BZ #25420] Florian Weimer
2020-02-13 21:59   ` Adhemerval Zanella [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=0728f253-b851-d9d5-7c9b-a1a514600afc@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).