|
|
Subscribe / Log in / New account

Cook: security things in Linux v5.0

Kees Cook reviews some of the security-related enhancements in the 5.0 kernel. "While the C language has a statement to indicate the end of a switch case ('break'), it doesn’t have a statement to indicate that execution should fall through to the next case statement (just the lack of a 'break' is used to indicate it should fall through — but this is not always the case), and such 'implicit fall-through' may lead to bugs. Gustavo Silva has been the driving force behind fixing these since at least v4.14, with well over 300 patches on the topic alone (and over 20 missing break statements found and fixed as a result of the work). The goal is to be able to add -Wimplicit-fallthrough to the build so that the kernel will stay entirely free of this class of bug going forward. From roughly 2300 warnings, the kernel is now down to about 200. It’s also worth noting that with Stephen Rothwell’s help, this bug has been kept out of linux-next by him sending warning emails to any tree maintainers where a new instance is introduced (for example, here’s a bug introduced on Feb 20th and fixed on Feb 21st)."

to post comments

Cook: security things in Linux v5.0

Posted Mar 13, 2019 18:38 UTC (Wed) by zblaxell (subscriber, #26385) [Link]

> The goal is to be able to add -Wimplicit-fallthrough to the build so that the kernel will stay entirely free of this class of bug going forward.

"-Werror=implicit-fallthrough" would be more effective, but you'd have to get all the way to zero warnings first.

Cook: security things in Linux v5.0

Posted Mar 13, 2019 19:12 UTC (Wed) by rweikusat2 (subscriber, #117920) [Link] (105 responses)

The C language doesn't have "a statement indicating the end a switch case" (seriously bizarre idea) because the C switch statement is not a (Pascal-style) multiway conditional. It's sort-of a computed goto where an expression is evaluated and execution continues at a certain label depending on the outcome.

What about "fixing" people writing code in C (the language is not that complicated, mind you) instead of inventing one bazillion
/*** OMFG !! Not like Pascal !!! ***/ pseudosyntactic tags?

Fixing programmers

Posted Mar 13, 2019 19:15 UTC (Wed) by corbet (editor, #1) [Link] (101 responses)

Perhaps because humans have this nasty tendency to be ... humans ... who will, when using a language that makes it easy to code certain types of mistakes, make those mistakes? Fixing the people has never been a workable solution to this kind of security issue; why would you expect this case to be different?

Fixing programmers

Posted Mar 13, 2019 19:35 UTC (Wed) by rweikusat2 (subscriber, #117920) [Link] (93 responses)

"Humans just can't learn!" wouldn't get anyone very far in a maths test (or any other kind of interview/ examination).

The C switch statements has certain properties. One could argue whether all of these properties are really desirable, but that's not going to change it. And adding /** I really disagree **/ comments to source code doesn't improve that (the code).

I have to open three different locks with three different keys when trying to get into my flat. Two of them even look identical and can only be distinguished by knowing their relative positions on the keyring. This is vastly more complicated than remembering that a break needs to be added to the end of 'a switch case 'if execution of code in the corresponding block is supposed to be terminated. Yet, human beings without any higher qualifications are expected to be able to do the former while it is claimed that "nobody" can do the latter. Strange, isn't it?

Whenever people have to make a decision, they'll sometimes get this decision wrong. But they will usually get it right most of the time, as evidenced by the miniscule number of missing breaks (compared to the size of the codebase) found during the course of this (a Linux source I happen to have lying around here contains 45,021 switch statements. 20 missing breaks in n * 45,021 cases, n > 2, is decidedly miniscule).

Fixing programmers

Posted Mar 13, 2019 19:40 UTC (Wed) by Cyberax (✭ supporter ✭, #52523) [Link]

> "Humans just can't learn!" wouldn't get anyone very far in a maths test (or any other kind of interview/ examination).
The number of CVEs caused by a missed "break" tends to confirm that people suck at math.

Fixing programmers

Posted Mar 13, 2019 19:43 UTC (Wed) by rahulsundaram (subscriber, #21946) [Link] (51 responses)

> What about "fixing" people writing code in C (the language is not that complicated, mind you)

All the empirical evidence including plenty of research and billions of dollars spent on fixing bugs in such code clearly indicates otherwise.

> And adding /** I really disagree **/ comments to source code doesn't improve that (the code).

That's not really what is happening here though. The specific comment here is being parsed by the compiler and therefore really is part of the code.

Fixing programmers

Posted Mar 13, 2019 20:38 UTC (Wed) by rweikusat2 (subscriber, #117920) [Link] (50 responses)

JFTR: This was already a feature of the original lint dating back to about 1977.

Fixing programmers

Posted Mar 13, 2019 20:45 UTC (Wed) by rahulsundaram (subscriber, #21946) [Link] (49 responses)

> JFTR: This was already a feature of the original lint dating back to about 1977.

Lots of tooling existed before but being part of the compiler makes them more readily available and even better if it is the default.

Fixing programmers

Posted Mar 13, 2019 21:38 UTC (Wed) by rweikusat2 (subscriber, #117920) [Link] (48 responses)

Clang/ gcc copying features from lint doesn't make these any more interesting than they were before. The idea that programmers should add cute little comments like

/* fallthru */

to express that they were actually planning to use a certain language feature in a machine-readable way is seriously old. The effect of this is that features someone considers particularly disagreeable become somewhat more complicated to use and that the code becomes cluttered (to a degree) with completely useless comments. Presence or absence of such comments doesn't indicate anything about correctness or incorrectness of the code.

Fixing programmers

Posted Mar 14, 2019 6:33 UTC (Thu) by epa (subscriber, #39769) [Link] (42 responses)

That would be true if someone were mindlessly adding ‘fall through’ markers in every place the language feature is used. That would indeed be a completely pointless exercise. But as I understand it, before adding the marker you first audit the code to make sure falling through is deliberate and not an oversight. Given the number of bugs that have been found in the past this auditing is a good use of time and likely to uncover and fix more bugs. When new code is written, having to add the marker serves as a reminder to the programmer to think about whether falling through is wanted. If programmers were machines this reminder would not be helpful. But experience shows that even the most highly skilled programmers occasionally make mistakes, and this is one of the more common of then, yet easy to prevent with a bit of tooling.

Fixing programmers

Posted Mar 14, 2019 16:19 UTC (Thu) by rweikusat2 (subscriber, #117920) [Link] (41 responses)

This "reminder" that a very vocal group of people has been disagreeing with pretty much any C design decision since 197x isn't useful. A much better idea would be to push for a language extension with the desired semantics, assuming some set of desired semantics can ever be agreed on. The sorry mess of Perl given/ when which will probably forever have someone's weird ideas about DWIM operators ("dumb matching") tied to its ankles should serve as a warning here. This would help to avoid the problem (if there is a problem) instead of just "keep on nagging for a few more decades!".

Fixing programmers

Posted Mar 14, 2019 18:31 UTC (Thu) by HelloWorld (guest, #56129) [Link] (38 responses)

> This "reminder" that a very vocal group of people has been disagreeing with pretty much any C design decision since 197x isn't useful. A much better idea would be to push for a language extension with the desired semantics, assuming some set of desired semantics can ever be agreed on.
How is a "fallthrough comment" at the end of a case branch not a language extension, assuming that its presence is enforced by the compiler?

Besides, this has been standardized in C++17. The only reason it's not in C is that the C committee is run by a bunch of stick-in-the-muds.

Fixing programmers

Posted Mar 14, 2019 21:19 UTC (Thu) by rweikusat2 (subscriber, #117920) [Link] (35 responses)

What's so wonderful about always trying to misunderstand something?

It is claimed that the semantics of switch, specifically, that it provides a way to jump to a certain location in a block but no automatic exit from there before the code tagged with the next case-label starts, are problematic. Assuming this problem exists (cf next paragraph), adding a metasyntactical sort-of language extension requiring an explicit something in both cases doesn't solve it. It just punishes people who need the fallthrough semantics. What would solve it would be to add another syntactic construct providing an actual multiway conditional, where the code blocks associated with the cases are independent of each other and at most one will be executed.

As to the "problematic", are we perhaps totemically repeating some "But that's not how I think it should be done!"-complaints someone initially made at least 40 years ago which since keep being repeated out of habit? According to the numbers in the text, about 99% of the warnings were false positives. Comparing the number of case-labels in a current -stable tree with the number of missing breaks indicates that this aspect of the code was correct in about 99.99% of all cases. This doesn't look like a "common" problem to me.

Fixing programmers

Posted Mar 14, 2019 23:03 UTC (Thu) by Cyberax (✭ supporter ✭, #52523) [Link] (30 responses)

> What would solve it would be to add another syntactic construct providing an actual multiway conditional, where the code blocks associated with the cases are independent of each other and at most one will be executed.
Why? Switch is fine for this. In 99% of cases it's NOT used as computed goto, so implicit fallthrough is actively harmful.

That's why other more modern languages (C#, Go, ...) have ditched that stupid semantics.

And yes, it's stupid. So stupid that the very first linter for C had the "forgotten break" inspection.

Fixing programmers

Posted Mar 15, 2019 15:56 UTC (Fri) by rweikusat2 (subscriber, #117920) [Link] (29 responses)

"Switch is fine except that it's not"?

I agree that the fallthrough is mostly useless and that all the time people and computers wasted by typing or processing

break;

statements could have been put to better uses. But overloading the syntax supposed to be used for inline documentation so that yet more useless code has to be added is not the answer, it's the problem taken to the next power.

Fixing programmers

Posted Mar 15, 2019 20:46 UTC (Fri) by myxie (subscriber, #127909) [Link] (28 responses)

If only the original designers of C had thought of using a different keyword to indicate continuing to the next case... but that would have meant another keyword to add to the language... or would it have? :-)

I'm almost scared to look up the semantics of continue inside a switch statement.

Fixing programmers

Posted Mar 15, 2019 21:15 UTC (Fri) by mpr22 (subscriber, #60784) [Link]

continue inside a switch has no special semantics - if you're inside a loop construct then it interacts with the loop, otherwise it's an error.

Fixing programmers

Posted Mar 15, 2019 21:36 UTC (Fri) by madscientist (subscriber, #16861) [Link] (26 responses)

Continue and return work the same inside a switch statement as outside a switch statement. They are not special.

The main problem is K&R chose the wrong "default" behavior. Usually you DON'T want to continue, so that should have been the default (that is, the current case is automatically terminated by the next case or the end of the statement), and there should be a special keyword used only when you DO want to fall through.

The one exception is empty cases ("case a: case b: case c: foo(); break;") A special dispensation could have been made that the keyword is not needed to fall through unless there are other statements in the case: empty cases don't need the keyword.

Of course, you need a different keyword. They could have used "continue", but both "break" and "continue" are already useful from within switch statements (to break out of or continue an enclosing loop) so using either one of them as meaningful inside a switch was (IMO) not a good decision. I've definitely run into situations where I wanted to break out of a loop from within a switch statement and having "break" overloaded is annoying.

A "fallthrough" or "nobreak" keyword would have been fine. Or if you REALLY didn't want to add a keyword you could have played tricks with "goto", maybe, allowing "goto case X;" where "case X:" existed somewhere in the current switch statement, plus "goto default;"

But that's not the language we have, so FALLTHROUGH-type comments that are recognized by the compiler are great things and everyone should use them. Even if they're weren't recognized by the compiler, they're recognized by the next programmer to come along and read the code, and make clear that you didn't forget something, so they should still always be used.

Fixing programmers

Posted Mar 15, 2019 21:44 UTC (Fri) by rweikusat2 (subscriber, #117920) [Link] (22 responses)

> But that's not the language we have, so FALLTHROUGH-type comments that are recognized by the compiler are great things and
> everyone should use them. Even if they're weren't recognized by the compiler, they're recognized by the next programmer to come > along and read the code, and make clear that you didn't forget something, so they should still always be used.

They make clear that someone was using lint (or similar). Not particularly interesting and technically useless as the default case is - well - the default case. Whether or not this is correct is a different conversation, but that's something which can only be determined by looking at the code. There's no more reason to assume that two cases with fallthrough are correct or incorrect than two cases seprated by a break;. I've actually written code where I forgot to omit the break in the past :-).

Fixing programmers

Posted Mar 15, 2019 22:42 UTC (Fri) by madscientist (subscriber, #16861) [Link] (20 responses)

> They make clear that someone was using lint (or similar). Not particularly interesting and
> technically useless as the default case is - well - the default case. Whether or not this is
> correct is a different conversation, but that's something which can only be determined by
> looking at the code. There's no more reason to assume that two cases with fallthrough
> are correct or incorrect than two cases seprated by a break;. I've actually written code
> where I forgot to omit the break in the past :-).

I'm not going to get drawn too far into this conversation because it's ridiculous, but I'll say that the above is at best missing the point.

A fallthrough comment is not trying to tell you whether or not the code will fall through. Obviously it will, there's no break! The comment is telling you that someone thought about it and INTENDED the fallthrough to happen.

If lint or the compiler warns someone about a missing break and they want a break, they'll obviously just add a break. If they get a warning and they intended to fallthrough, they will add a fallthrough comment. If they didn't add either one then you don't know whether they thought about it and intended the fallthrough, or they just forgot.

Of course, even with the comment the fallthrough behavior could be a bug. Code has bugs. But the comment is not telling you the code is bug-free, it's telling you that it's intentional, rather than an omission. That's still a big benefit.

Fixing programmers

Posted Mar 17, 2019 20:29 UTC (Sun) by rweikusat2 (subscriber, #117920) [Link] (19 responses)

> A fallthrough comment is not trying to tell you whether or not the code will fall through. Obviously it will, there's no break! The
> comment is telling you that someone thought about it and INTENDED the fallthrough to happen.

It's usually safe to assume that code came to be in a certain form because someone was convinced it would be the right way to solve a particular problem. But that's not particularly interesting. Interestsing is "is it the right way".

Fixing programmers

Posted Mar 18, 2019 13:49 UTC (Mon) by mathstuf (subscriber, #69389) [Link] (18 responses)

Depends. Sometimes "uninteresting" parts of a patch are done at a late (or early) hour and is just more prone to typos and errors. Reviews are invaluable to every coder, from those learning anew all the way up to Linus. One of the first things I do after opening a merge request is do another look over the code. I've lost count of how many 5-minute-later pushes I've made because of that. Or if I find a bigger issue, I at least leave a comment that something looks weird and might need more thought.

Fixing programmers

Posted Mar 18, 2019 16:14 UTC (Mon) by jezuch (subscriber, #52988) [Link]

I do that too, *and* I do the initial commit using git commit -p as a kind of self-review. Catches plenty of stuff I wanted to do or did temporarily but forgot etc.

Fixing programmers

Posted Mar 18, 2019 19:40 UTC (Mon) by rweikusat2 (subscriber, #117920) [Link] (16 responses)

I don't understand what that's supposed to mean in the given context.

I was trying to express two things:

1) Noting that a break is absent isn't sufficient grounds to assume that this must have been an oversight unless there's an a priori conviction that this is a very likely cause for an absent break. Considering the "99% false positives", such a conviction doesn't seem sensible to me.

2) Computers execute code as it was written, not as it was intended to be written. An absent break which was an oversight isn't necessarily an error. And neither is a conscious omission or a present break necessarily correct.

Fixing programmers

Posted Mar 18, 2019 19:53 UTC (Mon) by mathstuf (subscriber, #69389) [Link] (15 responses)

As a reviewer, I would want a positive indication of intent for either behavior. A lack of either break or a fallthrough comment/attribute is an automatic request for "please clarify". The goal isn't to make code writer's jobs easier, but those who have yet to come and read the code.

Fixing programmers

Posted Mar 18, 2019 21:46 UTC (Mon) by rweikusat2 (subscriber, #117920) [Link] (14 responses)

As I've already explained: Intent doesn't matter. Correctness does. YMMV.

Fixing programmers

Posted Mar 18, 2019 22:11 UTC (Mon) by Cyberax (✭ supporter ✭, #52523) [Link] (9 responses)

Actually you got it wrong. Correctness doesn’t matter. The intent does.

Fixing programmers

Posted Mar 18, 2019 22:29 UTC (Mon) by rweikusat2 (subscriber, #117920) [Link] (8 responses)

If you think so, that's your opinion and not mine.

As person who spends a seriously lot of time working with other people's code (and has done so for about 15 years), I can assure you that I don't give $random_small_quantity_of_money for documentation of "programmer intent", especially not in form of otherwise uninformative comments. I need to know what the code does, not what someone believed it should be doing.

Fixing programmers

Posted Mar 18, 2019 22:33 UTC (Mon) by Cyberax (✭ supporter ✭, #52523) [Link]

> I need to know what the code does, not what someone believed it should be doing.
So you need to know the intent. Duh. You're just deluding yourself at this point.

Correctness checking is TRIVIAL, it's not even worthy of mentioning. Checking of intent is anything but. And that's exactly why modern computer languages try to make it easier for developers to express their intent through code.

Fixing programmers

Posted Mar 18, 2019 22:39 UTC (Mon) by sfeam (subscriber, #2841) [Link]

I believe you have this backwards. What the code does can be determined in the absence of comments. The intent, not so much. That is why comments are valuable for bug-finding. Any place where the documented intent does not match the observed actual behavior is candidate for causing problems.

Fixing programmers

Posted Mar 19, 2019 12:24 UTC (Tue) by anselm (subscriber, #2796) [Link] (5 responses)

The goal of computer programming is to write code that does what it is supposed to be doing. You can use the code itself to figure out what it does, but you can't use the code itself to figure out whether it does what it is supposed to be doing.

It's very easy to write code that does something. Writing code that does what it it supposed to do is a lot harder, and requires outside context so you can determine when you're done. This is why in Real Life™ we have comments, specifications, unit tests, and so on – all to be able to figure out whether code does what it is supposed to do.

Fixing programmers

Posted Mar 19, 2019 14:14 UTC (Tue) by mathstuf (subscriber, #69389) [Link] (4 responses)

There are a few fields where I can see the actual behavior of the code is of utmost importance, damn the intent. Static analysis and zero day hunting to name a few. In these cases, what the intent was actually doesn't matter and correctness is all that counts. However, these fields usually result in changes to the analyzed code when something "interesting" is found, so intent can matter again at that point.

Fixing programmers

Posted Mar 19, 2019 14:31 UTC (Tue) by NAR (subscriber, #1313) [Link] (3 responses)

what the intent was actually doesn't matter and correctness is all that counts.

How can you check correctness when you don't know what that code is supposed to do?

Fixing programmers

Posted Mar 19, 2019 14:43 UTC (Tue) by mathstuf (subscriber, #69389) [Link] (2 responses)

For zero-day hacking, the intent doesn't matter. All that matters is that you can thread your special arguments through to some internal state that allows you access to something else that you normally wouldn't be able to access. In *fixing* the issue, intent again enters the picture since just closing the hole naïvely can block some use case that is supposed to be intended (or break some subtle backwards compatibility). Static analysis is similar. It's goal is to detect what the actual code does, match it against code smells and flag such code. Intent then comes in when you either suppress the notice or change the code to make the code not wrong.

Fixing programmers

Posted Mar 19, 2019 14:55 UTC (Tue) by NAR (subscriber, #1313) [Link] (1 responses)

that allows you access to something else that you normally wouldn't be able to access.

You're making the assumption that this particular access was not intended. So intent matters.

Fixing programmers

Posted Mar 19, 2019 14:59 UTC (Tue) by mathstuf (subscriber, #69389) [Link]

Granted, but I feel that the intent that matters is a much higher-level construct in black hat hacking than "should this case statement have a break statement?".

Fixing programmers

Posted Mar 19, 2019 10:02 UTC (Tue) by NAR (subscriber, #1313) [Link] (3 responses)

Intent doesn't matter. Correctness does.

Let's say I have this code snippet: a = b + c; Is it correct?

Fixing programmers

Posted Mar 19, 2019 21:44 UTC (Tue) by neilbrown (subscriber, #359) [Link] (2 responses)

> Let's say I have this code snippet: a = b + c; Is it correct?

Yes it is.
Your statement "I have this code snippet: a = b + c" is self-evidently correct.

Fixing programmers

Posted Mar 19, 2019 22:03 UTC (Tue) by pizza (subscriber, #46) [Link] (1 responses)

By that definition, the Therac-25 "correctly" killed three people.

Fixing programmers

Posted Mar 19, 2019 23:24 UTC (Tue) by neilbrown (subscriber, #359) [Link]

> By that definition, the Therac-25 "correctly" killed three people.

Sorry to correct you, but I think you mean "It is correct that 'The Therac-25 killed three people' ".

And this is the point - when people start using broad terms like "intent" and "correct" without ensuring that all corespondents are using them in the same sense, you can hardly expect a useful conversation to result.

(wouldn't it be great if people would think about what they write, instead of just writing about what they think).

Fixing programmers

Posted Mar 19, 2019 10:37 UTC (Tue) by HelloWorld (guest, #56129) [Link]

> There's no more reason to assume that two cases with fallthrough are correct or incorrect than two cases seprated by a break;. I've actually written code where I forgot to omit the break in the past :-).
There are actually two reasons:
– the case where you want to use break is vastly more common than the case where you want to fall through
– it's easier to forget adding the break keyword than it is to accidentally add the fall-through attribute

> I've actually written code where I forgot to omit the break in the past :-).
The article mentions 20 cases of missing break statements that were uncovered by this work, while it doesn't mention any cases like the one you describe. It's safe to say that missing break statements are a much more frequent occurrence.

Fixing programmers

Posted Mar 15, 2019 23:15 UTC (Fri) by mjg59 (subscriber, #23239) [Link]

C# blocks implicit fallthrough and requires an explicit goto statement referencing another switch label. goto might be considered harmful in general, but its use there seems consistent with the way it's generally used in the kernel.

Fixing programmers

Posted Mar 16, 2019 23:53 UTC (Sat) by Wol (subscriber, #4433) [Link] (1 responses)

Maybe we could add an optional keyword?

switch nofallthrough {
case a:
case b:
}

As for break being overloaded, can't remember the language but it was something like

labela: for i = 1 to 10
labelb: for j = 10 to 1 step -1
do something
if x continue labela
next
next

so break or continue could take labels to indicate which construct they were meant to break out of.

Cheers,
Wol

Fixing programmers

Posted Mar 17, 2019 0:28 UTC (Sun) by ABCD (subscriber, #53650) [Link]

Among possibly other languages, Java allows this:

labela:
for (int i = 1; i <= 10; i++) {
    labelb:
    for (int j = 10; j >= 1; j--) {
        do_something(i, j);
        if (x) continue labela;
    }
}

Fixing programmers

Posted Mar 15, 2019 7:11 UTC (Fri) by HelloWorld (guest, #56129) [Link]

> Assuming this problem exists (cf next paragraph), adding a metasyntactical sort-of language extension requiring an explicit something in both cases doesn't solve it.
Actually it does.

Fixing programmers

Posted Mar 15, 2019 13:33 UTC (Fri) by anselm (subscriber, #2796) [Link] (2 responses)

What would solve it would be to add another syntactic construct providing an actual multiway conditional, where the code blocks associated with the cases are independent of each other and at most one will be executed.

That would help. But programs using this construct would no longer be C programs. If sticking to a popular and well-understood language standard is of value to you (which makes sense in a large community like the Linux kernel crowd), then this is something not to be thrown away lightly.

OTOH, code that uses the “metasyntactical sort-of language extension” is valid C whether the compiler pays attention to it or not. But if you have a compiler that does pay attention, it's probably a good idea to exploit that, much like we exploit our compiler's paying attention to all sorts of other little things that might otherwise slip us by (think “if (foo = bar) …”).

Like a surgical scalpel, the C programming language is conceptually pretty simple but using it still requires considerable care and attention to detail. I haven't done lots of C programming recently but when I do I'm humble enough to appreciate all the assistance I can get.

Fixing programmers

Posted Mar 15, 2019 15:51 UTC (Fri) by rweikusat2 (subscriber, #117920) [Link] (1 responses)

Linux makes heavy use of gcc extensions already, so, their would be little, additional damage done here. Further, my opinion on this is that C would benefit more from proper multiway conditional than from other, invasive additions like threading support, IOW, if someone would implement support for something like this in a compiler I could use, I'd certainly be using it and expect that the standardized language would eventually catch up.

BTW, I've come to dislike if (a = b) warnings as well: Mistyping == as = is another, extremely rare error and some things will always have to be found and fixed via code rewiev and/ or testing. Algorithmic errors are far more common than any kind of syntax misuse.

Fixing programmers

Posted Mar 15, 2019 17:52 UTC (Fri) by anselm (subscriber, #2796) [Link]

Mistyping == as = is another, extremely rare error and some things will always have to be found and fixed via code rewiev and/ or testing.

You want code review and testing, but you also want reasonable compiler warnings. If a developer is made aware of a “==” vs. “=” typo by a compiler warning while they're writing the code in the first place, the issue doesn't even come up in code review or testing (where it would be more expensive, in terms of developer time, to detect and fix). This is what in security circles we call “defense in depth”.

Algorithmic errors are far more common than any kind of syntax misuse.

Yes, but the syntax problems still exist and are often easier to detect and fix. This is like saying garbage in the street is not important because there are millions of children starving in Africa.

Fixing programmers

Posted Mar 15, 2019 15:28 UTC (Fri) by jrigg (guest, #30848) [Link] (1 responses)

> the C committee is run by a bunch of stick-in-the-muds.
This could be considered a feature.

Fixing programmers

Posted Mar 16, 2019 9:22 UTC (Sat) by HelloWorld (guest, #56129) [Link]

> This could be considered a feature.
Yes, by other stick-in-the-muds.

Fixing programmers

Posted Mar 15, 2019 8:53 UTC (Fri) by epa (subscriber, #39769) [Link] (1 responses)

OK, so I can only speak for my personal experience here. When writing switch statements I sometimes forget the 'break;' at the end of one case. This happens by accident rather more frequently than the times when I deliberately want to use fallthrough. So for me, it saves time to have a warning or error from the compiler when implicit fallthrough is used -- it saves my time in headscratching and debugging when the code doesn't work, and may in some cases stop buggy code from being used in production systems. This has nothing to do with "disagreeing" with the C standard. There are plenty of other cases where the standard allows a particular construct but I prefer to get a warning, because it is empirically more likely to indicate a mistake on my part rather than a deliberate choice, and so the warning helps me be a more productive programmer. YMMV.

A language extension is a great idea. GCC effectively provides a GCC-specific extension to the C language here -- or perhaps you could call it a restriction, since the code allowed with -Wimplicit-fallthrough is a subset of that without the warning. Either way, it's useful in practice to many programmers, and Linux has started making use of it. Pushing it upstream to the ISO C standard would be better still of course.

Fixing programmers

Posted Mar 15, 2019 10:28 UTC (Fri) by HelloWorld (guest, #56129) [Link]

> Pushing it upstream to the ISO C standard would be better still of course.
Or people could just switch to C++ where is this already standardized, along with dozens of other useful features.
https://en.cppreference.com/w/cpp/language/attributes/fal...

Fixing programmers

Posted Mar 16, 2019 5:09 UTC (Sat) by scientes (guest, #83068) [Link] (4 responses)

It is also a bad idea to parse comments. It breaks distcc for example, so I submitted a patch fixing this stupidness

https://lkml.org/lkml/2019/3/15/792

Fixing programmers

Posted Mar 16, 2019 9:25 UTC (Sat) by HelloWorld (guest, #56129) [Link] (3 responses)

How does this break distcc?

Fixing programmers

Posted Mar 16, 2019 21:32 UTC (Sat) by zlynx (guest, #2285) [Link] (2 responses)

If I remember correctly (it's been many years since I last used distcc), distcc sends each compiler a preprocessed source file. It does this to avoid the need to send every include file along with the source file.

Preprocessed files do not include comments.

To fix this, you can of course use whatever compiler flag disables this switch case check.

Fixing programmers

Posted Mar 17, 2019 10:49 UTC (Sun) by HelloWorld (guest, #56129) [Link]

gcc also supports using an attribute instead of a comment, that will not be removed by the preprocessor.

Fixing programmers

Posted Mar 17, 2019 12:30 UTC (Sun) by madscientist (subscriber, #16861) [Link]

GCC provides options that allow the preprocessor to leave comments in its output files.

However, using attributes is probably a better way to go in general.

Fixing programmers

Posted Mar 13, 2019 20:27 UTC (Wed) by roc (subscriber, #30627) [Link] (31 responses)

Putting the wrong key in the wrong lock of your flat is immediately detected and has no lasting consequences.

Absent the kind of work described here that you are objecting to, omitting a "break" is not immediately detected and can have lasting consequences up to and including users you don't even know having their systems compromised by hostile forces.

It would be a better analogy if every time you touched a lock with the wrong key you got an electric shock. It would be interesting to see how long you tolerated that situation because "human beings without any qualifications should be able to do this".

Fixing programmers

Posted Mar 13, 2019 20:35 UTC (Wed) by rweikusat2 (subscriber, #117920) [Link] (30 responses)

> Putting the wrong key in the wrong lock of your flat is immediately detected and has no lasting consequences.

That I happened to use an example to illustrate something specific (complicatedness of a procedure) doesn't mean any side properties of said example are relevant to the discussion because they exist (or are believed to exist).

Fixing programmers

Posted Mar 13, 2019 21:12 UTC (Wed) by roc (subscriber, #30627) [Link] (29 responses)

The ease of detecting and correcting failure is relevant because it explains the difference in expectations that you highlighted.

I don't expect people to put the right key in the right lock first try every single time, just like I don't expect C developers to always remember to put "break" after switch cases. But because the consequences of the former are "it didn't work, try again" (i.e. negligible), it *is* reasonable to expect unskilled people to successfully enter their flat. The goal of the changes reported here, which you apparently oppose, is to change the consequences of omitting a "break" to something similar (whereas currently the consequences can be much more severe and fall on other parties).

Fixing programmers

Posted Mar 13, 2019 21:50 UTC (Wed) by rweikusat2 (subscriber, #117920) [Link] (28 responses)

> The ease of detecting and correcting failure is relevant because it explains the difference in expectations that you highlighted.

Just out of curiosity: Have you ever seen a bread slicing machine? Chances are that someone who doesn't get "using that" right every time will end up cutting off a part of his or her fingers. That's a seriously bloody and quite painful experience. Yet, people without a degree in anything are expected to be able to do that.

NB: This is still completely besides the point I was trying to make, it just illustrates that "misues of household devices is harmless !!! but misuse of switch Catastrophical !!1" is an nonsensical assertion despite misuse happend to be harmless for an example I used because it served as illustration for something completely different.

Random story I feel like telling here: A couple of years ago, I read about a guy who was resolved to commit suicide and thus, turned the gas on in his kitchen. After waiting for terminal results for a while, he suddenly changed his mind, turned the gas off again and opened the kitchen window. To celebrate his decision to face this life somewhat more, he then lighted a cigarette. The roof of the house was blown of but he survived with serious burns and was later sentenced for arson.

Fixing programmers

Posted Mar 13, 2019 21:59 UTC (Wed) by Cyberax (✭ supporter ✭, #52523) [Link] (18 responses)

Attitude like yours so far led to several decades of unreliable software that crashes at the first opportunity.

In reality people make mistakes. A lot of time.

A good example here is surgery. A surgeon is a highly trained professional, you need almost a decade of intense training for it. In short, a surgeon is the first candidate for somebody who shouldn't make stupid mistakes.

Yet surgeons forgetting instruments inside patients was a common occurrence before a simple check was added - nurses count surgical instruments before and after the surgery.

Aviation? The same issue. Solved by checklists that HAVE to be followed.

Fixing programmers

Posted Mar 14, 2019 6:35 UTC (Thu) by adobriyan (subscriber, #30858) [Link]

Philosophically, programming is still young profession compared to other professions, often thousands years old.
Programming still have yet to grow up which is (slowly) happening.

Current situation is further complicated by very low barriers to entry.

Fixing programmers

Posted Mar 14, 2019 12:16 UTC (Thu) by jem (subscriber, #24231) [Link]

I have learned that checklists are also being applied in surgery. The first item on the list is to check the patient's name.

Fixing programmers

Posted Mar 14, 2019 16:31 UTC (Thu) by rweikusat2 (subscriber, #117920) [Link] (1 responses)

> Attitude like yours so far led to several decades of unreliable software that crashes at the first opportunity.

Switching the topic of a discussion away from something technical and towards posting speculative, public insults about people who happen to disagree with some opinion is not a strong point in favour of this opinion. Rather the opposite.

Fixing programmers

Posted Mar 14, 2019 17:53 UTC (Thu) by Cyberax (✭ supporter ✭, #52523) [Link]

No. This is not an insult, it's a statement of fact.

A cavalier attitude of ignoring the simplest safety features has led the industry down the never-ending rabbit hole of security bugs.

The art of checklists

Posted Mar 18, 2019 0:58 UTC (Mon) by rickmoen (subscriber, #6943) [Link]

Cyberax wrote:

Aviation? The same issue. Solved by checklists that HAVE to be followed.

Sadly, there have been some painful (and fatal) lessons in effective use of checklists in the airline industry, as also in other industries where they're critical (marine transportation. weapons systems, spaceflight, medical care, etc.) Making a long story short, checklist design and implementation has had subtle aspects that are difficult to get right, and just saying they HAVE to be followed isn't nearly enough.

What happens when airlines get it wrong is what happened to my father, Pan Am Captain Arthur Moen, and his crew. (Upon finally reading the NTSB report, I was obliged to change my saying 'A checklist will have your life' to 'A well-debugged checklist will save your life'.)

Rick Moen
rick@linuxmafia.com

Fixing programmers

Posted Mar 18, 2019 10:18 UTC (Mon) by farnz (subscriber, #17727) [Link] (12 responses)

The thing that really changed both aviation and surgery is not checklists themselves, but three shifts in attitude that result in changes (including checklists) that improve on today's situation.

Change 1 is the idea that unforced human error is not an explanation - it's just a way of shifting blame onto the operator. All incidents have to be investigated, and at each point where a reasonable change to procedure or device implementation could have prevented an incident, that change should be identified. Once you have a list of changes that could have prevented this incident, then you do a risk/benefit assessment of each change and decide which ones are worth having, and which ones just add complexity for complexity's sake.

Change 2 is that there's no such thing as a lucky near miss - instead, there are near misses that . Whenever someone has a "lucky near miss", record what happened, and classify it with other lucky near misses. Someone looks for patterns of lucky near misses, and anything that recurs is treated as an incident and investigated with a view to stopping it happening again.

Finally, change 3 is the idea that seniority should not imply deference. The world's greatest experts all make mistakes, and when a junior calls you out on a possible error, you either fix it and graciously acknowledge their input (if they've called you on a real error like operating on the wrong limb), or you treat it as a teachable moment if they've misunderstood something (e.g. if they're asking you why you put the nose down and cut the throttle when trying to descend).

None of this is a panacea - mistakes still get made - but it means that you don't repeatedly make the same class of error, nor do you depend on "experience" and "expertise" to remove classes of mistake, because the changes you make (be it checklists, talking to the patient before operating, gauges rotated so that "perfect" is straight up, sign in/out sheets for everything that's used in an operation, making it normal for juniors to critique seniors) all change the working environment such that fewer mistakes are made.

In contrast, in software, we had the Morris Worm of 1988 (over 30 years ago), which exploited buffer overflows in C code. 30 years later, we're still seeing new buffer overflow attacks on maintained software written in C; why haven't we changed the way we work so that buffer overflows don't happen?

Fixing programmers

Posted Mar 18, 2019 11:18 UTC (Mon) by pizza (subscriber, #46) [Link] (7 responses)

> In contrast, in software, we had the Morris Worm of 1988 (over 30 years ago), which exploited buffer overflows in C code. 30 years later, we're still seeing new buffer overflow attacks on maintained software written in C; why haven't we changed the way we work so that buffer overflows don't happen?

Because, unlike both Surgery and Aviation, "programming" (C or otherwise) as a profession has little to no formal quality, training or certification requirements, and zero government oversight. Which is just they way the industry likes it.

You want this to change? Make software vendors directly liable (civilly and/or criminally) for software defects -- no more hiding behind "the software is provided with no warranty; not even implied merchantability or fitness for a particular purpose" disclaimers.

Fixing programmers

Posted Mar 18, 2019 11:43 UTC (Mon) by farnz (subscriber, #17727) [Link] (6 responses)

That's not sufficient - maritime transport is regulated in the same way as aviation, and yet is as generally disasterous as programming. In particular, maritime accidents can be blamed on human error and the captain or their crew prosecuted in a way that does not happen in aviation - see the Costa Concordia disaster for example, where no lessons are being learnt by the industry because they can push the blame onto the captain.

Fixing programmers

Posted Mar 18, 2019 12:46 UTC (Mon) by pizza (subscriber, #46) [Link] (5 responses)

I'm not sure that the Costa Concordia is a good example here, as the company was based in Italy, the ship flew an Italian flag, and the accident happened in Italian waters -- it's rare for two to be true, much less the trifecta! -- and its Captain demonstrated astonishing (not to mention criminal) levels of gross incompetence.

That said, the cruise industry as a whole also made changes (notably requiring safety drills prior to leaving port instead of "within 24 hours" as the governing treaties require) and much stricter rules about non-essential personnel on the bridge -- eg if you're going to sneak your mistress on board without a ticket, at least keep her off the bridge during offshore manoeuvres.

I might postulate that the "maritime industry" is learning the lesson that poor safety practices will severely hurt them in the market -- both in lower passenger booking and drastically higher insurance premiums. (Indeed, insurance company requirements probably do more to effect industry-wide changes than governments ever do..)

Fixing programmers

Posted Mar 18, 2019 13:20 UTC (Mon) by farnz (subscriber, #17727) [Link] (4 responses)

The Costa Concordia is a good example, because it had a near-miss doing a similar manoevure at company request under the same captain a few months earlier, but no formal investigation happened - it was just one of those things - and even now, the effort is to claim that the captain was at fault.

In an aviation equivalent, the setup would allow any bridge officer to override the captain on a risky manoevure like this; it simply wouldn't be just the captain's fault as the Concordia was suggested to be.

Plus, there are plenty of design issues with the cruise ships in general, which are being completely ignored in favour of minor tweaks to the way they operate - despite knowing that the requirement for active stability assist to stay upright is part of what caused the Concordia to crash.

Fixing programmers

Posted Mar 18, 2019 15:56 UTC (Mon) by pizza (subscriber, #46) [Link] (3 responses)

> In an aviation equivalent, the setup would allow any bridge officer to override the captain on a risky manoeuvre like this; it simply wouldn't be just the captain's fault as the Concordia was suggested to be.

(FYI, under maritime law, "overriding the captain" is called mutiny, something that tends to go quite badly for all involved..)

Meanwhile, the book wasn't thrown at the captain (and his senior staff) for merely running aground. Instead, it was for grossly mismanaging what happened next. To top it all off, the captain *abandoned his post* well before evacuation was complete.

Fixing programmers

Posted Mar 18, 2019 16:50 UTC (Mon) by farnz (subscriber, #17727) [Link] (2 responses)

Exactly my point - there are two things that matter and are different in aviation as opposed to maritime regulation:

  1. Overriding the captain when they are making a mistake is expected in aviation, and praised; it is punished in maritime regulation.
  2. The questions being asked of the captain are not "what could we have changed to stop this from happening", but "why did you not do the right things".

It's that blame culture that prevents maritime rules from moving on - we have a scapegoat for the incident, we don't need to consider anything other than Captain Schettino's bad behaviour. In the aviation world, there would be more significant changes expected; why does Captain Schettino claim he was asked to do a sail-past salute? Why can't a more junior officer order preparations to abandon ship? Why couldn't Captain De Falco hand command of the ship over to Mr Bosio when Captain Schettino refused to return onboard? Why is it possible for the alarm system to be off on captain's orders alone?

And I'm not a professional investigator - those are just four things raised by the public record on the disaster that should be understood and should lead to changes to the way ships are run, if it's managed the way aviation is. Human error happens, and the rates at which it happens are well understood, so why do we accept that the disaster was Captain Schettino's fault, and leave it at that, when we should be trying to ensure that the next Captain Schettino cannot make the same set of mistakes?

Fixing programmers

Posted Mar 18, 2019 17:20 UTC (Mon) by pizza (subscriber, #46) [Link] (1 responses)

Unfortunately, many of the answers to your questions are "because maritime law."

BTW, here is the 181-page official investigation report:

http://3kbo302xo3lg2i1rj8450xje-wpengine.netdna-ssl.com/w...

Fixing programmers

Posted Mar 18, 2019 19:09 UTC (Mon) by farnz (subscriber, #17727) [Link]

I don't disagree that a lot of the issues are down to maritime law - but that's precisely the sort of thing that needs to be fixed if maritime is to catch up on aviation w.r.t. safety errors. And (to circle back round) both aviation law and maritime law are government regulations on the way their respective industries are run, complete with liability control; however, one has a strong record of ratcheting up safety over time, and the other continues to blame individuals rather than address the many ways in which changes to the law would result in better safety for all.

Hence my belief that regulation, in itself, is not sufficient to improve software - it needs to be good regulation like aviation, where the emphasis is on changing the regulation to prevent repeats, not like maritime law where flag administrators are slow to change regulations in response to known deficiencies.

Fixing programmers

Posted Mar 19, 2019 14:43 UTC (Tue) by NAR (subscriber, #1313) [Link] (3 responses)

"why haven't we changed the way we work so that buffer overflows don't happen? "

According to this study, checks for buffer overflows in C can lead to 0-7% percent performance loss. Checking for integer overflow could lead to 50% slowdown. I guess those who still want to work in C don't want to accept this performance degradation.

Fixing programmers

Posted Mar 19, 2019 19:13 UTC (Tue) by Cyberax (✭ supporter ✭, #52523) [Link] (2 responses)

Integer overflow could easily be prevented in hardware (by causing a hardware trap). It doesn't even need any serious amount of silicon, integer overflow traps existed in lots of pre-x86 hardware.

Unfortunately, C made that useless and so it fell by the wayside.

Fixing programmers

Posted Mar 19, 2019 19:36 UTC (Tue) by mpr22 (subscriber, #60784) [Link] (1 responses)

I ask in all sincerity: which programming languages of vaguely similar vintage to C do any significantly better a job of accommodating integer overflow than C does?

Fixing programmers

Posted Mar 20, 2019 1:18 UTC (Wed) by Cyberax (✭ supporter ✭, #52523) [Link]

The Pascal dialect that I used back in 1995 definitely had it. I'm not sure about the Standard Pascal.

Ada has had integer overflow checking since forever (as you would expect).

Fixing programmers

Posted Mar 13, 2019 22:17 UTC (Wed) by farnz (subscriber, #17727) [Link] (7 responses)

And yet both of those examples (bread slicers and kitchen gas) have been changed over the years to reduce the chances of not using them correctly, and to make sure that it takes continued incorrect operation in the face of a machine trying to stop you before you hurt yourself. Unlike C, you have to actively work to hurt yourself with modern designed appliances.

Modern bread slicers are designed such that you need the guard down over the bread to allow the slicing action to run; you can't have your fingers near the bread, but the guard holds the loaf in place when it's held in place. On high speed slicers, the guard is the trigger mechanism - you put the unsliced loaf in, push the guard down, loaf is sliced and machine pushes on the guard to tell you to release it and move onto the next loaf.

This compares to older slicers, where the blades are exposed, and there's no interlocking mechanism in place to stop you cutting your fingers - you put the loaf in, remove your hand, and push the trigger.

Similarly, with kitchen gas, older appliances would run the gas forever once you turned it on; modern appliances cut the gas the moment you let go of the controls unless the burner is hot, and will cut it if the burner cools off too far (implying flame lost). Further, they will stop the gas flow after a fixed time period if the burner remains cold, to reduce the chance of accidentally holding the control down without lighting the gas, and then blowing yourself up. It's thus very, very hard to actually get enough gas out of an appliance to trigger an explosion, even if you're trying to do it.

Fixing programmers

Posted Mar 14, 2019 2:00 UTC (Thu) by martinfick (subscriber, #4455) [Link] (4 responses)

Unfortunately, I have yet to see a stove that comes with a timeout on every burner and doesn't continue to burn your food, your pot, and potentially your house if you forget to turn it off. Wait, we are expected to turn it off and not walk away! I would welcome such a safety feature if it existed, surely more than the nagging beep of a microwave that has food getting cold in it!

Fixing programmers

Posted Mar 14, 2019 3:14 UTC (Thu) by Cyberax (✭ supporter ✭, #52523) [Link]

You really need electronically actuated valves for this, it's impractical to do with purely mechanical valves. So I guess nobody wants to do this.

Fixing programmers

Posted Mar 14, 2019 9:30 UTC (Thu) by farnz (subscriber, #17727) [Link]

Unfortunately, the mechanical mechanisms used for gas safety are based on the idea that you simply permit the flow of gas to run freely when the burner is warm enough; they just stop gas flow when cold, and use pressure on the control knob to open up the flow. The better ones use pressure on the control knob to start a release timer, after which you need to release the control knob and press it again to resume the flow of gas.

As with all safety mechanisms, they're not that hard to get around if you're determined - the point, however, is that a single mistaken decision on its own is not enough to cause a serious problem.

Fixing programmers

Posted Mar 16, 2019 9:29 UTC (Sat) by HelloWorld (guest, #56129) [Link] (1 responses)

> Unfortunately, I have yet to see a stove that comes with a timeout on every burner and doesn't continue to burn your food, your pot, and potentially your house if you forget to turn it off.
Pots are made of metal and hence won't burn, and if the food burns, there will be smoke which will trigger the smoke detector, which is mandatory where I live.

Fixing programmers

Posted Mar 16, 2019 10:30 UTC (Sat) by roc (subscriber, #30627) [Link]

Many pots these days have coatings that burn off, ruining the pot, if it overheats.

Fixing programmers

Posted Mar 14, 2019 15:31 UTC (Thu) by nilsmeyer (guest, #122604) [Link] (1 responses)

And even after all that it's going to be the carbs that do you in in the long run.

Fixing programmers

Posted Mar 16, 2019 23:58 UTC (Sat) by Wol (subscriber, #4433) [Link]

What's wrong with the carbs? Or have you been drinking the diet kool-aid?

SUGAR can be very bad for you. But one of the biggest problems with carbs is the modern tendency to snack, leading to elevated blood sugar over a long period of time. Our body is designed for sugar levels to sawtooth - high after a meal and then low between meals. Snacking means it never gets a chance to drop, and that does a HELL of a lot of damage.

Cheers,
Wol

Fixing programmers

Posted Mar 13, 2019 22:25 UTC (Wed) by roc (subscriber, #30627) [Link]

A moment's searching shows that bread slicing machines routinely come with protective guards, which are legally required in some countries.

Personally I'd support people being free to chop off their own body parts if they insist on using unsafe equipment or unsafe programming languages, except that some of the costs inevitably fall on the community at large. For amputations, it's health care costs. For software, it's a combination of things: a software ecosystem polluted with vulnerable software, and a network ecosystem polluted with compromised devices.

The gas story is a good one.

Fixing programmers

Posted Mar 14, 2019 9:48 UTC (Thu) by dvdeug (guest, #10998) [Link]

Would you accept a new car that has some 90,000 parts and only 20 of them are going to fail in practice? The various Un*x kernels are basically the only remaining large-scale C programs that are examples of how large-scale C programming can actually work; shrugging off 20 bugs are hardly an argument for C as a reasonable implementation language.

There's been other problems like this; Fortran require you to declare variables, so when programmers misspelled variable names, the compiler wouldn't warn the programmer. So those still using Fortran have the option of using "IMPLICIT NONE", not too dissimilar to C programmers having an option to have the compiler complain when they don't use a break or a note comment.

Fixing programmers

Posted Mar 14, 2019 13:45 UTC (Thu) by dottedmag (subscriber, #18590) [Link] (1 responses)

Could you share a list of software you authored or contribute to?

Fixing programmers

Posted Mar 14, 2019 16:34 UTC (Thu) by rweikusat2 (subscriber, #117920) [Link]

Could you stop talking about me?

In theory, we're past the point were "Charge and beat 'em!" was an acceptable discussion tactic.

Fixing programmers

Posted Mar 14, 2019 15:27 UTC (Thu) by HelloWorld (guest, #56129) [Link]

> The C switch statements has certain properties. One could argue whether all of these properties are really desirable, but that's not going to change it.
Actually it does. "C with magic comment for fall-through" is a different (albeit similar) language than C, because the compiler actually enforces the comment. And empirically people are less likely to make the fall-through mistake in that language than they are in C.

Fixing programmers

Posted Mar 14, 2019 21:59 UTC (Thu) by NAR (subscriber, #1313) [Link]

Take a look at this road crossing. The 2011 October state shows something like the "C switch statement". It's clearly defined in the highway code that the cyclists coming from the north ("behind") have priority, the cars should give way to them. Yet many cyclists were hit in this very road crossing - apparently the drivers "just can't learn" and apply the highway code. So the road crossing was updated. The highway code was not changed (the semantics of the C switch statement did not change), the cars still need to yield to the cyclists. It's the radius of the curve that was changed, so the drivers have to break more, otherwise they can't turn in, and at a slower speed they have more time, more chance to notice the cyclist (the path of the cyclist was also changed, now there's no 250 m straight line before the crossing, only 20 m, so they don't arrive to the crossing at 30 km/h speed). Effectively a "look around carefully" comment was introduced to this "C switch statement".

Accidentally leaving out a break statement in the Linux kernel might not lead to actual accidents (but who knows, Linux is running on cars nowadays), but it's still better to make it safer for those who "just can't learn", just like it's better to make that road crossing safer.

Fixing programmers

Posted Mar 15, 2019 1:47 UTC (Fri) by jschrod (subscriber, #1646) [Link] (2 responses)

Ah, the "programming C is only for the math elite argument". Splendid.

As an old Unix grey beard (well, not quite literally, by now my beard is white), I'll have to say that demanding that all kernel programmers are "proficient in math" and "have to learn C" is not sufficient. Some decades ago, I was able to read binary OS/370 code, and did so everyday, not needing disassemblers. Nowadays, not so much any more; but that it is clearly the reason why I'm too old to be a kernel developer. But, since I still remember this time at the start of the 80s, it's not too far away, these kids today should get off the lawn. Obviously, this kind of my then-proficiency should be the standard for all current kernel developers -- they should stop writing that kind of code in C (a.k.a. abstract assembler of PDP-11 hardware) and should start using better abstract assembler for current hardware system abstractions. Since they are these geniuses, this should be no problem at all; if there is no such system, they can invent it. The Unix guys worked shoulder-to-shoulder with the C guys, and did it too, don't they. Insistence on C is so 70s, bring on new assemblers!

IOW: An argument that one should "fix programmers" is as silly as my paragraph above.

FTR: I've known Dennis Ritchie personally, and I'm proud that he took the time sharing several evenings with me. He was the first person who would have called these arguments "you have to learn C properly" not appropriate, since he knew the deficiency of his own creation quite well.

Fixing programmers

Posted Mar 15, 2019 13:19 UTC (Fri) by anselm (subscriber, #2796) [Link] (1 responses)

The Unix guys worked shoulder-to-shoulder with the C guys

Not just that. The Unix guys basically were the C guys.

I wonder what all the fuss is about. The C language has its problems but as far as I'm concerned break is not one of the bigger ones. It's more of an idiosyncrasy. To my mind, requiring explicit break statements lets you do useful¹ things that would be impossible if there was an implicit break in front of every case (think Duff's Device), and that, together with the fact that this style of switch is fairly straightforward and minimal to implement in a C compiler based on other stuff you already have, may have been enticing to the designers of the language.

Chances are that if you were designing the C programming language from scratch today you would do various things differently, probably including switch statements. But for better or worse, we're stuck with C – at least the C switch statement – as it has been for almost 50 years, so we must remember to put a break in all the appropriate places. If we can get the compiler to remind us to do that if we forgot, or else to tell it explicitly that we didn't want one, that can only be a good thing – ace programmers of rweikusat2's calibre will of course always do the Right Thing™ from the get-go and should therefore not ever be annoyed by superfluous compiler warnings, but people like you and I (and incidentally like jschrod's, my beard is also fairly white by now) may appreciate an occasional heads-up.

¹ Useful, that is, if you think of C as a high-level portable assembly language.

Fixing programmers

Posted Mar 15, 2019 18:51 UTC (Fri) by rgmoore (✭ supporter ✭, #75) [Link]

To my mind, requiring explicit break statements lets you do useful¹ things that would be impossible if there was an implicit break in front of every case

You could fix that by allowing an explicit fallthrough when that's what you want. Unfortunately, as you say it's too late to change the syntax now, so the best we can do is use the compiler to catch cases where the break is left out accidentally.

Fixing programmers

Posted Mar 14, 2019 15:42 UTC (Thu) by Wol (subscriber, #4433) [Link] (6 responses)

> Fixing the people has never been a workable solution to this kind of security issue; why would you expect this case to be different?

It's not about fixing the people - they've already been fixed. When observing people carrying out a task, if they keep doing the same thing wrong, ask yourself why.

It's a pretty safe bet they're doing EXACTLY what they've been trained to do. It's just that the task they're doing is unusual, and their training is making them do the wrong thing.

Case in point - who was the idiot that decided that in Windows "tab" should step between fields, and "return" should send the completed form back to the program. It took a MAHOUSIVE training effort to fix that programming blunder, and people STILL get it wrong on a regular basis.

If people can't do it right, IT'S BECAUSE THEY'VE BEEN TRAINED TO DO IT WRONG, and you've got to *find* that training and fix it - which may not be possible.

(Another case in point - these latest 737 MAX crashes - the plane avionics have changed, and it seems pilots haven't been told that 20 or 30 years of training will make them instinctively do the wrong thing in a crisis ... - TRUE STORY!)

Cheers,
Wol

Fixing programmers

Posted Mar 15, 2019 7:45 UTC (Fri) by jem (subscriber, #24231) [Link] (4 responses)

> Case in point - who was the idiot that decided that in Windows "tab" should step between fields, and "return" should send the completed form back to the program. It took a MAHOUSIVE training effort to fix that programming blunder, and people STILL get it wrong on a regular basis.

That convention is older than Windows, possibly older than the Apple Mac GUI. The real idiot was the one who later decided to implement this functionality differently on marginal platforms like Acorn's RISC OS.

Fixing programmers

Posted Mar 15, 2019 9:24 UTC (Fri) by halla (subscriber, #14185) [Link]

I think it's older than guis. Wasn't this already the default in things like db2 on the Apple 2? Or am I backprojecting... I cannot remember anything else than tab, shift-tab for moving between fields, enter for submitting and esc for cancelling.

Fixing programmers

Posted Mar 17, 2019 0:04 UTC (Sun) by Wol (subscriber, #4433) [Link] (1 responses)

Well, the convention that "return" should terminate the current FIELD and move to the next one was the norm for me when I started programming at the start of the 80s, so that goes back a long long way too - earlier than MS-DOS I think ...

(I was programming using text terminals on a mini ...)

Cheers,
Wol

Fixing programmers

Posted Mar 25, 2019 15:45 UTC (Mon) by Wol (subscriber, #4433) [Link]

I know it's well past, but I'll add that this convention long predates modern computers.

It was the convention on old green screen terminals. It was the convention on teletypes before that. Heck, it's the convention that first came about two centuries ago with the early typewriters!

Just changing the convection won't fix two centuries of training to do the opposite - since when did hitting "return" change the paper for you?

Cheers,
Wol

Fixing programmers

Posted Mar 17, 2019 9:11 UTC (Sun) by farnz (subscriber, #17727) [Link]

It was formalised in IBM's CUA guidelines in 1987, which was adopted by Motif. I can't find references for where IBM took that behaviour from, but the fact it was adopted as part of CUA suggests it was in use before 1987.

Fixing programmers

Posted Mar 16, 2019 17:20 UTC (Sat) by jezuch (subscriber, #52988) [Link]

Well, I more or less agree, and the fact that the syntax and semantics of the switch statement is massively inconsistent with the rest of the language doesn't help at all. So you could say that people are trained to use the C syntax for all statements - except this one which has completely different rules. But it is used rarely enough that peple reflexively try to apply the mental model of the rest of the language to this one statement as well.

I know I do. I still have to basically relearn switch every time I encounter it. And it took me a lot of time and much mental effort to get it the first time. It's just so freakin' odd.

Anyway, fixing people in face of obviously broken tools (instead of fixing the tools) is never the right answer. It's elitist, condescending, and thinking about it, it could also have a component of Stockholm syndrome.

Cook: security things in Linux v5.0

Posted Mar 14, 2019 18:49 UTC (Thu) by tdz (subscriber, #58733) [Link]

Time for coloring some bike sheds!

I don't see anything wrong with this. Of all the changes from the linked article, this is the least controversial. This has no runtime/compile overhead or any form of weird semantics. It doesn't obfuscate the code base. This change has zero negative impact. If anything, I'd ask for using the related gcc attribute instead of a comment.

Cook: security things in Linux v5.0

Posted Mar 15, 2019 11:24 UTC (Fri) by jani (subscriber, #74547) [Link] (1 responses)

> the language is not that complicated, mind you

I find that more than a little condescending.

Even so, it's not about complexity of the language per se. It's about the complexity of using the language in a way to avoid common mistakes. The problem is in the language, not the people.

> inventing one bazillion /*** OMFG !! Not like Pascal !!! ***/ pseudosyntactic tags?

Granted, I would have preferred __attribute__ ((fallthrough)) with some syntactic sugar macro. But this is one. What are the other (bazillion - 1)? Or even your top three pet peeves?

submitted

Posted Mar 16, 2019 5:16 UTC (Sat) by scientes (guest, #83068) [Link]

> Granted, I would have preferred __attribute__ ((fallthrough)) with some syntactic sugar macro.

https://lkml.org/lkml/2019/3/15/792

Because it is needed by distcc.


Copyright © 2019, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds