From patchwork Mon Jul 3 18:04:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 72026 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3AA0D3857B8E for ; Mon, 3 Jul 2023 18:05:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3AA0D3857B8E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688407512; bh=eSy3N48AUjgVWoTrleyS/7ArgxthyedfVjOSAARUs+o=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=fkbBiN8m8i9mVIot3dzRYml0U1CSGCCD9/oSO9/alVDeunPRW3qOAFPpyRMmlR5R+ tsEhoF30Rd98am1R6vI5342dgjm3QpdEX+yCN/1lDp+Wx38FEG4HM8qIBR4c4bPqI/ TpkUDiw1hP2RGrQ42wkU2ZaCqjnYW+vdaKaqxvLk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x2f.google.com (mail-oa1-x2f.google.com [IPv6:2001:4860:4864:20::2f]) by sourceware.org (Postfix) with ESMTPS id 761013858022 for ; Mon, 3 Jul 2023 18:04:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 761013858022 Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-1b060bce5b0so4454087fac.3 for ; Mon, 03 Jul 2023 11:04:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688407488; x=1690999488; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eSy3N48AUjgVWoTrleyS/7ArgxthyedfVjOSAARUs+o=; b=GDWDZQjUbAGI1Y56JGLQy+FwUs8+iaqDkmkAjGVFE30BYQTntJhAeoYePLWiH/6627 d7JyFHI+gVhBFjgCxjDW6MDIBEXs2Sm/Y+9nzgtoZHZyYEF5Npch1DZn/xiOKvE/4TKP G0LMk2NCz/jp9zQyFJYgPoF0lfovIfVixOiCXTq99stLugiywkCUDZW4tpxhM+HYI/oe GbO975jk11we/3zeiZSOHyVstaMvUkoiVcbBmrTHLE/prtG4LPSJQtXHIiYfelO+3j+w wDLIfJw5NQbJis1ncl2XjlUIFOJZIOg4f72iWeqBHirwvDKkCvwJq8XP12A+pCh8cfzP hiSw== X-Gm-Message-State: AC+VfDxjTa1ZK2s2EIhQZq0LgXtvTmi9eiHPdNsK83olnHKqnhJMYAzu XiKyPVHylLTrHueX3jyT9q2ONciTG1tdjPIk79lp0Q== X-Google-Smtp-Source: ACHHUZ7qtj0yrljjrwW93StS/ckDH7dMGsfrIiSmOY06okeB3esZAWoqKAL1o8HmZdmT77zGVhlCXg== X-Received: by 2002:a05:6870:fba8:b0:1b0:e939:8ab1 with SMTP id kv40-20020a056870fba800b001b0e9398ab1mr12111457oab.15.1688407488348; Mon, 03 Jul 2023 11:04:48 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c3:665c:ecc5:4952:8dae:2a84]) by smtp.gmail.com with ESMTPSA id nw11-20020a056870bb0b00b001b04d0b55ebsm9578813oab.26.2023.07.03.11.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jul 2023 11:04:47 -0700 (PDT) To: libc-alpha@sourceware.org, Paul Pluzhnikov Cc: Alan Zhao Subject: [PATCH v2] debug: Fix fortified realpath C++ ODR violation (BZ 30516) Date: Mon, 3 Jul 2023 15:04:44 -0300 Message-Id: <20230703180444.1698963-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.9 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.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Although fortify wrappers are built with always_inline attribute, C++ modules imports a precompiled header module foo.pcm generated from foo.h which may differ if the translation unit includes or not limit.h. Although GCC does not fully support C++ modules yet, this is a problem when using C++ modules with clang. To avoid lower C diagnostic coverage, a new installed header is added that adds namespace-clean macro with value similar to current one (__PATH_MAX). A test is also added to check if the kernel decides to change it. Checked on x86_64-linux-gnu. --- bits/stdlib_lim.h | 26 ++++++++++ stdlib/Makefile | 1 + stdlib/bits/stdlib.h | 6 ++- sysdeps/unix/sysv/linux/Makefile | 10 ++++ sysdeps/unix/sysv/linux/bits/stdlib_lim.h | 26 ++++++++++ sysdeps/unix/sysv/linux/tst-limits-consts.py | 54 ++++++++++++++++++++ 6 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 bits/stdlib_lim.h create mode 100644 sysdeps/unix/sysv/linux/bits/stdlib_lim.h create mode 100755 sysdeps/unix/sysv/linux/tst-limits-consts.py diff --git a/bits/stdlib_lim.h b/bits/stdlib_lim.h new file mode 100644 index 0000000000..f0295490c0 --- /dev/null +++ b/bits/stdlib_lim.h @@ -0,0 +1,26 @@ +/* Implementation limits related to stdlib.h - generic version. + Copyright (C) 2023 Free Software Foundation, Inc. + 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 + . */ + +#ifndef _BITS_STDLIB_LIM_H +#define _BITS_STDLIB_LIM_H 1 + +/* Same as PATH_MAX, but defined in the implementation namespace so it can + be used in places where including limits.h is not possible. */ +#undef __PATH_MAX + +#endif diff --git a/stdlib/Makefile b/stdlib/Makefile index 0975f55ee6..726a109b67 100644 --- a/stdlib/Makefile +++ b/stdlib/Makefile @@ -33,6 +33,7 @@ headers := \ bits/stdlib-float.h \ bits/stdlib-ldbl.h \ bits/stdlib.h \ + bits/stdlib_lim.h \ bits/time64.h \ bits/timesize.h \ bits/types/error_t.h \ diff --git a/stdlib/bits/stdlib.h b/stdlib/bits/stdlib.h index c6c0082ad5..ed54c24fd4 100644 --- a/stdlib/bits/stdlib.h +++ b/stdlib/bits/stdlib.h @@ -20,6 +20,8 @@ # error "Never include directly; use instead." #endif +#include + extern char *__realpath_chk (const char *__restrict __name, char *__restrict __resolved, size_t __resolvedlen) __THROW __wur; @@ -41,8 +43,8 @@ __NTH (realpath (const char *__restrict __name, char *__restrict __resolved)) if (sz == (size_t) -1) return __realpath_alias (__name, __resolved); -#if defined _LIBC_LIMITS_H_ && defined PATH_MAX - if (__glibc_unsafe_len (PATH_MAX, sizeof (char), sz)) +#ifdef __PATH_MAX + if (__glibc_unsafe_len (__PATH_MAX, sizeof (char), sz)) return __realpath_chk_warn (__name, __resolved, sz); #endif return __realpath_chk (__name, __resolved, sz); diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 23a84cf225..5fc559568f 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -376,6 +376,16 @@ $(objpfx)tst-mount-consts.out: ../sysdeps/unix/sysv/linux/tst-mount-consts.py < /dev/null > $@ 2>&1; $(evaluate-test) $(objpfx)tst-mount-consts.out: $(sysdeps-linux-python-deps) +tests-special += \ + $(objpfx)tst-limits-consts.out \ + # tests-special +$(objpfx)tst-limits-consts.out: ../sysdeps/unix/sysv/linux/tst-limits-consts.py + $(sysdeps-linux-python) \ + ../sysdeps/unix/sysv/linux/tst-limits-consts.py \ + $(sysdeps-linux-python-cc) \ + < /dev/null > $@ 2>&1; $(evaluate-test) +$(objpfx)tst-limits-consts.out: $(sysdeps-linux-python-deps) + tests-special += \ $(objpfx)tst-mount-compile.out \ # tests-special diff --git a/sysdeps/unix/sysv/linux/bits/stdlib_lim.h b/sysdeps/unix/sysv/linux/bits/stdlib_lim.h new file mode 100644 index 0000000000..935c9836d8 --- /dev/null +++ b/sysdeps/unix/sysv/linux/bits/stdlib_lim.h @@ -0,0 +1,26 @@ +/* Implementation limits related to stdlib.h - Linux version. + Copyright (C) 2023 Free Software Foundation, Inc. + 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 + . */ + +#ifndef _BITS_STDLIB_LIM_H +#define _BITS_STDLIB_LIM_H + +/* Same as PATH_MAX, but defined in the implementation namespace so it can + be used in places where including limits.h is not possible. */ +#define __PATH_MAX 4096 + +#endif diff --git a/sysdeps/unix/sysv/linux/tst-limits-consts.py b/sysdeps/unix/sysv/linux/tst-limits-consts.py new file mode 100755 index 0000000000..6abbc6e379 --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-limits-consts.py @@ -0,0 +1,54 @@ +#!/usr/bin/python3 +# Test that glibc's limits.h constants match the kernel's. +# Copyright (C) 2022-2023 Free Software Foundation, Inc. +# 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 +# . + +import argparse +import sys + +import glibcextract +import glibcsyscalls + + +def main(): + """The main entry point.""" + parser = argparse.ArgumentParser( + description="Test that glibc's limits.h constants " + "match the kernel's.") + parser.add_argument('--cc', metavar='CC', + help='C compiler (including options) to use') + args = parser.parse_args() + + def check_single(kcte, cte): + macros_1 = glibcextract.compute_macro_consts( + '#include \n', + args.cc, + kcte) + macros_2 = glibcextract.compute_macro_consts( + '#include \n', + args.cc, + cte) + ret = 1 + for (k1, v1), (k2, v2) in zip(macros_1.items(), macros_2.items()): + if v1 == v2: + ret = 0 + return ret + + sys.exit(check_single('PATH_MAX', '__PATH_MAX')) + +if __name__ == '__main__': + main()