mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Julia Lawall <julia@diku.dk>
To: Emese Revfy <re.emese@gmail.com>
Cc: Kees Cook <kees.cook@canonical.com>,
	linux-kernel@vger.kernel.org, cocci@diku.dk,
	Lionel Debroux <lionel_debroux@yahoo.fr>,
	Brad Spengler <spender@grsecurity.net>
Subject: Re: [Cocci] Re: status of constification
Date: Thu, 11 Nov 2010 23:53:35 +0100 (CET)	[thread overview]
Message-ID: <Pine.LNX.4.64.1011112352030.27612@ask.diku.dk> (raw)
In-Reply-To: <4CDC64B9.8070208@gmail.com>

On Thu, 11 Nov 2010, Emese Revfy wrote:

> On 11/10/10 07:35, Julia Lawall wrote:
> >> I tried to automate the whole process with Coccinelle but I abandoned it
> >> because Coccinelle didn't support recursive header file inclusion at the time.
> >> If someone feels like fixing Coccinelle then I would quickly finish my script
> >> (it has a few bugs because I could never test it for real), but see the end
> >> of the mail for the current version. I think it would be a good idea because
> >> it would take a few hours only to generate a constification patch for a new
> >> kernel. One thing that probably cannot be automated with Coccinelle is that
> >> once the script determines that a given structure cannot be constified, it
> >> cannot undo already emitted patches for the given structure so it must be
> >> cleaned up by post processing script.
> > 
> > What would the right approach be?  It is not obvious to find 100% of the 
> > header files, because some of them depend on information in Makefiles.  
> 
> For 100% coverage you can look at how the Linux Makefiles invoke sparse.

I haven't looked at it, but I doubt it gives 100% coverage, because one 
can have code in both the if and else branches of an ifdef.  I would 
imagine that it gives 100% coverage for whatever architecture you would be 
compiling for?

julia

