From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-4.2 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 631D11F910 for ; Mon, 28 Nov 2022 04:56:31 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; unprotected) header.d=cs.ucla.edu header.i=@cs.ucla.edu header.b="h8EBypph"; dkim-atps=neutral Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ozWBV-0007q4-BW; Sun, 27 Nov 2022 23:56:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ozWBT-0007oz-EN for bug-gnulib@gnu.org; Sun, 27 Nov 2022 23:55:59 -0500 Received: from zimbra.cs.ucla.edu ([131.179.128.68]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ozWBR-00007U-FV for bug-gnulib@gnu.org; Sun, 27 Nov 2022 23:55:59 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 7F968160056 for ; Sun, 27 Nov 2022 20:55:56 -0800 (PST) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id pmOA89jyyGp6; Sun, 27 Nov 2022 20:55:55 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 2B397160048; Sun, 27 Nov 2022 20:55:55 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.9.2 zimbra.cs.ucla.edu 2B397160048 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.ucla.edu; s=78364E5A-2AF3-11ED-87FA-8298ECA2D365; t=1669611355; bh=LSzwK8L5tI8PV+KDod5B2wi83l+U1QFjrx1qyZL0++8=; h=From:To:Subject:Date:Message-Id:MIME-Version: Content-Transfer-Encoding; b=h8EBypphgSRASLH6fw772rI+NkDMHKcAFia3J74jJGO0KH54U/lIC0e1Y86Yi06sU WylYE140Yo+/Wij50H0M6N7dQUI11jKAlBluYdYtm17VRxIuLhoQ7lgL/egRgOn1mY N34ogC8T/48YA6P72fB8jt0/9FBgO6lUgxIVfMb0= X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 3fHZd88KXpKj; Sun, 27 Nov 2022 20:55:55 -0800 (PST) Received: from localhost.localdomain (cpe-172-91-119-151.socal.res.rr.com [172.91.119.151]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id F3218160043; Sun, 27 Nov 2022 20:55:54 -0800 (PST) From: Paul Eggert To: bug-gnulib@gnu.org Cc: Paul Eggert Subject: [PROPOSED 4/4] explicit_bzero: implement via memset_explicit Date: Sun, 27 Nov 2022 20:55:43 -0800 Message-Id: <20221128045543.1355731-5-eggert@cs.ucla.edu> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221128045543.1355731-1-eggert@cs.ucla.edu> References: <20221128045543.1355731-1-eggert@cs.ucla.edu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=131.179.128.68; envelope-from=eggert@cs.ucla.edu; helo=zimbra.cs.ucla.edu X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org * lib/explicit_bzero.c (explicit_bzero): Simplify by just calling memset_explicit. * m4/explicit_bzero.m4 (gl_PREREQ_EXPLICIT_BZERO): Now a no-op. * modules/explicit_bzero (Depends-on): Add memset_explicit. (configure.ac): No need to worry about gl_PREREQ_EXPLICIT_BZERO. --- ChangeLog | 8 +++++ lib/explicit_bzero.c | 69 +++++++----------------------------------- m4/explicit_bzero.m4 | 7 ++--- modules/explicit_bzero | 4 +-- 4 files changed, 22 insertions(+), 66 deletions(-) diff --git a/ChangeLog b/ChangeLog index ea76fef399..26dfd4174c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2022-11-27 Paul Eggert =20 + explicit_bzero: implement via memset_explicit + * lib/explicit_bzero.c (explicit_bzero): + Simplify by just calling memset_explicit. + * m4/explicit_bzero.m4 (gl_PREREQ_EXPLICIT_BZERO): + Now a no-op. + * modules/explicit_bzero (Depends-on): Add memset_explicit. + (configure.ac): No need to worry about gl_PREREQ_EXPLICIT_BZERO. + explicit_bzero: memset_explicit is standard * doc/glibc-functions/explicit_bzero.texi: Say that memset_explicit is preferred in new code. diff --git a/lib/explicit_bzero.c b/lib/explicit_bzero.c index 584f982924..fc309f81d6 100644 --- a/lib/explicit_bzero.c +++ b/lib/explicit_bzero.c @@ -1,74 +1,27 @@ /* Erasure of sensitive data, generic implementation. Copyright (C) 2016-2022 Free Software Foundation, Inc. - This file is part of the GNU C Library. =20 - 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. + This file 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. =20 - The GNU C Library is distributed in the hope that it will be useful, + This file 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. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. =20 - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ + You should have received a copy of the GNU Lesser General Public Lice= nse + along with this program. If not, see = . */ =20 -/* An assembler implementation of explicit_bzero can be created as an - assembler alias of an optimized bzero implementation. - Architecture-specific implementations also need to define - __explicit_bzero_chk. */ - -#if !_LIBC -# include -#endif - -/* memset_s need this define */ -#if HAVE_MEMSET_S -# define __STDC_WANT_LIB_EXT1__ 1 -#endif +#include =20 #include =20 -#if defined _WIN32 && !defined __CYGWIN__ -# define WIN32_LEAN_AND_MEAN -# include -#endif - -#if _LIBC -/* glibc-internal users use __explicit_bzero_chk, and explicit_bzero - redirects to that. */ -# undef explicit_bzero -#endif - /* Set LEN bytes of S to 0. The compiler will not delete a call to this function, even if S is dead after the call. */ void explicit_bzero (void *s, size_t len) { -#if defined _WIN32 && !defined __CYGWIN__ - (void) SecureZeroMemory (s, len); -#elif HAVE_EXPLICIT_MEMSET - explicit_memset (s, '\0', len); -#elif HAVE_MEMSET_S - (void) memset_s (s, len, '\0', len); -#elif defined __GNUC__ && !defined __clang__ - memset (s, '\0', len); - /* Compiler barrier. */ - __asm__ volatile ("" ::: "memory"); -#elif defined __clang__ - memset (s, '\0', len); - /* Compiler barrier. */ - /* With asm ("" ::: "memory") LLVM analyzes uses of 's' and finds that= the - whole thing is dead and eliminates it. Use 'g' to work around this - problem. See . = */ - __asm__ volatile ("" : : "g"(s) : "memory"); -#else - /* Invoke memset through a volatile function pointer. This defeats co= mpiler - optimizations. */ - void * (* const volatile volatile_memset) (void *, int, size_t) =3D me= mset; - (void) volatile_memset (s, '\0', len); -#endif + memset_explicit (s, 0, len); } diff --git a/m4/explicit_bzero.m4 b/m4/explicit_bzero.m4 index 3b4ef8c3cc..6e6f2b4037 100644 --- a/m4/explicit_bzero.m4 +++ b/m4/explicit_bzero.m4 @@ -16,8 +16,5 @@ AC_DEFUN([gl_FUNC_EXPLICIT_BZERO], fi ]) =20 -AC_DEFUN([gl_PREREQ_EXPLICIT_BZERO], -[ - AC_CHECK_FUNCS([explicit_memset]) - AC_CHECK_FUNCS_ONCE([memset_s]) -]) +dnl Defined for backward compatibility. +AC_DEFUN([gl_PREREQ_EXPLICIT_BZERO], [:]) diff --git a/modules/explicit_bzero b/modules/explicit_bzero index bb5f8a5310..8ba9a06ada 100644 --- a/modules/explicit_bzero +++ b/modules/explicit_bzero @@ -7,14 +7,12 @@ m4/explicit_bzero.m4 =20 Depends-on: extensions +memset_explicit string =20 configure.ac: gl_FUNC_EXPLICIT_BZERO gl_CONDITIONAL([GL_COND_OBJ_EXPLICIT_BZERO], [test $HAVE_EXPLICIT_BZERO = =3D 0]) -AM_COND_IF([GL_COND_OBJ_EXPLICIT_BZERO], [ - gl_PREREQ_EXPLICIT_BZERO -]) gl_STRING_MODULE_INDICATOR([explicit_bzero]) =20 Makefile.am: --=20 2.37.2