SlideShare uma empresa Scribd logo
1 de 15
Bug Finding using Coccinelle

     Julia Lawall (Inria/LIP6)

            Joint work with
 Gilles Muller, René Rydhof Hansen,
    Nicolas Palix, Arie Middelkoop



        September 21, 2012




                 1
Bugs: They’re everywhere!




                            2
Our focus


  Bugs in the Linux kernel
     Linux is critical software.
         – Used in embedded systems, desktops, servers, etc.

      Linux is very large.
         – Almost 18 000 .c files
         – Over 10.5 million lines of code
         – Increase of 8% since July 2011 (Linux 3.0).

      Linux has both more and less experienced developers.
         – Maintainers, contributers, developers of proprietary drivers




                                    3
Bug: !x&y


  Author: Al Viro <viro@ZenIV.linux.org.uk>

      wmi: (!x & y) strikes again

  diff --git a/drivers/acpi/wmi.c b/drivers/acpi/wmi.c
  @@ -247,7 +247,7 @@
    block = &wblock->gblock;
    handle = wblock->handle;

  - if (!block->flags & ACPI_WMI_METHOD)
  + if (!(block->flags & ACPI_WMI_METHOD))
      return AE_BAD_DATA;

    if (block->instance_count < instance)
Bug: dereference of a possibly NULL value

  Author: Mariusz Kozlowski <m.kozlowski@tuxland.pl>

      tun/tap: Fix crashes if open() /dev/net/tun and
      then poll() it.

  diff --git a/drivers/net/tun.c b/drivers/net/tun.c
  @@ -486,12 +486,14 @@
  - struct sock *sk = tun->sk;
  + struct sock *sk;
    unsigned int mask = 0;

    if (!tun)
      return POLLERR;

  + sk = tun->sk;



                           5
Isolated problems, but these bug types can occur many times




                                                                                                      0
                                                                                                xt .3
                                                                                                          bug present



                                                                                             ne -2.6 9
                                                                                                          file absent



                                                                                                ux .2
                                                                                             lin -2.6 8
                                                                                                ux .2
                                                                                             lin -2.6 7
                                                                                                ux .2
                                                                                             lin -2.6 6
                                                                                                ux .2
                                                                                             lin -2.6 5
                                                                                                ux .2
                                                                                             lin -2.6 4
                                                                                                ux .2
                                                                                             lin -2.6 3
                                                                                                ux .2
                                                                                             lin -2.6 2
                                                                                                ux .2
                                                                                             lin -2.6 1
                                                                                                ux .2




                                                                                                          Linux
                                                                                             lin -2.6 0




                                                                                                                        6
                                                                                                ux .2
                                                                                             lin -2.6 9
                                                                                                ux .1
                                                                                             lin -2.6 8
                                                                                                ux .1
                                                                                             lin -2.6 7
                                                                                                ux .1
                                                                                             lin -2.6 6
                                                                                                ux .1
                                                                                             lin -2.6 5
                                                                                                ux .1
                                                                                             lin -2.6 4
                                                                                                ux .1
                                                                                             lin -2.6 3
                                                                                                ux .1
                                                                                             lin -2.6
                                                                                                ux
                                                                                             lin
                                                                      !x&y case:
                                                                                   Defects
Issue
Goal: Find and fix bugs in C code



                   Find once, fix everywhere.




  Approach: Coccinelle: http://coccinelle.lip6.fr/
      Static analysis to find patterns in C code.

      Automatic transformation to fix bugs.

      User scriptable, based on patch notation
      (semantic patches).



                                 7
Bug: !x&y


  Author: Al Viro <viro@ZenIV.linux.org.uk>

      wmi: (!x & y) strikes again

  diff --git a/drivers/acpi/wmi.c b/drivers/acpi/wmi.c
  @@ -247,7 +247,7 @@
    block = &wblock->gblock;
    handle = wblock->handle;

  - if (!block->flags & ACPI_WMI_METHOD)
  + if (!(block->flags & ACPI_WMI_METHOD))
      return AE_BAD_DATA;

    if (block->instance_count < instance)



                           8
Finding and fixing !x&y bugs using Coccinelle



   @@
   expression E;
   constant C;
   @@

   - !E & C
   + !(E & C)


      E is an arbitrary expression.

      C is an arbitrary constant.




                                    9
Example

  Original code:

    if (!state->card->
       ac97_status & CENTER_LFE_ON)
            val &= ~DSP_BIND_CENTER_LFE;

  Semantic patch:

  @@ expression E; constant C; @@
  - !E & C
  + !(E & C)

  Generated code:

    if (!(state->card->ac97_status & CENTER_LFE_ON))
            val &= ~DSP_BIND_CENTER_LFE;


                           10
xt        .3
                                                                                        0
                                                                         ne        .6
                                                                                -2
                                                                              ux     .2
                                                                                        9
                                                                         lin       .6
                                                                                -2
          96 instances in Linux from 2.6.13 (August 2005) to




                                                                              ux     .2
                                                                                        8
                                                                         lin       .6
                                                                                -2
                                                                              ux     .2
                                                                                        7
                                                                         lin       .6
                                                                                -2
                                                                              ux     .2
                                                                                        6
                                                                         lin       .6
                                                                                -2
                                                                              ux     .2
                                                                                        5
                                                                         lin       .6
                                                                                -2
                                                                              ux     .2
                                                                                        4
                                                                         lin       .6
                                                                                -2
                                                                              ux     .2
                                                                                        3
                                                                         lin       .6
                                                                                -2
                                                                              ux     .2
                                                                                        2
                                                                         lin       .6
                                                                                -2
                                                                              ux




                                                                                            Linux
                                                                                        1
                                                                         lin         .2
                                                                                   .6




                                                                                                    11
                                                                                -2
                                                                              ux     .2
                                                                                        0
          v2.6.28 (December 2008)




                                                                         lin       .6
                                                                                -2
                                                                              ux     .1
                                                                                        9
                                                                         lin       .6
                                                                                -2
                                                                              ux     .1
                                                                                        8
                                                                         lin       .6
                                                                                -2
                                                                              ux     .1
                                                                                        7
                                                                         lin       .6
                                                                                -2
                                                                              ux     .1
                                                                                        6
                                                                         lin       .6
                                                                                -2
                                                                              ux     .1
                                                                                        5
                                                                         lin       .6
                                                                                -2
                                                                              ux     .1
                                                                                        4
                                                                         lin       .6
                                                                                -2
                                                                              ux     .1
                                                                                        3
                                                                         lin       .6
                                                                                -2
                                                                              ux
                                                                         lin
Results
                                                               Defects
Other examples: dereference of a possibly NULL value


  @@
  type T;
  identifier i,fld;
  expression E;
  statement S;
  @@

    T i = E->fld;
  + T i;
    ... when != E
         when != i
    if (E == NULL) S
  + i = E->fld;
Other examples: dereference of a possibly NULL value


  @@
  type T;
  identifier i,fld;
  expression E;
  statement S;
  @@

  - T i = E->fld;
  + T i;
    ... when != E
         when != i
    if (E == NULL) S
  + i = E->fld;


                         13
Other examples



     Forgetting to initialize the return value.

     Testing the wrong value.

     Forgetting to free data, unlock locks, etc.

     Dereferencing freed data.

     Double-initializing the same variable, field, etc.

     And many others...




                                  14
Conclusion

  A patch-like program matching and transformation language

  Over 1000 Coccinelle-based patches accepted into Linux

  Coccinelle semantic patches available in the Linux source code

  Used by other Linux developers

  Probable bugs found in gcc, postgresql, vim, amsn, pidgin,
  mplayer, openssl, vlc, wine


                http://coccinelle.lip6.fr/



                                15

Mais conteúdo relacionado

Mais de Anne Nicolas

Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataKernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataAnne Nicolas
 
