From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12947 Path: news.gmane.org!.POSTED!not-for-mail From: David CARLIER Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] proposal adding explicit_bzero Date: Tue, 26 Jun 2018 21:48:47 +0100 Message-ID: References: <20180626204341.GY1392@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000009ccd7a056f91a08e" X-Trace: blaine.gmane.org 1530046030 17613 195.159.176.226 (26 Jun 2018 20:47:10 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 26 Jun 2018 20:47:10 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-12963-gllmg-musl=m.gmane.org@lists.openwall.com Tue Jun 26 22:47:05 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 1fXurf-0004SZ-93 for gllmg-musl@m.gmane.org; Tue, 26 Jun 2018 22:47:03 +0200 Original-Received: (qmail 26462 invoked by uid 550); 26 Jun 2018 20:49:12 -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 26444 invoked from network); 26 Jun 2018 20:49:11 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=T3a/xYfv98IWQQvE7BESt6nnG9pnZ3ruZmLC3BZVtow=; b=a0nuSEfmCc+zpZJbiRqeDOr3t3OxLjv1K2gSl5B3PmzLlRDuxVhedUyPhnH1xvDg/i uTInX2kZ5B8r819pB/WbwnXlCAgS17o9bGKbC0PoY2ioDkObf3nrk/C2clAmGr7yENNT d30FTkg8E0OEZbjlkdRhtaD/zcme/cj7Kh4URk5iDPXzFe7C94vXUTBqpi3uawW7cLY2 8b598bJ/BktoIyDhMv7SRs45aeeAShNzEFpnibb0Qcv1SPQkXHg+tbNd025FEw8OilAS BizG/VxvBCfCJQP36x3Gg0vXE73mg4EQ23RUgxi6YixOnygohtbRy+PP2WMeSNy6T/Wj +reQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=T3a/xYfv98IWQQvE7BESt6nnG9pnZ3ruZmLC3BZVtow=; b=pMMfCUlh5UDsW4Z/zLr1xAbsrjIYLHrsE+AQ8gfACxm2g59F6r98QEaTlLBcBWwLnU a1aOizpl1h3NaLewWES+/igA5gjwECkqOiCB63hmgIewzqpS6mwDyhdUvrbNuWVOqhkq iuh7UIvf56ch+uIsBnw9T+LFDXa4amsx/OAbn/zeoYJeUIZjLlDS4z+4m1oEGBGss0ZW ESGR/Q45iEzAg5qF5wZU2Vld9vJSJbVAjoUkG7XU3yZ73e+9YatAZPT/1lUovVNrxvvy SAs4H5zFntMr887u0LaXjLZO7OSDQ5aPU2tRSDaCHgrdx5jnlC61/BbEloyWAAuktCtV jKXQ== X-Gm-Message-State: APt69E2LQUalGU+8qMk5hP8HEAzL292youd6/MQ9EJHls7RAhuYnlkwD l/yIjjyXsZN66jisxOcyiLR8Cv28pdwWcW50Og8= X-Google-Smtp-Source: AAOMgpdkbnB5r9jzmIRXtnfnetPLNe15C4CMjR+k8kWcEnH2AoAy4Be+0uRGy1hpo3TWDbSvRO/cH8NeJUpOut5LQds= X-Received: by 2002:aca:4456:: with SMTP id r83-v6mr1688559oia.270.1530046139123; Tue, 26 Jun 2018 13:48:59 -0700 (PDT) In-Reply-To: <20180626204341.GY1392@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:12947 Archived-At: --0000000000009ccd7a056f91a08e Content-Type: text/plain; charset="UTF-8" Yes true sorry :-|. Kind regards. On Tue, 26 Jun 2018 at 21:43, Rich Felker wrote: > 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 > --0000000000009ccd7a056f91a08e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Yes true sorry :-|.

Kind= regards.

On Tue= , 26 Jun 2018 at 21:43, Rich Felker <= dalias@libc.org> wrote:
On F= ri, 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 r= ejected.

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 <dcarlier@afilias.info>
> Date: Fri, 15 Jun 2018 13:30:09 +0000
> Subject: [PATCH] string: adding simple explicit_bzero implementation.<= br> >
> glibc implementing it and modern security based code starting
> using it widely, here a simple implementation using memory barrier. > ---
>=C2=A0 include/string.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | 1 +<= br> >=C2=A0 src/string/explicit_bzero.c | 8 ++++++++
>=C2=A0 2 files changed, 9 insertions(+)
>=C2=A0 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 *__restr= ict, int, size_t);
>=C2=A0 char *strsep(char **, const char *);
>=C2=A0 size_t strlcat (char *, const char *, size_t);
>=C2=A0 size_t strlcpy (char *, const char *, size_t);
> +void explicit_bzero (void *, size_t);
>=C2=A0 #endif
>=C2=A0
>=C2=A0 #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 <string.h>
> +
> +void explicit_bzero(void *d, size_t n)
> +{
> +=C2=A0 =C2=A0 =C2=A0memset(d, 0, n);
> +=C2=A0 =C2=A0 =C2=A0__asm__ volatile("": "r=3D"(d= ) :: "memory");
> +}
> --

The constraint here looks wrong. Normally =3D 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
--0000000000009ccd7a056f91a08e--