From patchwork Thu Dec 21 18:59:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 757029 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp1054060wrw; Thu, 21 Dec 2023 11:00:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IFeFU0DYDBP8wWfKl1hcfWpdSn6vRJyCGnewME6k7WLbHFKY76gcYpRMcqRChgahL7SQ6LU X-Received: by 2002:aca:2b07:0:b0:3ba:92a:910 with SMTP id i7-20020aca2b07000000b003ba092a0910mr124299oik.104.1703185214011; Thu, 21 Dec 2023 11:00:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1703185213; cv=pass; d=google.com; s=arc-20160816; b=jJyAKZKjM/4zU4VR3jxlNOwedIEDLWhpNFv9QCiBVw6pPHUscwnRsZ6wo2aekjmdgx oi4MYaAZ+oE50fkl8MgZ8S66Ku3vbU8KJHe/xW+IDKnztn5PJ/l6oikq4i6ZHCWO+HxC uHHY9n+uBl5SUpNSPMhiDTOg9T79pYc5x+yIX8VkPxlgLjtKAb0Sp8waoCZXzPijc/3E /D6S3xhA02cYXkDIxpBF6oWIghsCE9eyTKYQnJZJpXsPU9ij4GuX57cCmPyMvUvZzGLP KtmpYFJJjoiH+/W4X5AFxwXPhjAXCraY8NCRAqV+VBYnwjHaS5Mvj/E+3VC+u0mhOQll hdkg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=vv53uQpYbZuGOr4ynPza99NntS1MMyxrhLUOdBkxv+4=; fh=JNN3k7BRNI1OnWdIBK9jlpNeitGd8uBm02dHI75AGcg=; b=MPVRJbHWnBR23QaiFw8w3XTJn3ipwArLdTxF+qLw2mljoCScCV7Y5+/Q3xURbyAA/t +Jsbqg7oEvLLGnNFD6UnzSQKMIJyYvP+l5p+5pF9zPKvker327FQiMM3WAI2esl8KcAJ FDvf7wgxGVG9aKlCBzb/1SbN1irLiB48Aq0E1xM5M1sTMEsxIy0/v9lvEDk0IRFvkc3E Garfwo6cAHbrixUNqT3Jl28RjmNJ4SXzKmaoGF8knnu5i4k9xabZwv5FTpFJQMxiYuaz /sJgeTHLvy/m5dWiQ6QV1ATdAhZvyFCFplwuq/CWfYsrYs+K8EPxc5B5y5LJ96BcOQaJ Orxw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vZUNeIeU; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id f3-20020a0ccc83000000b0067aba030a80si2700477qvl.23.2023.12.21.11.00.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 11:00:13 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vZUNeIeU; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A5F473864873 for ; Thu, 21 Dec 2023 19:00:13 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by sourceware.org (Postfix) with ESMTPS id 823BC385B532 for ; Thu, 21 Dec 2023 18:59:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 823BC385B532 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 823BC385B532 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::12e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703185193; cv=none; b=IdRsD5rjuyP4kUkr2VasKiLiZ+kXlaw0I0bAzQ0ZU6UAsQCxfpcrhicWIaVx2rRyUtXncGo7JuC/cGhku8c+UHDSCVRffVTXoAWI8N5f01/+r0NefPFjrj4fXiqN9xzi2dbJ74oL1WcvXBfEYi9qFFyPTNPZE57Ql1wYyg+F95o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703185193; c=relaxed/simple; bh=e694cuZ44CNyt5dfALndjqMXp3Fa5Cj+qkRwaNVsNPw=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=N5BxeyWo/WIDKhcBNo6DEG5j5QSi91x2kMifwzxReLd4YBvoLtkYAmHu3xonDZPMztOOyIxYkR1Wk+6gpDkEHjusxBIIHvlrH2HlLWgC13K5CX+23kxpgMlPTce1ylOSpPuk5htoWLtmcVH2ySjKQz/fI0/UVlZWQ2fiWbzLq58= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x12e.google.com with SMTP id e9e14a558f8ab-35fd5a13285so2942555ab.3 for ; Thu, 21 Dec 2023 10:59:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703185190; x=1703789990; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=vv53uQpYbZuGOr4ynPza99NntS1MMyxrhLUOdBkxv+4=; b=vZUNeIeU6p9X1ToHtUItVMu2pY3PuCX5rakRU5UENrVAuhmdlfEKUpXxYlxdag2cRv CZ8xCzwTNnY47Ai8JHFcIX8kjJMc7PZZUU8G/WeJky1f3rY1IyHn6wXtwi0dOsTyNTWY W7aMBdCPLjeM93keq/hE892lqdjo6OegC5EKs0+ZuhA8comf8Eua7QTKrWbnfP66kkbW FAtXttGQ65aeDPGCu8IjfxUZy4DLOvSs4UF346S2A3uT/mi32TPdC9kFy77NxNo9GwUf 4ranvwwgRgTYS5tn8+KigUZpIM7IZ48QHxobxqFsvOH0FQERhLzByp5md9eDEx2GYIMo zU3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703185190; x=1703789990; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vv53uQpYbZuGOr4ynPza99NntS1MMyxrhLUOdBkxv+4=; b=e/09rwBpM0wwGQQGcPeqOJfUfzPJYa3Xq4sAu+u8+bS6IhF+kqFUKptAzkg5qGL9Y6 lm9/xy8A2Fa9AeYz+Jk9QF3oIdoD7obiWy6vXZAlm1ohj7vyZuao8f6u2PHqXidmgYx5 Am1qABRRrfLnYmbuN3FMG0B20t9ogaVdFe283n+YLptvR/w3tS1TE8ujFRcFCvBMu3/u rCiixX3BECX1ymDXK+zbgJ1X9b5MNFBt+3uBtKIM97AiBsLpZnhfAL0MrcLZ2PmFnHem dxuZsCrK+ty70quGqQUvx9W9Mzknw0yoLIAayncd0vEoKX8+x87ZWsfrW9+VuPozwVM4 GUig== X-Gm-Message-State: AOJu0YwGfA54jjh6/YIZykdW6EQvDHkSoLW0DlFjEOED0Ge+MOMmUmgy JDcVTDRpHMameaduSEH6s2r9nb8tee1FG3FgjJNup1cvnMc= X-Received: by 2002:a05:6e02:1b02:b0:35f:ac66:e863 with SMTP id i2-20020a056e021b0200b0035fac66e863mr110439ilv.50.1703185190187; Thu, 21 Dec 2023 10:59:50 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c0:8192:ecd7:d327:bea0:14dc]) by smtp.gmail.com with ESMTPSA id a9-20020a63e409000000b005cdbebd61d8sm1946165pgi.9.2023.12.21.10.59.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 10:59:49 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Siddhesh Poyarekar Subject: [PATCH 04/15] debug: Add fortify syslog tests Date: Thu, 21 Dec 2023 15:59:18 -0300 Message-Id: <20231221185929.1307116-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221185929.1307116-1-adhemerval.zanella@linaro.org> References: <20231221185929.1307116-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patch=linaro.org@sourceware.org It requires to be in a container tests to avoid logging bogus information on the system. The syslog also requires to be checked in a different process because the internal printf call will abort with the internal syslog lock taken (which makes subsequent syslog calls deadlock). Checked on aarch64, armhf, x86_64, and i686. Reviewed-by: Siddhesh Poyarekar --- debug/Makefile | 5 ++ debug/tst-fortify-syslog.c | 128 +++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 debug/tst-fortify-syslog.c diff --git a/debug/Makefile b/debug/Makefile index c49e5d86ec..fdc250e209 100644 --- a/debug/Makefile +++ b/debug/Makefile @@ -179,6 +179,7 @@ CPPFLAGS-tst-longjmp_chk3.c += $(no-fortify-source),-D_FORTIFY_SOURCE=1 CPPFLAGS-tst-realpath-chk.c += $(no-fortify-source),-D_FORTIFY_SOURCE=2 CPPFLAGS-tst-chk-cancel.c += $(no-fortify-source),-D_FORTIFY_SOURCE=2 CFLAGS-tst-sprintf-fortify-rdonly.c += $(no-fortify-source),-D_FORTIFY_SOURCE=2 +CFLAGS-tst-fortify-syslog.c += $(no-fortify-source),-D_FORTIFY_SOURCE=2 # _FORTIFY_SOURCE tests. # Auto-generate tests for _FORTIFY_SOURCE for different levels, compilers and @@ -293,6 +294,10 @@ tests-time64 += \ $(tests-all-time64-chk) \ # tests-time64 +tests-container += \ + tst-fortify-syslog \ + # tests-container + ifeq ($(have-ssp),yes) tests += tst-ssp-1 endif diff --git a/debug/tst-fortify-syslog.c b/debug/tst-fortify-syslog.c new file mode 100644 index 0000000000..26a93d9be8 --- /dev/null +++ b/debug/tst-fortify-syslog.c @@ -0,0 +1,128 @@ +/* Fortify tests for syslog interface. + Copyright (C) 2023 Free Software Foundation, Inc. + Copyright The GNU Toolchain Authors. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +static const char *str2 = "F"; +static char buf2[10] = "%s"; + +static volatile int chk_fail_ok; +static jmp_buf chk_fail_buf; + +static void +handler (int sig) +{ + if (chk_fail_ok) + { + chk_fail_ok = 0; + longjmp (chk_fail_buf, 1); + } + else + _exit (127); +} + +#define FAIL() \ + do { \ + printf ("Failure on line %d\n", __LINE__); \ + support_record_failure (); \ + } while (0) +#define CHK_FAIL_START \ + chk_fail_ok = 1; \ + if (! setjmp (chk_fail_buf)) \ + { +#define CHK_FAIL_END \ + chk_fail_ok = 0; \ + FAIL (); \ + } + +static void +call_vsyslog (int priority, const char *format, ...) +{ + va_list va; + va_start (va, format); + vsyslog (priority, format, va); + va_end (va); +} + +static void +run_syslog_chk (void *closure) +{ + int n1; + CHK_FAIL_START + syslog (LOG_USER | LOG_DEBUG, buf2, str2, &n1, str2, &n1); + CHK_FAIL_END +} + +static void +run_vsyslog_chk (void *closure) +{ + int n1; + CHK_FAIL_START + call_vsyslog (LOG_USER | LOG_DEBUG, buf2, str2, &n1, str2, &n1); + CHK_FAIL_END +} + +static int +do_test (void) +{ + set_fortify_handler (handler); + + int n1, n2; + + n1 = n2 = 0; + syslog (LOG_USER | LOG_DEBUG, "%s%n%s%n", str2, &n1, str2, &n2); + TEST_COMPARE (n1, 1); + TEST_COMPARE (n2, 2); + + n1 = n2 = 0; + call_vsyslog (LOG_USER | LOG_DEBUG, "%s%n%s%n", str2, &n1, str2, &n2); + TEST_COMPARE (n1, 1); + TEST_COMPARE (n2, 2); + + strcpy (buf2 + 2, "%n%s%n"); + + /* The wrapper tests need to be in a subprocess because the abort called by + printf does not unlock the internal syslog lock. */ + { + struct support_capture_subprocess result + = support_capture_subprocess (run_syslog_chk, NULL); + support_capture_subprocess_check (&result, "syslog", 0, sc_allow_stderr); + support_capture_subprocess_free (&result); + } + + { + struct support_capture_subprocess result + = support_capture_subprocess (run_vsyslog_chk, NULL); + support_capture_subprocess_check (&result, "syslog", 0, sc_allow_stderr); + support_capture_subprocess_free (&result); + } + + return 0; +} + +#include