Kernel Recipes 2019 - Analyzing changes to the binary interface exposed by th...
Kernel Recipes 2019 - Analyzing changes to the binary interface exposed by th...Kernel Recipes 2019 - Analyzing changes to the binary interface exposed by th...
Kernel Recipes 2019 - Analyzing changes to the binary interface exposed by th...Anne Nicolas
 
Embedded Recipes 2019 - Remote update adventures with RAUC, Yocto and Barebox
Embedded Recipes 2019 - Remote update adventures with RAUC, Yocto and BareboxEmbedded Recipes 2019 - Remote update adventures with RAUC, Yocto and Barebox
Embedded Recipes 2019 - Remote update adventures with RAUC, Yocto and BareboxAnne Nicolas
 
Embedded Recipes 2019 - Making embedded graphics less special
Embedded Recipes 2019 - Making embedded graphics less specialEmbedded Recipes 2019 - Making embedded graphics less special
Embedded Recipes 2019 - Making embedded graphics less specialAnne Nicolas
 
Embedded Recipes 2019 - Linux on Open Source Hardware and Libre Silicon
Embedded Recipes 2019 - Linux on Open Source Hardware and Libre SiliconEmbedded Recipes 2019 - Linux on Open Source Hardware and Libre Silicon
Embedded Recipes 2019 - Linux on Open Source Hardware and Libre SiliconAnne Nicolas
 
Embedded Recipes 2019 - From maintaining I2C to the big (embedded) picture
Embedded Recipes 2019 - From maintaining I2C to the big (embedded) pictureEmbedded Recipes 2019 - From maintaining I2C to the big (embedded) picture
Embedded Recipes 2019 - From maintaining I2C to the big (embedded) pictureAnne Nicolas
 
Embedded Recipes 2019 - Testing firmware the devops way
Embedded Recipes 2019 - Testing firmware the devops wayEmbedded Recipes 2019 - Testing firmware the devops way
Embedded Recipes 2019 - Testing firmware the devops wayAnne Nicolas
 
Embedded Recipes 2019 - Herd your socs become a matchmaker
Embedded Recipes 2019 - Herd your socs become a matchmakerEmbedded Recipes 2019 - Herd your socs become a matchmaker
Embedded Recipes 2019 - Herd your socs become a matchmakerAnne Nicolas
 
Embedded Recipes 2019 - LLVM / Clang integration
Embedded Recipes 2019 - LLVM / Clang integrationEmbedded Recipes 2019 - LLVM / Clang integration
Embedded Recipes 2019 - LLVM / Clang integrationAnne Nicolas
 
Embedded Recipes 2019 - Introduction to JTAG debugging
Embedded Recipes 2019 - Introduction to JTAG debuggingEmbedded Recipes 2019 - Introduction to JTAG debugging
Embedded Recipes 2019 - Introduction to JTAG debuggingAnne Nicolas
 
Embedded Recipes 2019 - Pipewire a new foundation for embedded multimedia
Embedded Recipes 2019 - Pipewire a new foundation for embedded multimediaEmbedded Recipes 2019 - Pipewire a new foundation for embedded multimedia
Embedded Recipes 2019 - Pipewire a new foundation for embedded multimediaAnne Nicolas
 
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all startedKernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all startedAnne Nicolas
 
Kernel Recipes 2019 - Suricata and XDP
Kernel Recipes 2019 - Suricata and XDPKernel Recipes 2019 - Suricata and XDP
Kernel Recipes 2019 - Suricata and XDPAnne Nicolas
 
Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)
Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)
Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)Anne Nicolas
 
Kernel Recipes 2019 - Formal modeling made easy
Kernel Recipes 2019 - Formal modeling made easyKernel Recipes 2019 - Formal modeling made easy
Kernel Recipes 2019 - Formal modeling made easyAnne Nicolas
 
