From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 95767 invoked by alias); 21 Jan 2020 18:42:23 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 95685 invoked by uid 89); 21 Jan 2020 18:42:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=discrepancy, HX-Languages-Length:1765 X-HELO: us-smtp-1.mimecast.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579632140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HzNG7T5oRwFefX+l9GbePe3/1oIFD2RXA0Brg+JORbs=; b=TVI0R3mvaVN8SkwBsqKTyQiBUPNUeNk7D/svnjPrT5Z02nTV4tBI5DOqlJgjsqRlymTRId nfcFVjlCkmcO8QkKodKXgrvXhXDesQl6Rrr5xPXF+FAm8wJuTm4xkg5h+y39IvlS44byEI ddoUc142TNU1S0bbW+LuZ6hKsaisZ3Y= From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH 5/5] resolv: Fix ABA race in /etc/resolv.conf change detection [BZ #25420] In-Reply-To: References: Message-Id: <95b81fd1ccd9d41c4f6a897a1c43d1298da0486e.1579631655.git.fweimer@redhat.com> Date: Tue, 21 Jan 2020 21:28:00 -0000 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: quoted-printable X-SW-Source: 2020-01/txt/msg00496.txt.bz2 __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]"). --- 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 =3D __resolv_conf_load (NULL, NULL); + struct file_change_detection after_load; + conf =3D __resolv_conf_load (NULL, &after_load); if (conf !=3D NULL) { if (global_copy->conf_current !=3D NULL) conf_decrement (global_copy->conf_current); global_copy->conf_current =3D conf; /* Takes ownership. */ =20 - /* 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 =3D 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 =3D after_load; + else + /* If there is a discrepancy, trigger a reload during the + next use. */ + global_copy->file_resolve_conf.size =3D -1; } } =20 --=20 2.24.1