cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

flags.cocci (1589B)


      1// SPDX-License-Identifier: GPL-2.0-only
      2/// Find nested lock+irqsave functions that use the same flags variables
      3///
      4// Confidence: High
      5// Copyright: (C) 2010-2012 Nicolas Palix.
      6// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6.
      7// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6.
      8// URL: http://coccinelle.lip6.fr/
      9// Comments:
     10// Options: --no-includes --include-headers
     11
     12virtual context
     13virtual org
     14virtual report
     15
     16@r exists@
     17expression lock1,lock2,flags;
     18position p1,p2;
     19@@
     20
     21(
     22spin_lock_irqsave@p1(lock1,flags)
     23|
     24read_lock_irqsave@p1(lock1,flags)
     25|
     26write_lock_irqsave@p1(lock1,flags)
     27)
     28... when != flags
     29(
     30spin_lock_irqsave(lock1,flags)
     31|
     32read_lock_irqsave(lock1,flags)
     33|
     34write_lock_irqsave(lock1,flags)
     35|
     36spin_lock_irqsave@p2(lock2,flags)
     37|
     38read_lock_irqsave@p2(lock2,flags)
     39|
     40write_lock_irqsave@p2(lock2,flags)
     41)
     42
     43@d exists@
     44expression f <= r.flags;
     45expression lock1,lock2,flags;
     46position r.p1, r.p2;
     47@@
     48
     49(
     50*spin_lock_irqsave@p1(lock1,flags)
     51|
     52*read_lock_irqsave@p1(lock1,flags)
     53|
     54*write_lock_irqsave@p1(lock1,flags)
     55)
     56... when != f
     57(
     58*spin_lock_irqsave@p2(lock2,flags)
     59|
     60*read_lock_irqsave@p2(lock2,flags)
     61|
     62*write_lock_irqsave@p2(lock2,flags)
     63)
     64
     65// ----------------------------------------------------------------------
     66
     67@script:python depends on d && org@
     68p1 << r.p1;
     69p2 << r.p2;
     70@@
     71
     72cocci.print_main("original lock",p1)
     73cocci.print_secs("nested lock+irqsave that reuses flags",p2)
     74
     75@script:python depends on d && report@
     76p1 << r.p1;
     77p2 << r.p2;
     78@@
     79
     80msg="ERROR: nested lock+irqsave that reuses flags from line %s." % (p1[0].line)
     81coccilib.report.print_report(p2[0], msg)