Kernel Recipes 2019 - CVEs are dead, long live the CVE!
Kernel Recipes 2019 - CVEs are dead, long live the CVE!Kernel Recipes 2019 - CVEs are dead, long live the CVE!
Kernel Recipes 2019 - CVEs are dead, long live the CVE!Anne Nicolas
 
Kernel Recipes 2019 - XDP closer integration with network stack
Kernel Recipes 2019 -  XDP closer integration with network stackKernel Recipes 2019 -  XDP closer integration with network stack
Kernel Recipes 2019 - XDP closer integration with network stackAnne Nicolas
 
Kernel Recipes 2019 - Kernel hacking behind closed doors
Kernel Recipes 2019 - Kernel hacking behind closed doorsKernel Recipes 2019 - Kernel hacking behind closed doors
Kernel Recipes 2019 - Kernel hacking behind closed doorsAnne Nicolas
 
Kernel Recipes 2019 - Faster IO through io_uring
Kernel Recipes 2019 - Faster IO through io_uringKernel Recipes 2019 - Faster IO through io_uring
Kernel Recipes 2019 - Faster IO through io_uringAnne Nicolas
 
Embedded Recipes 2019 - RT is about to make it to mainline. Now what?
Embedded Recipes 2019 - RT is about to make it to mainline. Now what?Embedded Recipes 2019 - RT is about to make it to mainline. Now what?
Embedded Recipes 2019 - RT is about to make it to mainline. Now what?Anne Nicolas
 

Mais de Anne Nicolas (20)

Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataKernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
 
Kernel Recipes 2019 - Analyzing changes to the binary interface exposed by th...
Kernel Recipes 2019 - Analyzing changes to the binary interface exposed by th...Kernel Recipes 2019 - Analyzing changes to the binary interface exposed by th...
Kernel Recipes 2019 - Analyzing changes to the binary interface exposed by th...
 
Embedded Recipes 2019 - Remote update adventures with RAUC, Yocto and Barebox
Embedded Recipes 2019 - Remote update adventures with RAUC, Yocto and BareboxEmbedded Recipes 2019 - Remote update adventures with RAUC, Yocto and Barebox
Embedded Recipes 2019 - Remote update adventures with RAUC, Yocto and Barebox
 
Embedded Recipes 2019 - Making embedded graphics less special
Embedded Recipes 2019 - Making embedded graphics less specialEmbedded Recipes 2019 - Making embedded graphics less special
Embedded Recipes 2019 - Making embedded graphics less special
 
Embedded Recipes 2019 - Linux on Open Source Hardware and Libre Silicon
Embedded Recipes 2019 - Linux on Open Source Hardware and Libre SiliconEmbedded Recipes 2019 - Linux on Open Source Hardware and Libre Silicon
Embedded Recipes 2019 - Linux on Open Source Hardware and Libre Silicon
 
Embedded Recipes 2019 - From maintaining I2C to the big (embedded) picture
Embedded Recipes 2019 - From maintaining I2C to the big (embedded) pictureEmbedded Recipes 2019 - From maintaining I2C to the big (embedded) picture
Embedded Recipes 2019 - From maintaining I2C to the big (embedded) picture
 
Embedded Recipes 2019 - Testing firmware the devops way
Embedded Recipes 2019 - Testing firmware the devops wayEmbedded Recipes 2019 - Testing firmware the devops way
Embedded Recipes 2019 - Testing firmware the devops way
 
Embedded Recipes 2019 - Herd your socs become a matchmaker
Embedded Recipes 2019 - Herd your socs become a matchmakerEmbedded Recipes 2019 - Herd your socs become a matchmaker
Embedded Recipes 2019 - Herd your socs become a matchmaker
 
Embedded Recipes 2019 - LLVM / Clang integration
Embedded Recipes 2019 - LLVM / Clang integrationEmbedded Recipes 2019 - LLVM / Clang integration
Embedded Recipes 2019 - LLVM / Clang integration
 
