Coccinelle archive on lore.kernel.org
 help / color / 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, back to index

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

Coccinelle archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/cocci/0 cocci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cocci cocci/ https://lore.kernel.org/cocci \
		cocci@systeme.lip6.fr
	public-inbox-index cocci

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/fr.lip6.systeme.cocci


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git