Security Lessons From a New Programming Language


A security professional needed a secure language for IoT development. So he wrote his own, applying learned lessons about memory and resources in the process.

When a security researcher needs to create an application, there are many choices in terms of programming languages and frameworks. But when project requirements include SSL and an embedded Internet of Things (IoT) platform, the number of good options becomes limited. That’s why Thomas Pornin decided to build his own language.

Pornin, who is technical director and member of the cryptography services practice at NCC Group, has been thinking about programming languages, their strengths, and their weaknesses for more than 30 years. He has worked on many different, complex tech deployments and has the experience of launching an open source project, BearSSL, an SSL stack that is smaller than most SSL implementations available to developers.

The language Pornin wanted to build had two significant requirements: First, its resulting applications had to fit onto a resource-constrained IoT device, and that those applications performed reasonably well. Next, the applications developed using the language would not be subject to certain built-in vulnerabilities seen in some applications. Those vulnerabilities tend to revolve around the way the processor allocates and uses memory, so Pornin focused on memory in his thinking about language security.

Getting the project started took time. “I took care to write a big specification, a 65-page document,” Pornin says. “In it, I explained how it should work and why it should work that way.”

From Spec to Language
The initial specification was the basis for T0, Pornin’s first pass at the programming language. T0 was designed to create applications that would work on an embedded system — defined as one with severely limited memory resources, a CPU that’s not very powerful, no memory management unit, and no operating system to mediate the application’s interaction with the hardware.

Pornin decided to base the design of his secure IoT language on Forth — a programming language that is oriented around the idea of stacks (memory structures where the last item pushed in is the first thing pulled out). He says the decision was partially driven by practical considerations about the discipline that stacks impose on the way memory is used, and partially by aesthetics. The stack orientation means that Forth code uses a distinctive notation (Reverse Polish Notation) familiar to anyone who used an HP calculator without the “=” key.

T0 was able to create compact, operational code. Pornin simplified the job of writing the T0 compiler by having it produce C source code as its output — code that then had to be recompiled and linked into the final executable code using an existing C compiler. It was much of what he wanted, but it was not yet secure. That waited for T1.

The Next Step
In T1, which Pornin described in a presentation at NorthSec 2019, protection for memory and restrictions on stacks were introduced. While Pornin is still working on building out the details of T1 and creating the full compiler for the language, he believes the language is moving in his desired direction.

There are already a number of languages that can be used for embedded applications. Depending on the hardware in use, C, Java ME, Go, Rust Embedded, and Forth may be possibilities. So does Pornin think other security practitioners should write their own programming languages?

“I think that anybody who is really serious about development should have the idea somewhere in their head,” he says. “They should think about what they would like to see in a programming language.” He adds with a laugh, “And it would also be good for people at large if most would stop before actually doing it.”

It is useful, though, for developers and security practitioners to understand how the compilers work and the sort of code they produce. Understanding whether they create code that makes the most of memory protection and memory structures available in the hardware can help them write more secure, more robust applications.

Related Content:

 

Black Hat USA returns to Las Vegas with hands-on technical Trainings, cutting-edge Briefings, Arsenal open-source tool demonstrations, top-tier security solutions, and service providers in the Business Hall. Click for information on the conference and to register.

 

 

Curtis Franklin Jr. is Senior Editor at Dark Reading. In this role he focuses on product and technology coverage for the publication. In addition he works on audio and video programming for Dark Reading and contributes to activities at Interop ITX, Black Hat, INsecurity, and … View Full Bio

More Insights


Read More…

Leave a Reply

Your email address will not be published. Required fields are marked *