|
|
Log in / Subscribe / Register

Meltdown and Spectre mitigations — a February update

Meltdown and Spectre mitigations — a February update

Posted Feb 6, 2018 1:03 UTC (Tue) by karkhaz (subscriber, #99844)
Parent article: Meltdown and Spectre mitigations — a February update

Two things about static analysis to detect where Variant 1 mitigations need to be applied.

1. It seems to me that the Clang Static Analyzer would be an excellent tool to do this, if only it could parse the kernel. There has been excellent work on compiling the kernel with Clang/LLVM (as described in a talk at the last LLVM Developers' Meeting [1] and here on LWN [2]), but I'm not aware of efforts to do analysis on the kernel (would love to hear if anybody is working on this!).

In particular, the Clang Static Analyzer preserves the AST of the language, whereas many comparably powerful tools first convert the program into some lower-level intermediate representation. The IR is usually better for implementing proper static analyses, but for ``pattern-matching'' cases like this one, you really do want the original AST.

I'm not sure if GCC has softened their position on allowing the AST to be exported to help static analysis tools, text editor autocompletion, and other use cases; but if they have not, then here is one more argument that they really should. We're compiling the kernel with GCC, and it would be really excellent to dump the kernel's AST for cases like this.

2. I contribute to a static analyzer which does convert program code into IR. However, the particular use case in the article does seem to be fairly easy to recover from IR. Is it really just: "flag the locations where the access of an array is guarded by a bounds check for that access"? I would be interested in exactly what pattern is needed (the article does not elaborate), and what trouble Coverity has had (Coverity isn't very good, but this seems quite simple, so I wonder about the nature of the false positives they're reporting and whether I could do any better). Does anybody have pointers to discussion about this or other relevant information?

[1] https://www.youtube.com/watch?v=6l4DtR5exwo
[2] https://lwn.net/Articles/734071/


to post comments

Meltdown and Spectre mitigations — a February update

Posted Feb 6, 2018 15:30 UTC (Tue) by Koral (guest, #115236) [Link]

I think it would be really possible to create a gcc plugin that is doing some pattern matching on the AST and raising a warning in case of spectre var 1.

Meltdown and Spectre mitigations — a February update

Posted Feb 6, 2018 18:57 UTC (Tue) by amaranth (subscriber, #57456) [Link]

It's not just "flag the locations where the access of an array is guarded by a bounds check for that access", that would have an insanely high false positive rate. What is needed is to track inputs to the kernel and find places where they are used (however indirectly) to index an array. If those places have bounds checks they need the Spectre v1 mitigation applied.

Meltdown and Spectre mitigations — a February update

Posted Feb 9, 2018 9:19 UTC (Fri) by jezuch (subscriber, #52988) [Link]

If it was just that then you wouldn't need powerful static analysis, Coccinelle would be enough.

Meltdown and Spectre mitigations — a February update

Posted Feb 16, 2018 11:53 UTC (Fri) by oldtomas (guest, #72579) [Link]

> I'm not sure if GCC has softened their position on allowing the AST to be exported [...]

It has, since a while ago (version 4.5, somewhere 2011):
https://old.lwn.net/Articles/457543/

People are using that for static analysis:
https://old.lwn.net/Articles/370717/

Grsecurity is actually using that in the Linux kernel context:
https://old.lwn.net/Articles/691102/

And for those who want to play comfortably, there's a kind of "meta-plugin" which you can program in some kind of Lisp (and which ironically is named MELT):
http://gcc-melt.org/


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