lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <25e057c01002250906x6267a3b6xe661abfa12f913cb@mail.gmail.com>
Date:	Thu, 25 Feb 2010 18:06:51 +0100
From:	roel kluin <roel.kluin@...il.com>
To:	Pekka Enberg <penberg@...helsinki.fi>
Cc:	Mikael Pettersson <mikpe@...uu.se>,
	Herbert Xu <herbert@...dor.apana.org.au>,
	"David S. Miller" <davem@...emloft.net>,
	linux-crypto@...r.kernel.org,
	Andrew Morton <akpm@...ux-foundation.org>,
	LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] sha: prevent removal of memset as dead store in 
	sha1_update()

On Thu, Feb 25, 2010 at 5:33 PM, roel kluin <roel.kluin@...il.com> wrote:
> On Thu, Feb 25, 2010 at 5:16 PM, Pekka Enberg <penberg@...helsinki.fi> wrote:
>> On Thu, Feb 25, 2010 at 5:56 PM, Mikael Pettersson <mikpe@...uu.se> wrote:
>>> I fear that the only portable (across compiler versions) and safe
>>> solution is to invoke an assembly-coded dummy function with prototype
>>>
>>>        void use(void *p);
>>>
>>> and rewrite the code above as
>>>
>>>        {
>>>                u32 temp[...];
>>>                ...
>>>                memset(temp, 0, sizeof temp);
>>>                use(temp);
>>>        }
>>>
>>> This forces the compiler to consider the buffer live after the
>>> memset, so the memset cannot be eliminated.
>>
>> So is there some "do not optimize" GCC magic that we could use for a
>> memzero_secret() helper function?
>>
>>                        Pekka
>>
>
>        *(volatile char *)p = *(volatile char *)p;
>
> appears to work when called after the memset:

Or similar to suggested here:

https://www.securecoding.cert.org/confluence/display/cplusplus/MSC06-CPP.+Be+aware+of+compiler+optimization+when+dealing+with+sensitive+data

This memzero_secret() appears to work:

void *memzero_secret(void *v, size_t n) {
        volatile unsigned char *p = v;
        while (n--)
                *p++ = 0;

        return v;
}
---
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void *memzero_secret(void *v, size_t n) {
	volatile unsigned char *p = v;
	while (n--)
		*p++ = 0;

	return v;
}

void foo()
{
	char password[] = "secret";
	password[0]='S';
	printf ("Don't show again: %s\n", password);
	memzero_secret(password, sizeof(password));
	//memset(password, 0, sizeof(password));
}

int main(int argc, char* argv[])
{
	foo();
	int i;
	char foo3[] = "";
	char* bar = &foo3[0];
	for (i = -50; i < 50; i++)
		printf ("%c.", bar[i]);
	printf("\n");
	return 0;
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