From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12945 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] proposal adding explicit_bzero Date: Tue, 26 Jun 2018 16:43:41 -0400 Message-ID: <20180626204341.GY1392@brightrain.aerifal.cx> References: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1530045711 28156 195.159.176.226 (26 Jun 2018 20:41:51 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 26 Jun 2018 20:41:51 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-12961-gllmg-musl=m.gmane.org@lists.openwall.com Tue Jun 26 22:41:47 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1fXumX-0007An-4M for gllmg-musl@m.gmane.org; Tue, 26 Jun 2018 22:41:45 +0200 Original-Received: (qmail 20286 invoked by uid 550); 26 Jun 2018 20:43:53 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 20262 invoked from network); 26 Jun 2018 20:43:53 -0000 Content-Disposition: inline In-Reply-To: Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:12945 Archived-At: On Fri, Jun 15, 2018 at 01:37:43PM +0000, David CARLIER wrote: > Hi dear lists, > this is my first message so forgive me if this idea had already been rejected. It's definitely not rejected outright, and I think the consensus is to adopt it. But.. > From c0a16cf96b96b009097d6ed656a2a7b8969e8399 Mon Sep 17 00:00:00 2001 > From: David Carlier > Date: Fri, 15 Jun 2018 13:30:09 +0000 > Subject: [PATCH] string: adding simple explicit_bzero implementation. > > glibc implementing it and modern security based code starting > using it widely, here a simple implementation using memory barrier. > --- > include/string.h | 1 + > src/string/explicit_bzero.c | 8 ++++++++ > 2 files changed, 9 insertions(+) > create mode 100644 src/string/explicit_bzero.c > > diff --git a/include/string.h b/include/string.h > index ce1dc300..795a2abc 100644 > --- a/include/string.h > +++ b/include/string.h > @@ -82,6 +82,7 @@ void *memccpy (void *__restrict, const void *__restrict, int, size_t); > char *strsep(char **, const char *); > size_t strlcat (char *, const char *, size_t); > size_t strlcpy (char *, const char *, size_t); > +void explicit_bzero (void *, size_t); > #endif > > #ifdef _GNU_SOURCE > diff --git a/src/string/explicit_bzero.c b/src/string/explicit_bzero.c > new file mode 100644 > index 00000000..47dba3c7 > --- /dev/null > +++ b/src/string/explicit_bzero.c > @@ -0,0 +1,8 @@ > +#define _BSD_SOURCE > +#include > + > +void explicit_bzero(void *d, size_t n) > +{ > + memset(d, 0, n); > + __asm__ volatile("": "r="(d) :: "memory"); > +} > -- The constraint here looks wrong. Normally = is written before the type, not after; I'm not sure if all compiler versions accept the unusual form with it after. But more importantly you have it as an output constraint, where it's essentially a dead store, such that the asm block does nothing to make explicit_bzero force the memset to happen. I think you meant for the constraint to be an input constraint "r"(d). Does that sound right? Rich