Embedded Recipes 2019 - Introduction to JTAG debugging
Embedded Recipes 2019 - Introduction to JTAG debuggingEmbedded Recipes 2019 - Introduction to JTAG debugging
Embedded Recipes 2019 - Introduction to JTAG debugging
 
Embedded Recipes 2019 - Pipewire a new foundation for embedded multimedia
Embedded Recipes 2019 - Pipewire a new foundation for embedded multimediaEmbedded Recipes 2019 - Pipewire a new foundation for embedded multimedia
Embedded Recipes 2019 - Pipewire a new foundation for embedded multimedia
 
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all startedKernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all started
 
Kernel Recipes 2019 - Suricata and XDP
Kernel Recipes 2019 - Suricata and XDPKernel Recipes 2019 - Suricata and XDP
Kernel Recipes 2019 - Suricata and XDP
 
Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)
Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)
Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)
 
Kernel Recipes 2019 - Formal modeling made easy
Kernel Recipes 2019 - Formal modeling made easyKernel Recipes 2019 - Formal modeling made easy
Kernel Recipes 2019 - Formal modeling made easy
 
Kernel Recipes 2019 - CVEs are dead, long live the CVE!
Kernel Recipes 2019 - CVEs are dead, long live the CVE!Kernel Recipes 2019 - CVEs are dead, long live the CVE!
Kernel Recipes 2019 - CVEs are dead, long live the CVE!
 
Kernel Recipes 2019 - XDP closer integration with network stack
Kernel Recipes 2019 -  XDP closer integration with network stackKernel Recipes 2019 -  XDP closer integration with network stack
Kernel Recipes 2019 - XDP closer integration with network stack
 
Kernel Recipes 2019 - Kernel hacking behind closed doors
Kernel Recipes 2019 - Kernel hacking behind closed doorsKernel Recipes 2019 - Kernel hacking behind closed doors
Kernel Recipes 2019 - Kernel hacking behind closed doors
 
Kernel Recipes 2019 - Faster IO through io_uring
Kernel Recipes 2019 - Faster IO through io_uringKernel Recipes 2019 - Faster IO through io_uring
Kernel Recipes 2019 - Faster IO through io_uring
 
Embedded Recipes 2019 - RT is about to make it to mainline. Now what?
Embedded Recipes 2019 - RT is about to make it to mainline. Now what?Embedded Recipes 2019 - RT is about to make it to mainline. Now what?
Embedded Recipes 2019 - RT is about to make it to mainline. Now what?
 

Último

The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 

Último (20)

The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 

