cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] field access scoping / check who accesses certain struct members ?
@ 2019-11-20 19:50 Enrico Weigelt, metux IT consult
  2019-11-20 20:44 ` Julia Lawall
  0 siblings, 1 reply; 3+ messages in thread
From: Enrico Weigelt, metux IT consult @ 2019-11-20 19:50 UTC (permalink / raw)
  To: Coccinelle

Hi folks,


is there a way to scan for code lines that access certain struct
members ?

Rationale:

In the kernel, we have lots of struct fields (eg. in struct device)
which are supposed to be only accessed by certain subsystems.
I'd like to add some checks for that by scanning for all sites that
access certain struct members and filter out those files that are
allowed to do so. This should print out all sites which do those
unallowed direct access w/o going through the appropriate helpers.


--mtx

---
Enrico Weigelt, metux IT consult
Free software and Linux embedded engineering
info@metux.net -- +49-151-27565287
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Cocci] field access scoping / check who accesses certain struct members ?
  2019-11-20 19:50 [Cocci] field access scoping / check who accesses certain struct members ? Enrico Weigelt, metux IT consult
@ 2019-11-20 20:44 ` Julia Lawall
  2019-11-21 16:04   ` Markus Elfring
  0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2019-11-20 20:44 UTC (permalink / raw)
  To: Enrico Weigelt, metux IT consult; +Cc: Coccinelle



On Wed, 20 Nov 2019, Enrico Weigelt, metux IT consult wrote:

> Hi folks,
>
>
> is there a way to scan for code lines that access certain struct
> members ?

@@
struct structure_of_interest x;
@@

* x.field_of_interest

This will take care of pointers as well.

If you want to check on many types and fields, you can use the following
rule:

@@
identifier virtual.ty;
struct ty x;
identifier virtual.fld;
@@

* x.fld

Then you can run it with the command-line options:

-D ty=type_of_interest -D fld=field_of_interest

To figure out all the types, Coccinelle may need information from header
files.  So you could run it with the options

--recursive-includes --include-headers-for-types --relax-include-path

This will take a long time.

It may be useful to use to python code to note the file in which the
reference occurs, and then only print a message if it is a file that is of
concern.  So you could have:

@r@
identifier virtual.ty;
struct ty x;
identifier virtual.fld;
position p;
@@

* x.fld@p

@script:python@
p << r.p;
@@

... p[0].file ...

Let me know if anything is not clear.

julia
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Cocci] field access scoping / check who accesses certain struct members ?
  2019-11-20 20:44 ` Julia Lawall
@ 2019-11-21 16:04   ` Markus Elfring
  0 siblings, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2019-11-21 16:04 UTC (permalink / raw)
  To: Julia Lawall, Enrico Weigelt; +Cc: cocci

> If you want to check on many types and fields, you can use the following rule:
>
> @@
> identifier virtual.ty;
> struct ty x;
> identifier virtual.fld;
> @@
>
> * x.fld
>
> Then you can run it with the command-line options:
>
> -D ty=type_of_interest -D fld=field_of_interest

This data processing approach can be useful.
But I imagine that an other approach can become nicer if more identifier
combinations should be checked at once.
* How do you think about to construct SmPL constraints for the mentioned
  metavariables in the format of lists or regular expressions?

* Would you like to work with scripted SmPL constraints (so that even more
  helpful data structures can be applied)?

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-11-21 16:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-20 19:50 [Cocci] field access scoping / check who accesses certain struct members ? Enrico Weigelt, metux IT consult
2019-11-20 20:44 ` Julia Lawall
2019-11-21 16:04   ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).