Re:Google, Xiaomi, and Huawei affected by zero-day flaw that...
by wildmusings on Saturday October 05, 2019 @10:19PM
(#21169402)
You’re wrong that no one should ever use goto. Goto is a perfectly fine control flow operator IF AND WHEN you use it in a highly structured, well-understood way. This is how systems programming is done. A “goto cleanup” section at the end of a function is the best way to do exit-on-error in C, hands down.
I hate that people keep peddling this nonsense because they wrote a little C and read a headline about “goto considered harmful”, which is a gross oversimplification and a BAD piece of “wisdom” that for some reason won’t die. This is how serious handling in C is done. Please stop repeating this tired trope.
Re:Google, Xiaomi, and Huawei affected by zero-day flaw that...
by jumpingmice on Sunday October 06, 2019 @12:00PM
(#21172806)
Goto is only de rigueur in terrible languages that are unable to release function-local resources automatically. It is an intentional choice by kernel authors to ignore all progress in our field after 1988 and insist on writing everything in C. It’s not the goto statements that are the problem, rather it is the culture that necessitates them.
Re:Google, Xiaomi, and Huawei affected by zero-day flaw that...
by neop1x on Monday October 07, 2019 @05:24AM
(#21178880)
Do you realize how big the kernel source is? No one wants to rewrite it to C++. Also C++ compiles slower and can be more difficult to read, depending on code style and features used. C++ is also far more fragile regarding compiler compatibility and sometimes spits rather confusing error descriptions.
Re:Google, Xiaomi, and Huawei affected by zero-day flaw that...
by xeromal on Sunday October 06, 2019 @03:31AM
(#21170426)
I'm sure some of the people parroting that got it from their professors in college. I know mine sure did.
Re:Google, Xiaomi, and Huawei affected by zero-day flaw that...
by dleslie on Saturday October 05, 2019 @08:48PM
(#21169018)
Care to name and shame with supporting evidence?
Re:Google, Xiaomi, and Huawei affected by zero-day flaw that...
by Hello71 on Saturday October 05, 2019 @09:05PM
(#21169102)
it's fairly well known that small kmallocs do not fail, and that there are many, many instances in the filesystem code which assume that small kmallocs do not fail. there have been two LWN articles on this exact subject.
Re:Google, Xiaomi, and Huawei affected by zero-day flaw that...
by girvo on Saturday October 05, 2019 @09:14PM
(#21169147)
And goto being used for error handling is pretty stock standard across most C codebases I’ve worked on or seen over the years, so I’m not sure what the particular gripe is there
Re:Google, Xiaomi, and Huawei affected by zero-day flaw that...
by telanis on Saturday October 05, 2019 @09:26PM
(#21169205)
Since when is "we do it all the time" the same as "it's a good thing"?
Re:Google, Xiaomi, and Huawei affected by zero-day flaw that...
by nothrabannosir on Saturday October 05, 2019 @10:20PM
(#21169404)
goto for error handling is not just "freeform anything goes goto". It's a very specific idiom, being an "error" label and a bunch of "if (resource) free(resource)" statements at the end of the function. It is essentially analogous to a common use case of Go's defer. Typically an accepted pattern when dealing with many resources and possible exit points. Prevalent in I/O heavy code.
Different ballgame from the subject of Dijkstra's manifesto.
Re:Google, Xiaomi, and Huawei affected by zero-day flaw that...
by josteink on Sunday October 06, 2019 @05:25AM
(#21170841)
> It is essentially analogous to a common use case of Go
Go, which is also known for its terrible error-handling.
Great.
Re:Google, Xiaomi, and Huawei affected by zero-day flaw that...
by neop1x on Monday October 07, 2019 @05:26AM
(#21178895)
Really? I have never seen a Go program to misbehave while not printing some meaningful output. It is possible but almost no one ignores the error parameter. Yet I have seen many, many Java and Python software which quit after the first Unhandled Exception. So often that I consider exceptions as the bad error handling mechanism.
Re:Google, Xiaomi, and Huawei affected by zero-day flaw that...
by cjbprime on Saturday October 05, 2019 @11:39PM
(#21169682)
It's both common and a good idea, when used purely internally to a function in order to redirect error paths to a standard set of cleanup code. It helps prevents memory errors and other problems.
This is the sense in which the Linux kernel uses goto.
Re:Google, Xiaomi, and Huawei affected by zero-day flaw that...
by tmd83 on Saturday October 05, 2019 @11:45PM
(#21169701)
I'm not experienced in C or kernel code but from my understanding they use it almost entirely like a catch/finally clause of many higher level language which is a widely accepted and successful pattern.
Re:Google, Xiaomi, and Huawei affected by zero-day flaw that...
by kevin_thibedeau on Saturday October 05, 2019 @10:59PM
(#21169534)
Properly used goto is essentially an inline exception handler. That is a good thing to eliminate repetitive fault checks and fragile cleanup code.
Re:Google, Xiaomi, and Huawei affected by zero-day flaw that...
by __s on Saturday October 05, 2019 @09:47PM
(#21169294)
Since when are standard practices the same as "it's a good thing"?
Well written code is the best code. Some well written code uses goto. Some not well written code doesn't use goto
Re:Google, Xiaomi, and Huawei affected by zero-day flaw that...
by jumpingmice on Saturday October 05, 2019 @09:23PM
(#21169196)
Yeah that’s the rumor but allocations of any size can fail when kmem cgroup accounting is enabled and the container is out of space.
Re:Google, Xiaomi, and Huawei affected by zero-day flaw that...
by jnurmine on Sunday October 06, 2019 @09:32AM
(#21171905)
Well, if the allocation is done with GFP_ACCOUNT bit set, i.e. kmemcg accounting enabled, isn't that the intended behaviour that the allocation can fail?
Re:Google, Xiaomi, and Huawei affected by zero-day flaw that...
by jumpingmice on Sunday October 06, 2019 @12:13PM
(#21172891)
Yes that is the point. In the relatively rare case of failure this particular function uses a goto to return without releasing a held mutex. Error paths within the kernel are a rich vein of malfunction.
Re:Google, Xiaomi, and Huawei affected by zero-day flaw that...
by carapace on Sunday October 06, 2019 @04:58PM
(#21175079)
"We should look at the whole project as a cautionary tale of the kind of leveraged destruction that some programmers of modest ability but extreme confidence can wreak on our industry."
Oh man, can I put that on a t-shirt?
It's bad enough that syzbot finds fifty serious bugs per hour, but I'll relay a personal anecdote. Earlier this year I wagered a colleague that I could open up the source of the 4.10 kernel (the one that was once current in Ubuntu 16) and find an obvious defect in less than an hour. It actually only took me about 15 minutes, to find a deadlock in the squashfs that was triggered by kmalloc failure and an error path via goto, which of course nobody should ever use. And while I'm reading it I'm just thinking to myself that this is the worst program I've ever seen and it would never pass a code review at my workplace, but it's out there right now running on billions of computers.