Coccinelle, a bug finding tool

  • 1. Bug Finding using Coccinelle Julia Lawall (Inria/LIP6) Joint work with Gilles Muller, René Rydhof Hansen, Nicolas Palix, Arie Middelkoop September 21, 2012 1
  • 3. Our focus Bugs in the Linux kernel Linux is critical software. – Used in embedded systems, desktops, servers, etc. Linux is very large. – Almost 18 000 .c files – Over 10.5 million lines of code – Increase of 8% since July 2011 (Linux 3.0). Linux has both more and less experienced developers. – Maintainers, contributers, developers of proprietary drivers 3
  • 4. Bug: !x&y Author: Al Viro <viro@ZenIV.linux.org.uk> wmi: (!x & y) strikes again diff --git a/drivers/acpi/wmi.c b/drivers/acpi/wmi.c @@ -247,7 +247,7 @@ block = &wblock->gblock; handle = wblock->handle; - if (!block->flags & ACPI_WMI_METHOD) + if (!(block->flags & ACPI_WMI_METHOD)) return AE_BAD_DATA; if (block->instance_count < instance)
  • 5. Bug: dereference of a possibly NULL value Author: Mariusz Kozlowski <m.kozlowski@tuxland.pl> tun/tap: Fix crashes if open() /dev/net/tun and then poll() it. diff --git a/drivers/net/tun.c b/drivers/net/tun.c @@ -486,12 +486,14 @@ - struct sock *sk = tun->sk; + struct sock *sk; unsigned int mask = 0; if (!tun) return POLLERR; + sk = tun->sk; 5
  • 6. Isolated problems, but these bug types can occur many times 0 xt .3 bug present ne -2.6 9 file absent ux .2 lin -2.6 8 ux .2 lin -2.6 7 ux .2 lin -2.6 6 ux .2 lin -2.6 5 ux .2 lin -2.6 4 ux .2 lin -2.6 3 ux .2 lin -2.6 2 ux .2 lin -2.6 1 ux .2 Linux lin -2.6 0 6 ux .2 lin -2.6 9 ux .1 lin -2.6 8 ux .1 lin -2.6 7 ux .1 lin -2.6 6 ux .1 lin -2.6 5 ux .1 lin -2.6 4 ux .1 lin -2.6 3 ux .1 lin -2.6 ux lin !x&y case: Defects Issue
  • 7. Goal: Find and fix bugs in C code Find once, fix everywhere. Approach: Coccinelle: http://coccinelle.lip6.fr/ Static analysis to find patterns in C code. Automatic transformation to fix bugs. User scriptable, based on patch notation (semantic patches). 7
  • 8. Bug: !x&y Author: Al Viro <viro@ZenIV.linux.org.uk> wmi: (!x & y) strikes again diff --git a/drivers/acpi/wmi.c b/drivers/acpi/wmi.c @@ -247,7 +247,7 @@ block = &wblock->gblock; handle = wblock->handle; - if (!block->flags & ACPI_WMI_METHOD) + if (!(block->flags & ACPI_WMI_METHOD)) return AE_BAD_DATA; if (block->instance_count < instance) 8
  • 9. Finding and fixing !x&y bugs using Coccinelle @@ expression E; constant C; @@ - !E & C + !(E & C) E is an arbitrary expression. C is an arbitrary constant. 9
  • 10. Example Original code: if (!state->card-> ac97_status & CENTER_LFE_ON) val &= ~DSP_BIND_CENTER_LFE; Semantic patch: @@ expression E; constant C; @@ - !E & C + !(E & C) Generated code: if (!(state->card->ac97_status & CENTER_LFE_ON)) val &= ~DSP_BIND_CENTER_LFE; 10
  • 11. xt .3 0 ne .6 -2 ux .2 9 lin .6 -2 96 instances in Linux from 2.6.13 (August 2005) to ux .2 8 lin .6 -2 ux .2 7 lin .6 -2 ux .2 6 lin .6 -2 ux .2 5 lin .6 -2 ux .2 4 lin .6 -2 ux .2 3 lin .6 -2 ux .2 2 lin .6 -2 ux Linux 1 lin .2 .6 11 -2 ux .2 0 v2.6.28 (December 2008) lin .6 -2 ux .1 9 lin .6 -2 ux .1 8 lin .6 -2 ux .1 7 lin .6 -2 ux .1 6 lin .6 -2 ux .1 5 lin .6 -2 ux .1 4 lin .6 -2 ux .1 3 lin .6 -2 ux lin Results Defects
  • 12. Other examples: dereference of a possibly NULL value @@ type T; identifier i,fld; expression E; statement S; @@ T i = E->fld; + T i; ... when != E when != i if (E == NULL) S + i = E->fld;
  • 13. Other examples: dereference of a possibly NULL value @@ type T; identifier i,fld; expression E; statement S; @@ - T i = E->fld; + T i; ... when != E when != i if (E == NULL) S + i = E->fld; 13
  • 14. Other examples Forgetting to initialize the return value. Testing the wrong value. Forgetting to free data, unlock locks, etc. Dereferencing freed data. Double-initializing the same variable, field, etc. And many others... 14
  • 15. Conclusion A patch-like program matching and transformation language Over 1000 Coccinelle-based patches accepted into Linux Coccinelle semantic patches available in the Linux source code Used by other Linux developers Probable bugs found in gcc, postgresql, vim, amsn, pidgin, mplayer, openssl, vlc, wine http://coccinelle.lip6.fr/ 15