News for hackers. Stuff that matters.
Re:Critical Bluetooth vulnerability in Android by userbinator on Friday February 07, 2020 @08:25AM (#22265695)
It's an 8-bit counter... just allocate a fixed 256 entries and be done with it. That reads like code written by people without any embedded/low-level experience.

Keeping code simple and without unnecessary abstraction is a far more valuable skill than $safe-language-trend-of-the-day.

Re:Critical Bluetooth vulnerability in Android by atoav on Friday February 07, 2020 @09:13AM (#22266064)
As someone who both writes C and Rust I don't think the two contradict each other. Rust is very nice to write stable, fast and well tested libraries in that can interface with C code in.

Learning Rust and with its concepts improved my C code. Even if Rust would vanish over night I wouldn't regret learning it.

Re:Critical Bluetooth vulnerability in Android by reyqn on Friday February 07, 2020 @09:09AM (#22266038)
It's a valuable skill for sure, but there apparently isn't enough people with this skill on the market, which is why $safe-language-trend-of-the-day is being developed and gains momentum.
Re:Critical Bluetooth vulnerability in Android by zamalek on Friday February 07, 2020 @10:49AM (#22267088)
> there apparently isn't enough people with this skill on the market

Judging by the number of memory vulnerabilities found each year in mainstream operating systems (which are developed by some of the best programmers around), there aren't any people on the market with this skill. This is very likely because all programmers are human beings.

Manually managing memory isn't difficult, it has been proven to be practically impossible. I wouldn't care if it were Linus claiming otherwise, it's ignoring incredible amounts of evidence to the contrary and is much like flat-earther.

Re:Critical Bluetooth vulnerability in Android by bluejekyll on Friday February 07, 2020 @09:46AM (#22266411)
How long must a language be around and prove it’s staying power before people will stop brushing it aside with the “$safe-language-trend-of-the-day“ quip? 1 year? 2 years? 5 years? 50?

How many people must use it? 1k? 10k? 100k?

It’s pointless to argue with someone who throws Rust into that category at this point because it means nothing. It’s a slight to allow them to feel ok, that eventually this language too will pass, and so it will be ignored.

Re:Critical Bluetooth vulnerability in Android by bitwize on Friday February 07, 2020 @10:36AM (#22266941)
People who know how to do that are expensive, and they still make mistakes. Rust enables junior-level JavaScript programmers to write kernel/bare-metal level code without fear of making these kinds of errors. If you've spent a career programming in C and you're complaining about Rust, you're right. Rust isn't for you, it's for your replacement.
Re:Critical Bluetooth vulnerability in Android by blub on Friday February 07, 2020 @10:49AM (#22267096)
"Rust enables junior-level JavaScript programmers to write kernel/bare-metal level code without fear of making these kinds of errors. If you've spent a career programming in C and you're complaining about Rust, you're right. Rust isn't for you, it's for your replacement."

That's a pretty silly thing to say.

Writing code that doesn't crash isn't the hardest thing about writing low-level code. Sure, it's a problem, even an important problem, but there's a ton of other knowledge that no JS developer would have. Unless by "write" you mean write 2 lines per day with lots of searching in-between that has to be thrown away in the end.

Re:Critical Bluetooth vulnerability in Android by dpc_pw on Friday February 07, 2020 @01:47PM (#22269251)
The way I see it it: With C/C++, you have to to have a team of 5 senior devs, and they have to cross-check each other work all the time. With Rust, you could have 1 senior Rust dev, and 4 junior devs, and they would arrive in a better place anyway, just by the virtue of compiler doing 90% of the boring checks and tutoring.
Re:Critical Bluetooth vulnerability in Android by blub on Friday February 07, 2020 @02:26PM (#22269758)
You can't build a quality project only with juniors supervised by a senior no matter what technology you use. This is such a common programming fallacy, it's surprising to see it here.
Re:Critical Bluetooth vulnerability in Android by miohtama on Friday February 07, 2020 @04:27PM (#22271135)
But at least with Rust it won't have out of bounds and use after free bugs even if being crap otherwise.
Re:Critical Bluetooth vulnerability in Android by AnthonyMouse on Friday February 07, 2020 @11:16AM (#22267430)
> People who know how to do that are expensive

Good programmers are expensive. The notion that better tools are going to change that is naive.

Rust is good. Use it for things. But the idea that it can let people who don't know what they're doing write secure code is dangerous. For example, what does Rust do about Spectre? Does your junior-level JavaScript programmer know how to address that? What about other timing attacks, or knowing which crypto to use in which context?

People still have to know what they're doing.

Re:Critical Bluetooth vulnerability in Android by leshow on Friday February 07, 2020 @12:24PM (#22268344)
> Rust enables junior-level JavaScript programmers to write kernel/bare-metal level code without fear of making these kinds of errors

I've used Rust for a while, and this isn't really true. At the lowest level you still have to build good abstractions with judicious use of `unsafe`. It also comes across as incredibly hostile, you're not doing Rust any favors with this.

Re:Critical Bluetooth vulnerability in Android by rafaelvasco on Friday February 07, 2020 @01:33PM (#22269107)
"Junior-level JavaScript programmers" "kernel/bare-metal level code"

Can't see how that can be. Only a small minority of programmers can code low level systems. Only those that truly enjoy it, go through the pains necessary to have adequate grasp of it.

Re:Critical Bluetooth vulnerability in Android by WrtCdEvrydy on Saturday February 08, 2020 @04:25AM (#22274898)
> If you've spent a career programming in C and you're complaining about Rust, you're right. Rust isn't for you, it's for your replacement.

LOL, I wish. I've been told I was going to be replaced every 5 years for the last 20 years of my career. I fucking wish they did so I could finally retire but I keep being given money and cool problems so I stay waiting for this fangled replacement who will come and take my job.

Re:Critical Bluetooth vulnerability in Android by 0xdead on Friday February 07, 2020 @12:45PM (#22268575)
If by "write kernel/bare-metal level code" you mean blinking an LED, sure. Writing low level doesn't have to do anything with C or any language for that matter. It requires a deep understanding of the architecture that you're writing code for. Junior JS devs don't have enough experience or the skills to do that.
Re:Critical Bluetooth vulnerability in Android by e12e on Friday February 07, 2020 @02:02PM (#22269469)
I appreciate this comment, because it demonstrates a solid approach to simplify the code.

That said, regarding:

> safe-language-trend-of-the-day.

I agree that rust advocacy can sometimes be a bit misguided and over-enthusiastic - however how often is an out of bounds write not a bug (or a too clever by far hack)?

We've had pretty efficient ways to deal with this in c like languages for a long time (eg Pascal, Ada).

(c-like in the sense of being relatively low-overhead, close to the hardware wrt memory layout etc).

Re:Critical Bluetooth vulnerability in Android by est31 on Friday February 07, 2020 @12:08PM (#22268135)
> It's an 8-bit counter... just allocate a fixed 256 entries and be done with it. That reads like code written by people without any embedded/low-level experience.

I guess you are talking about the first commit I linked. The problem here seems to be that some events of the kind HCI_READ_RMT_EXT_FEATURES_COMP_EVT can be shorter than the assumed 13 bytes. The code contains no check for that and if the events are shorter, it would read data from after the allocation. It would use that data to index inside arrays, etc.

Now, if you just allocate a buffer of 256 entries but don't do anything else, it wouldn't read data from outside the allocation, yes, but it would still read uninitialized data, as nothing would be written after the end of the valid data. That uninitialized data could e.g. come from previous freed allocations. This would hardly be an improvement. You'd have to allocate and zero-initialize it, and then you'd still have the problem whether zero is invalid data or part of the allocation... Even if code would figure that out, it would be extremely smelly code and I'd never merge it in any projects I maintain.

The approach done by the patch to just check the length is much much better. The length is sent as part of the event.

> Keeping code simple and without unnecessary abstraction is a far more valuable skill than $safe-language-trend-of-the-day.

This code almost directly maps to the bluetooth host controller interface which is part of the published Bluetooth standard. So you can't change the core concepts of it. There are a few abstraction layers which copy the data for some reason from a new/delete managed hidl_vec to a malloc/free managed array (check hciEventReceived function in hci/src/hci_layer_android.cc). Yes, I'd say that some of those layers are indeed unnecessary. But those abstraction layers are not where the vulnerability occurs. It occurs in the code that parses the message, and the bug is that the code does not check the length of the input data. This is a classic bug that can occur in C/C++ codebases.

Safe Rust prevents OOB writes/reads by performing bounds checks when you index into a slice.

The issue with languages like C is that verifying that code is safe is extremely hard, even harder than writing it in the first place. This codebase seems to have not been written by Google but by Broadcom, so Google would have to verify whether what Broadcom wrote is actually safe. With Rust, such verification is easy. If your code makes little use of unsafe, and most code doesn't actually have to, it's easy to verify its safety (at least for the classes of bugs that Rust eliminates). Due to the strong typing, other types of bugs are made harder to write as well.