> > You can use that information by running the preprocessor on Coccinelle 
> > first, but then the result is only useful for finding files that need 
> > changing, but not actually making the changes because Coccinelle does not 
> > relate the preprocessed code back to the original code.  But if you run 
> > the preprocessor, you only get information for your current configuration, 
> > which is probably not what you want.
> > 
> > Coccinelle could certainly get a new option -really_all_includes, or 
> > something like that, that would recursively include among what it can find 
> > and what has not been included already.  Would that be what is wanted?
> 
> Yes, this is exactly what I'd like to have, missing the few includes
> you referred to above is not a problem for my purposes.
> 
> Thanks, Emese
> 
> > 
> > I guess that in practice the includes are only being used for type 
> > information?  Wouldn't it be safe to run the semantic patch based on the 
> > includes that are available?
> > 
> > julia
> > 
> >>
> >> --
> >> Emese
> >>
> >>
> >> // spatch.opt -sp_file $1 -include_headers -local_includes -all_includes -I "include/" -dir $2
> >>
> >> @initialize:python@
> >> noconst = []
> >>
> >> @stc@
> >> identifier idtype, y;
> >> type t;
> >> position p;
> >> @@
> >> struct idtype {
> >> 	...
> >> 	t (*y)(...);@p
> >> 	...
> >> };
> >>
> >> @notjustfp@
> >> identifier stc.idtype, y;
> >> type t;
> >> position p != stc.p;
> >> @@
> >> struct idtype {
> >> 	...
> >> 	t y;@p
> >> 	...
> >> };
> >>
> >> @script:python depends on notjustfp@
> >> @@
> >> cocci.include_match(False)
> >>
> >> @variable@
> >> identifier stc.idtype, idvariant, id;
> >> @@
> >> (
> >> 	struct idtype idvariant = {
> >> 		...
> >> 	};
> >> |
> >> 	struct idtype idvariant;
> >> |
> >> 	struct idtype *idvariant;
> >> |
> >> 	struct id {
> >> 		...
> >> 		struct idtype idvariant;
> >> 		...
> >> 	};
> >> )
> >>
> >> @script:python@
> >> y << variable.idvariant;
> >> @@
> >> if y in noconst:
> >> 	cocci.include_match(False)
> >>
> >> @alreadyconst@
> >> identifier stc.idtype, variable.idvariant, id;
> >> @@
> >> (
> >> 	const struct idtype idvariant;
> >> |
> >> 	const struct idtype idvariant = {
> >> 		...
> >> 	};
> >> |
> >> 	const struct idtype *idvariant;
> >> |
> >> 	struct id {
> >> 		...
> >> 		const struct idtype idvariant;
> >> 		...
> >> 	};
> >> )
> >>
> >> @script:python depends on alreadyconst@
> >> @@
> >> cocci.include_match(False)
> >>
> >> @fn_declaration@
> >> identifier stc.idtype, variable.idvariant, fn;
> >> type t;
> >> @@
> >> t fn(struct idtype *idvariant);
> >>
> >> @fn_definition@
> >> identifier stc.idtype, variable.idvariant, fn;
> >> type t;
> >> @@
> >> t fn(struct idtype *idvariant)
> >> {
> >> 	...
> >> }
> >>
> >> // TODO: handle var.field1.field2, var->field1->field2
> >> @assignement@
> >> identifier variable.idvariant, x, idptr;
> >> @@
> >> (
> >> 	idvariant.x = ...;
> >> |
> >> 	idvariant->x = ...;
> >> |
> >> 	idptr = &idvariant;
> >> 	...
> >> 	idptr->x = ...;
> >> |
> >> 	memcpy(&idvariant, ...);
> >> |
> >> 	memcpy(idvariant.x, ...);
> >> |
> >> 	memcpy(idvariant->x, ...);
> >> |
> >> 	idvariant = kzalloc(...);
> >> |
> >> 	idvariant = kmalloc(...);
> >> )
> >>
> >> @script:python depends on assignement@
> >> x << stc.idtype;
> >> y << variable.idvariant;
> >> @@
> >> print "Cannot be const: %s-%s" % (x, y)
> >> noconst.append(y)
> >> cocci.include_match(False)
> >>
> >> @depends on stc && !fn_declaration && !fn_definition@
> >> identifier stc.idtype, variable.idvariant, id;
> >> @@
> >> (
> >> -struct idtype idvariant = {
> >> +const struct idtype idvariant = {
> >> 		...
> >>  };
> >> |
> >> -struct idtype idvariant;
> >> +const struct idtype idvariant;
> >> |
> >> -struct idtype *idvariant;
> >> +const struct idtype *idvariant;
> >> |
> >> -struct idtype *idvariant = NULL;
> >> +const struct idtype *idvariant = NULL;
> >> |
> >> struct id {
> >> ...
> >> -struct idtype idvariant;
> >> +const struct idtype idvariant;
> >> ...
> >>  };
> >> )
> >>
> >> @depends on stc && fn_declaration && !fn_definition@
> >> identifier stc.idtype, variable.idvariant, fn_declaration.fn;
> >> type fn_declaration.t;
> >> @@
> >> t fn(
> >> -struct idtype *idvariant
> >> +const struct idtype *idvariant
> >>  );
> >>
> >> @depends on stc && !fn_declaration && fn_definition@
> >> identifier stc.idtype, variable.idvariant, fn_definition.fn;
> >> type fn_definition.t;
> >> @@
> >> t fn(
> >> -struct idtype *idvariant
> >> +const struct idtype *idvariant
> >>  )
> >>  {
> >>  	...
> >>  }
> >>
> >>
> > 
> 
> 

  reply	other threads:[~2010-11-11 22:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-08 22:38 Kees Cook
2010-11-09 21:54 ` Emese Revfy
     [not found] ` <4CD9BF25.4090306@gmail.com>
2010-11-10  6:35   ` [Cocci] " Julia Lawall
2010-11-11 21:48     ` Emese Revfy
2010-11-11 22:53       ` Julia Lawall [this message]
2010-11-13 12:13         ` Emese Revfy
2010-11-13 13:43           ` Julia Lawall
2010-11-13 14:41       ` Julia Lawall
2011-05-28  3:13   ` Kees Cook
2011-05-28  6:39     ` [Cocci] " Julia Lawall
2011-06-05 21:47       ` Emese Revfy
2011-06-06  5:03         ` Julia Lawall
2011-06-06  7:49         ` Julia Lawall
2011-06-10 21:28           ` Emese Revfy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.1011112352030.27612@ask.diku.dk \
    --to=julia@diku.dk \
    --cc=cocci@diku.dk \
    --cc=kees.cook@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lionel_debroux@yahoo.fr \
    --cc=re.emese@gmail.com \
    --cc=spender@grsecurity.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®