From patchwork Wed Oct 14 19:03:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 54963 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by patches.linaro.org (Postfix) with ESMTPS id 2046C23012 for ; Wed, 14 Oct 2015 19:03:41 +0000 (UTC) Received: by wicgb1 with SMTP id gb1sf31219212wic.3 for ; Wed, 14 Oct 2015 12:03:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:mailing-list :precedence:list-id:list-unsubscribe:list-subscribe:list-archive :list-post:list-help:sender:delivered-to:from:to:subject:date :message-id:x-original-sender:x-original-authentication-results; bh=kybOuSzlpbSppf0GJbzS/ryJhiBrk6NPr1RdVCFT3pM=; b=Tqlf6q1cbRTEva8Dijz2gCuG+EFdWB77M+YJ8q7KE0r7n1Vg5WBbh4kTbiWT+yusA2 CWyFIaQhldJ+MEgMOa5AvNf1TH3LaVSXfwFSPRTpszLfYoUk5z+btlJwrqqWPtjsj7Lh ALAfGSxDzCggI31P/dSWJOC/gdNxHMcnjyPKeX0nFyN2omPE/wLDCi4oKqUrK2LFdJT7 5P1T4iCITU0NI1wG8WVV815KZtiWFVlpzTWFZJCFCJczGgGd1XMMp4yY9X3hXeh9qXe6 E+z2vixXM25GQzoa2zQCcyjpmlS617kh78xycZ0vI6KbLRW5OPKotYtoyM6SMK0jURCO sfDQ== X-Gm-Message-State: ALoCoQnNzdF+pED87uS92zr4xgamdFkGEg+KqUDrssCegHjGvcGlP/YviN+E2J2SnkHETqVmt7HI X-Received: by 10.112.12.132 with SMTP id y4mr1147211lbb.0.1444849420176; Wed, 14 Oct 2015 12:03:40 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.29.148 with SMTP id d142ls67005lfd.27.gmail; Wed, 14 Oct 2015 12:03:39 -0700 (PDT) X-Received: by 10.25.16.73 with SMTP id f70mr1440063lfi.21.1444849419907; Wed, 14 Oct 2015 12:03:39 -0700 (PDT) Received: from mail-lb0-x233.google.com (mail-lb0-x233.google.com. [2a00:1450:4010:c04::233]) by mx.google.com with ESMTPS id a7si6522175lfb.32.2015.10.14.12.03.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Oct 2015 12:03:39 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::233 as permitted sender) client-ip=2a00:1450:4010:c04::233; Received: by lbbck17 with SMTP id ck17so53601257lbb.1 for ; Wed, 14 Oct 2015 12:03:39 -0700 (PDT) X-Received: by 10.112.135.9 with SMTP id po9mr2523003lbb.56.1444849419781; Wed, 14 Oct 2015 12:03:39 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp180285lbq; Wed, 14 Oct 2015 12:03:38 -0700 (PDT) X-Received: by 10.50.62.46 with SMTP id v14mr27390619igr.79.1444849418507; Wed, 14 Oct 2015 12:03:38 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id p136si8549788ioe.31.2015.10.14.12.03.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Oct 2015 12:03:38 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-64059-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 80776 invoked by alias); 14 Oct 2015 19:03:28 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list List-Id: List-Unsubscribe: , List-Subscribe: List-Archive: List-Post: , List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 80758 invoked by uid 89); 14 Oct 2015 19:03:27 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-yk0-f180.google.com X-Received: by 10.129.51.73 with SMTP id z70mr3525386ywz.148.1444849404373; Wed, 14 Oct 2015 12:03:24 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH] nptl: Fix racy pipe closing in tst-cancel{20,21} Date: Wed, 14 Oct 2015 16:03:15 -0300 Message-Id: <1444849395-18800-1-git-send-email-adhemerval.zanella@linaro.com> X-Original-Sender: adhemerval.zanella@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::233 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@sourceware.org X-Google-Group-Id: 836684582541 The tst-cancel20 open two pipes and creates a thread which blocks reading the first pipe. It then issues a signal to activate an handler which also blocks reading the second pipe. Finally the cancellation cleanup-up handlers are tested by first closing the all the pipe ends and issuing a pthread_cancel. The tst-cancel21 have a similar behavior, but use an extra fork after the test itself. The race condition occurs if the cancellation handling acts after the pipe close: in this case read will return EOF (indicating side-effects) and thus the cancellation must not act. However current GLIBC cancellation behavior acts regardless the syscalls returns with sid-effects. This patch adjust the test by moving the pipe closing after the cancellation handling. This avoid spurious cancellation for the case described. Checked on x86_64 and i386. * nptl/tst-cancel20.c (do_one_test): Move the pipe closing after pthread_join. * nptl/tst-cancel21.c (tf): Likewise. --- ChangeLog | 6 ++++++ nptl/tst-cancel20.c | 15 +++++++++------ nptl/tst-cancel21.c | 15 +++++++++------ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/nptl/tst-cancel20.c b/nptl/tst-cancel20.c index 51b558e..91452fb 100644 --- a/nptl/tst-cancel20.c +++ b/nptl/tst-cancel20.c @@ -145,12 +145,6 @@ do_one_test (void) return 1; } - /* This will cause the read in the child to return. */ - close (fd[0]); - close (fd[1]); - close (fd[2]); - close (fd[3]); - void *ret; if (pthread_join (th, &ret) != 0) { @@ -170,6 +164,15 @@ do_one_test (void) return 1; } + /* The pipe closing must be issued after the cancellation handling to avoid + a race condition where the cancellation runs after both pipe ends are + closed. In this case the read syscall returns EOF and the cancellation + must not act. */ + close (fd[0]); + close (fd[1]); + close (fd[2]); + close (fd[3]); + return 0; } diff --git a/nptl/tst-cancel21.c b/nptl/tst-cancel21.c index b54f236..d082776 100644 --- a/nptl/tst-cancel21.c +++ b/nptl/tst-cancel21.c @@ -123,12 +123,6 @@ tf (void *arg) exit (1); } - /* This will cause the read in the initial thread to return. */ - close (fd[0]); - close (fd[1]); - close (fd[2]); - close (fd[3]); - void *ret; if (pthread_join (th, &ret) != 0) { @@ -154,6 +148,15 @@ tf (void *arg) exit (1); } + /* The pipe closing must be issued after the cancellation handling to avoid + a race condition where the cancellation runs after both pipe ends are + closed. In this case the read syscall returns EOF and the cancellation + must not act. */ + close (fd[0]); + close (fd[1]); + close (fd[2]); + close (fd[3]); + exit (0); }