From patchwork Fri Jun 23 09:42:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 1798823 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=mmNlKMlE; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QnXSV10SGz20Wk for ; Fri, 23 Jun 2023 19:46:34 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1A6483851C04 for ; Fri, 23 Jun 2023 09:46:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A6483851C04 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1687513592; bh=KNz7Lm47fzJ3Q/CiHtGsNG6QGDXka1Tcsxp3X1TpVDY=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=mmNlKMlEaoJ9Wks65O90+6RlzAbrw2gdHuN6d6xo8CoF0GYNWt4X8TOVMWKfopkV9 75Z7xbtQwQ97K6xRhxJI3IYChB6f64pZbhpFOI4qvXooGdJhyKz7WNW53YwXQEDrba skggORgLHxb7NdRPIvSds8AQScPs7JzdE/g9Yu5U= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 63FBF38582A1 for ; Fri, 23 Jun 2023 09:43:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 63FBF38582A1 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-103-RoB_yPjTMuiRZpO6PSWhbw-1; Fri, 23 Jun 2023 05:43:35 -0400 X-MC-Unique: RoB_yPjTMuiRZpO6PSWhbw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 18704185A7A4; Fri, 23 Jun 2023 09:43:35 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7216A1121314; Fri, 23 Jun 2023 09:43:34 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v2 07/14] misc/sys/cdefs.h: Create FORTIFY redirects for internal calls Date: Fri, 23 Jun 2023 11:42:16 +0200 Message-ID: <20230623094223.3742673-8-fberat@redhat.com> In-Reply-To: <20230623094223.3742673-1-fberat@redhat.com> References: <20230623094223.3742673-1-fberat@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: =?utf-8?q?Fr=C3=A9d=C3=A9ric_B=C3=A9rat_via_Libc-alpha?= From: Frederic Berat Reply-To: =?utf-8?b?RnLDqWTDqXJpYyBCw6lyYXQ=?= Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" The __REDIRECT* macros are creating aliases which may lead to unwanted PLT entries when fortification is enabled. To prevent these entries, the REDIRECT alias should be set to point to the existing __GI_* aliases. This is done transparently by creating a __REDIRECT_FORTIFY* version of these macros, that can be overwritten internally when necessary. --- include/sys/cdefs.h | 14 ++++++++++++++ misc/sys/cdefs.h | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/include/sys/cdefs.h b/include/sys/cdefs.h index 56adb231aa..b84ad34a70 100644 --- a/include/sys/cdefs.h +++ b/include/sys/cdefs.h @@ -40,6 +40,20 @@ rtld_hidden_proto (__chk_fail) #endif +#if defined SHARED +#if IS_IN (libc) && __USE_FORTIFY_LEVEL > 0 && defined __fortify_function + +#undef __REDIRECT_FORTIFY +#define __REDIRECT_FORTIFY(name, proto, alias) \ + __REDIRECT(name, proto, __GI_##alias) + +#undef __REDIRECT_FORTIFY_NTH +#define __REDIRECT_FORTIFY_NTH(name, proto, alias) \ + __REDIRECT_NTH(name, proto, __GI_##alias) + +#endif +#endif /* defined SHARED */ + #endif /* !defined _ISOMAC */ #endif diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h index 393d9091d9..90c21e2703 100644 --- a/misc/sys/cdefs.h +++ b/misc/sys/cdefs.h @@ -268,6 +268,14 @@ # define __ASMNAME(cname) __ASMNAME2 (__USER_LABEL_PREFIX__, cname) # define __ASMNAME2(prefix, cname) __STRING (prefix) cname +#ifndef __REDIRECT_FORTIFY +#define __REDIRECT_FORTIFY __REDIRECT +#endif + +#ifndef __REDIRECT_FORTIFY_NTH +#define __REDIRECT_FORTIFY_NTH __REDIRECT_NTH +#endif + /* #elif __SOME_OTHER_COMPILER__