From patchwork Mon Jun 13 11:11:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 634557 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rSqpq2dDfz9t0G for ; Mon, 13 Jun 2016 21:11:31 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=nFF21CKc; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; q=dns; s=default; b= AYalMA9m5k3c7M0/4bu3F/grodxVQqmDSH+nk7pHe0m5zXzWDKppNciJYJgIhBzv aYrl5Se4+Uaigqc0JAB0yRWXasE7oe3JanCnfgu/o1Se+26o4lrV5lLoEQf9imP4 qk7kIbOJYTvwsmrbIPmpmTo548YwBEwd5/9i35AtvpQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; s=default; bh=rXd+I5 AtGy+PA/tpvk2d1/Rzv+8=; b=nFF21CKcxR2ZX5GPbbIVc/ONoivVEo/x0VBSqt GGvFhKiZ47ziMIzGp87eMw+lwIhY0i/uBGlybmto7tTQKI4Bneg7INa/s5X2k1El w5EhRcNURbQBEyJ8DKeylXKi2TIakHsLld/EQL+qhwI9DwbA7/GhoYWeABGS38Ml 3aP/w= Received: (qmail 98006 invoked by alias); 13 Jun 2016 11:11:22 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk 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 97984 invoked by uid 89); 13 Jun 2016 11:11:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=35, 9, H*MI:oldenburg, HContent-Transfer-Encoding:8bit X-HELO: mx1.redhat.com Date: Mon, 13 Jun 2016 13:11:11 +0200 To: libc-alpha@sourceware.org Subject: [PATCH] debug/tst-longjmp_chk2: Make signal handler more conservative [BZ #20248] User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Message-Id: <20160613111111.79B3D4022A42D@oldenburg.str.redhat.com> From: fweimer@redhat.com (Florian Weimer) Currently, printf needs more stack space than what is available with SIGSTKSZ. This commit use the the write system call directly instead. Also use sig_atomic_t for the “pass” variable (for general correctness), and restore signal handlers to their defaults, to avoid masking crashes. 2016-06-13 Florian Weimer [BZ #20248] * debug/tst-longjmp_chk2.c (pass): Use volatile sig_atomic_t. (write_message): New function. (stackoverflow_handler): Call it instead of printf, to avoid excessive stack usage by printf. (do_test): Restore SIGSEGV, SIGBUS default handlers. diff --git a/debug/tst-longjmp_chk2.c b/debug/tst-longjmp_chk2.c index dae9ca0..243568c 100644 --- a/debug/tst-longjmp_chk2.c +++ b/debug/tst-longjmp_chk2.c @@ -6,15 +6,25 @@ #include #include #include +#include #include #include #include +#include static jmp_buf mainloop; static sigset_t mainsigset; -static int pass; +static volatile sig_atomic_t pass; +static void +write_message (const char *message) +{ + ssize_t unused __attribute__ ((unused)); + for (int i = 0; i < pass; ++i) + unused = write (STDOUT_FILENO, " ", 1); + unused = write (STDOUT_FILENO, message, strlen (message)); +} static void stackoverflow_handler (int sig) @@ -25,11 +35,9 @@ stackoverflow_handler (int sig) pass++; assert (pass < 5); sigaltstack (NULL, &altstack); - /* Using printf is not really kosher in signal handlers but we know - it will work. */ - printf ("%*sin signal handler\n", pass, ""); + write_message ("in signal handler\n"); if (altstack.ss_flags & SS_ONSTACK) - printf ("%*son alternate stack\n", pass, ""); + write_message ("on alternate stack\n"); siglongjmp (mainloop, pass); } @@ -112,6 +120,11 @@ do_test (void) else printf ("disabling alternate stack succeeded \n"); + /* Restore the signal handlers, in case we trigger a crash after the + tests above. */ + signal (SIGBUS, SIG_DFL); + signal (SIGSEGV, SIG_DFL); + return 0; }