Newsgroups: comp.arch Path: csiph.com!feeder.erje.net!2.us.feeder.erje.net!weretis.net!feeder6.news.weretis.net!news.glorb.com!border1.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!kithrup.com!mrs From: mrs@kithrup.com (Mike Stump) Subject: Re: The freedom that give us C++ and C Message-ID: Date: Sat, 6 Feb 2016 13:22:36 GMT References: <2016Jan31.164329@mips.complang.tuwien.ac.at> Organization: Kithrup Enterprises, Ld. X-Newsreader: trn 4.0-test77 (Sep 1, 2010) Lines: 54 Xref: csiph.com comp.arch:33517 In article , David Brown wrote: >On 31/01/16 16:43, Anton Ertl wrote: >> David Brown writes: >>> On 29/01/16 17:03, Anton Ertl wrote: >>>> David Brown writes: > >> Right, blame the OpenSSH programmers for not using a C11 function in >> 2010. The conservative approach is to introduce an optimizable >> memset_o(), and programmers can use that in performance-critical >> places if it is safe to do so. >> > >I blame the OpenSSH programmers for getting their code wrong. Forgive >me if I offer a modern solution along with the alternatives I have given. > >>> The compiler can optimise that as it does >>> with normal memset, using larger writes when it knows they are safe. >>> You could also use the variety of OS or compiler specific functions that >>> exist for the same purpose. Or you could write it faster by hand: >>> >>> void getPassword(void) { >>> union { >>> uint64_t blocks[8]; >>> char pwd[64]; >>> } u; >>> if (GetPassword(u.pwd, sizeof(u.pwd))) { >>> /* Checking of password, secure operations, etc. */ >>> } >>> >>> volatile uint64_t *p = u.blocks; >>> for (int i = 0; i < 8; i++) { >>> *p++ = 0; >>> } >>> } >> >> Better ask a C language lawyer whether a conformant compiler is >> allowed to compile this differently from what you intended. I suspect >> it is. > >Ask away. I believe you are wrong, If the question boils down to does i = 0 zero memory so that it cannot be recovered when i is volatile, that answer is yes. If the question is, can I store into a char, and overwrite anything, the answer is yes. I phrase it this way, as I don't want to miss any indended finer points. _And_ I'd be happy to be corrected by a security expert. I am not one, even though I know more than some. But, let me put it this way, if you have to ask, you're not qualified to write the code, or review the code. Security code is (should be) special, written by people that when faced with a paper bag, can actually code their way out of it. If you think eval is the right method to call on a random string from an untrusted source, well, you should become a wallmart greeter. Welcome to PHP.