News for hackers. Stuff that matters.

jcr1488

Re:Stop Memsetting Structures on Wednesday May 01, 2019 @08:38AM (#19796494)
> That step is 90% of the work

I spent several years working on a production grade compiler and I can assure you it's not. But keep just making things up off the top of your head if it makes you feel smart.

Re:Stop Memsetting Structures on Tuesday April 30, 2019 @03:16AM (#19785772)
> It's just a type of dead store elimination

It's not just any, typical kind of dead store elimination. It also would require other optimization passes that I can assure you no mainstream compiler actually does. You can disagree with me if you want, but you're simply wrong.

Re:Stop Memsetting Structures on Monday April 29, 2019 @03:18AM (#19776459)
> This is the kind of thing that can break by accident and ruin everyone's month.

Not in practice. Compilers make use of undefined behaviour to optimize things that are widely applicable and profitable. No real compiler does what you're saying and no future compiler is likely to without explicitly being asked to.

I agree that, by the letter of the spec, you're right, but you're still most certainly overstating the relevance.

I'm not arguing that this isn't a real problem or that people shouldn't use memzero_explicit() (or similar) where security is on the line, as I already said several times in another sub-thread -- I'm just saying that this kind of thing is extreme language-lawyering beyond the realms of probability. It's still not an excuse to be lax, but let's be realistic about the actual likelihood of it happening.

Re:Stop Memsetting Structures on Sunday April 28, 2019 @11:04PM (#19775514)
As soon as a pointer to said memory is passed to an extern function in another translation unit, the compiler can't prove anything about how it's used, which is the case in pretty much all of the examples mentioned in this thread.

Also, type-punning is a thing. memset is byte-oriented/memory-oriented. Just because you're using it to zero a struct of a particular kind doesn't mean that's the only way the memory will accessed. Just because reading the padding of some struct is undefined behaviour doesn't mean accessing those bits by some other means is also undefined.

A compiler usually can't eliminate a call to memset() in most practical cases of initialization (where memory leakage is also a concern) because they almost always pass a reference to a routine in another translation unit. Something like memzero_explicit() can be used anyway -- but you're massively overstating the relevance of compilers eliminating dead stores done via memset(). It's much more of an issue for post-destruction memory sanitizing (which is the primary use case for memzero_explicit) than it is for compiler f*ckery when memset() is used for initialization.

Re:Stop Memsetting Structures on Sunday April 28, 2019 @08:27AM (#19770765)
You mean it can remove a memset() that doesn't cause the observable behaviour to change?

For the sake of argument, can you show me some example code where it would be conforming to remove a memset() call? Preferably a realistic example and not a Google'd copypasta. Because it's all too easy to just regurgitate things you heard and think you understood, but no so easy to demonstrate it yourself.

Re:Stop Memsetting Structures on Sunday April 28, 2019 @05:23AM (#19770173)
You clearly haven't understood the thread.
Re:Stop Memsetting Structures on Sunday April 28, 2019 @01:51AM (#19769577)
I guess we are misunderstanding each other's point. I just found hermitdev's comment to be misleading (despite being correct), but perhaps it's just my reading of it.

To be fair though, memset() usually IS a fix. As mentioned by the kernel memzero_explicit() docs:

> usually using memset is just fine (!)

-- https://www.kernel.org/doc/htmldocs/kernel-api/API-memzero-e...

A conforming C compiler can't just remove memset() as it pleases. The case that most often requires memzero_explicit() is when zeroing an object after destruction, because the compiler thinks it can statically determine that it's a dead store. It very rarely happens that a compiler elides a memset() used for initialization.

I'm not sure why you seem to think that memset() can just be dropped at will for no reason whatsoever or that it's somehow always undefined behaviour.

Re:Stop Memsetting Structures on Sunday April 28, 2019 @01:22AM (#19769502)
> But the problem is that the security concerns and fixes are all undefined here.

No one in this sub-thread has mentioned (or implied) any "fix". You appear to be putting words in my mouth.

> So the initial comment is still very right.

Of course it's right, but it's also misleading when read in the context of the parent comment.

> If you're relying on the padding to be anything in particular, you're in trouble.

No shit.

Re:Stop Memsetting Structures on Sunday April 28, 2019 @12:38AM (#19769375)
Right, but I didn't make a case that memset() is any more secure, did I? The parent comment was talking about undefined behaviour as if it's some kind of universal get-out clause.
Re:Stepping Away from Sass on Saturday April 27, 2019 @11:17PM (#19769112)
What's even more weird is making every 10 line function a "library" and the average program having 500+ dependencies. JS people are so hung up on "re-usability" that they completely miss the concept of dependency hygiene.
Re:Stop Memsetting Structures on Saturday April 27, 2019 @10:25PM (#19768903)
If you pass partially uninitialized objects (including padding) between kernel space and user space, there's a chance that the (less privileged) user space code can recover information it shouldn't be able to see, regardless of what the spec says about undefined behaviour. Such information may include secrets that previously occupied the memory where a new, unrelated struct now resides. The same can also apply to passing objects between different machines.

All "undefined behaviour" means is that the spec can no longer guarantee anything about the execution of a program once a constraint is violated. It doesn't say anything about the practicality of actually doing it on any given implementation.

FWIW I didn't downvote you, but your reasoning about undefined behaviour seems overly simplistic. It should never be used to explain away security concerns.

Re:Vim.wasm on Friday April 26, 2019 @06:40AM (#19756139)
What has he done, besides The Cathedral and the Bazaar...?

Most of his open source contributions seem to be littering up source files with long-winded comments and grandiose attributions to himself. I've read a fair bit of his code and it's certainly not impressive. Quite the opposite actually.

Re:Vim.wasm on Thursday April 25, 2019 @09:11PM (#19754013)
I'm further right on the political spectrum than ESR is. It's his delusions of grandeur and constant, smug championing of his own relevance that I can't stand...
Re:Stepping Away from Sass on Thursday April 25, 2019 @09:08PM (#19754006)
> Everyone forgets that SASS is meant to be programmable CSS

That sounds like a solution looking for a problem... The vast majority of real SASS I've seen has been much like the stuff this article mentions.

> If you treat it as CSS+ then you're not really benefitting from it's true potential

People aren't looking for "potential", they're looking for a way to accomplish their design goals whilst keeping their stylesheets maintainable. The real use cases where SASS is actually worth the complexity overheads are getting fewer and fewer.

Re:Vim.wasm on Thursday April 25, 2019 @06:41AM (#19746722)
I'm not sure. I think the caret is just a prefix to make it distinguishable from the normal letters.

It is the reason why Ctrl+i in a terminal is the same as Tab though. Likewise for Ctrl+m == Enter.

Re:Vim.wasm on Thursday April 25, 2019 @05:44AM (#19746454)
ESR is a poseur who doesn't belong next to those other names.
Re:Vim.wasm on Thursday April 25, 2019 @05:31AM (#19746407)
> Holding `CTRL` essentially lops off the first three bits

No, it inverts the 7th bit (or subtracts 64).

The Linux `ascii(7)` man page has a similar table, but with 2 columns. The first 32 control characters listed there have their "caret notation" character in the opposite column.