Re: [Cocci] cocci: remove unnecessary casts of void * while avoiding casts with __user or __force ?

2017-08-28 Thread Julia Lawall


On Mon, 28 Aug 2017, Joe Perches wrote:

> A simple cocci script that removes unnecessary casts of
> a void * will also remove casts with __force or __user

Unfortunately, attributes are currently not supported inside casts.  This
can be done in a hackish way (possible false negatives) as follows:

---

@initialize:ocaml@
@@

let close (p1,p2) =
  let r = (List.hd p1).line_end in
  let l = (List.hd p2).line in
  let rc = (List.hd p1).col_end in
  let lc = (List.hd p2).col in
  r = l && lc = rc+1

@r@
position p1,p2;
expression f,e;
type T;
@@

f(..., // generalize this rule as needed
 (T@p1 *@p2)
 e,...)

@@
position r.p2 : script:ocaml(r.p1) { close(p1,p2) };
position r.p1;
expression e;
type T;
@@

- (T@p1 *@p2)
  e

---

Basically, it assumes that if the type and the * are more than one space
apart then there is something important there, and the cast is not
removed.

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


[Cocci] cocci: remove unnecessary casts of void * while avoiding casts with __user or __force ?

2017-08-28 Thread Joe Perches
A simple cocci script that removes unnecessary casts of
a void * will also remove casts with __force or __user

e.g.:

-   xemaclite_aligned_write(address_ptr, (u32 __force *) addr, ETH_ALEN);
+   xemaclite_aligned_write(address_ptr, addr, ETH_ALEN);

Is there a simple mechanism to avoid converting those?

$ cat void.cocci
@@
type T;
void *v;
expression e;
@@

-   e = (T *)v;
+   e = v;

@@
identifier f;
type T;
void *v;
@@

f(...,
-   (T *)v,
+   v,
...)

$


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


Re: [Cocci] Automatic replacement of function declarations

2017-08-28 Thread Kees Cook
On Mon, Aug 28, 2017 at 4:34 AM, Julia Lawall  wrote:
>
>
> On Sun, 27 Aug 2017, Kees Cook wrote:
>
>>  Hi,
>>
>> So, I noticed that if I replace argument types in a function,
>> coccinelle will normally replace them in any forward declarations too.
>> However, this:
>>
>> @change_callback
>>  depends on patch@
>> identifier _callback;
>> type _origtype;
>> identifier _origarg;
>> type _handletype;
>> identifier _handle;
>> @@
>>
>>  void _callback(
>> -_origtype _origarg
>> +struct timer_list *t
>>  )
>>  {
>> ... when != _origarg
>> _handletype *_handle =
>> -(_handletype *)_origarg;
>> +TIMER_CONTAINER(_handle, t, timer);
>> ... when != _origarg
>>  }
>>
>> run against drivers/net/wireless/ray_cs.c will fix join_net and
>> start_net correctly:
>>
>> -static void join_net(u_long local);
>> -static void start_net(u_long local);
>> +static void join_net(struct timer_list *t);
>> +static void start_net(struct timer_list *t);
>>
>> but misses  verify_dl_startup and authenticate_timeout.
>>
>> The difference is the latter have forward declarations without an argument 
>> name:
>>
>> static void authenticate_timeout(u_long);
>> static void verify_dl_startup(u_long);
>
> This was the first use of u_long in the file, so it was considering it to
> be a K parameter name.  Now, by default, as soon as there is any non-K
> parameter, the parser gives up on trying to find K parameters.
> --force-kr causes it to keep looking for K parameters, and --prevent-kr
> causes it to never look for K parameters.
>
> I don't know to what extent people are still working on K code.  Another
> option would be to have --prevent-kr as the default.
>
> In any case, the example works now with no extra command line arguments.

Oh awesome, thanks for fixing this!

-Kees

-- 
Kees Cook
Pixel Security
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] Addition of support for conjunctions on types

2017-08-28 Thread SF Markus Elfring
>> I am looking for descriptions about circumstances under which the 
>> metavariable combination
>> will be useful by the mentioned SmPL conjunctions.
> 
> I still don't understand the question.

It seems that I have got a few understanding difficulties with the added 
functionality.


> Another example is
> 
> (
> (
> struct i
> |
> union i
> )
> &
> t
> )
> 
> Now you have one metavariable, t, that stores the whole type,

I find this technical detail unclear.


> whether it is a struct or a union.

But this information sounds promising.

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


Re: [Cocci] Addition of support for conjunctions on types

2017-08-28 Thread Julia Lawall


On Mon, 28 Aug 2017, SF Markus Elfring wrote:

> > I have no idea what information is wanted.
>
> I am looking for descriptions about circumstances under which the 
> metavariable combination
> will be useful by the mentioned SmPL conjunctions.

I still don't understand the question.  Another example is

(
(
struct i
|
union i
)
&
t
)

Now you have one metavariable, t, that stores the whole type, whether it
is a struct or a union.

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


Re: [Cocci] Addition of support for conjunctions on types

2017-08-28 Thread SF Markus Elfring
> I have no idea what information is wanted.

I am looking for descriptions about circumstances under which the metavariable 
combination
will be useful by the mentioned SmPL conjunctions.

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


Re: [Cocci] Addition of support for conjunctions on types

2017-08-28 Thread SF Markus Elfring
>> I would like to know a bit more for the application of such a metavariable 
>> combination.

I would appreciate another feedback for this aspect.


>> Unfortunately, I get the information “… Fatal error occurred, no output PDF
>> file produced! …” from data processing by the command “make docs”.
> 
> Fixed.  Thanks for the report.

Thanks for your quick software update “latex fix”.

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


Re: [Cocci] Addition of support for conjunctions on types

2017-08-28 Thread SF Markus Elfring
> @@
> type t;
> identifier i;
> @@
>
> (
> struct i
> &
> t
> )
>
> will now bind both i and t appropriately.


I would like to know a bit more for the application of such a metavariable 
combination.
I hoped also to read something about it in the current manual.
Unfortunately, I get the information “… Fatal error occurred, no output PDF
file produced! …” from data processing by the command “make docs”.

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


Re: [Cocci] Addition of support for variable attributes

2017-08-28 Thread SF Markus Elfring
> It is now (github) possible to match and transform a single such attribute
> when it comes after the name of a variable in a variable declaration.

This is a nice extension for your software.

How does this information fit to the wording in the manual?
https://github.com/coccinelle/coccinelle/blob/2776ede39f6f4197eaa0fc8344152e5ed07e0ad3/docs/manual/cocci_syntax.tex#L308
“…
It is not possible to match or remove an attribute, only to add one.
…”


> attribute name __ro_after_init;

Do you imagine any further software evolution if you start the specification
of this metavariable type with two words?

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


[Cocci] update

2017-08-28 Thread Julia Lawall
There was a bug in the include file management that could cause
--recursive-includes to go into an infinite loop.  That is now fixed.

There is also now support for conjunctions on types.  That is:

@@
type t;
identifier i;
@@

(
struct i
&
t
)

will now bind both i and t appropriately.

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


Re: [Cocci] Automatic replacement of function declarations

2017-08-28 Thread Julia Lawall


On Sun, 27 Aug 2017, Kees Cook wrote:

>  Hi,
>
> So, I noticed that if I replace argument types in a function,
> coccinelle will normally replace them in any forward declarations too.
> However, this:
>
> @change_callback
>  depends on patch@
> identifier _callback;
> type _origtype;
> identifier _origarg;
> type _handletype;
> identifier _handle;
> @@
>
>  void _callback(
> -_origtype _origarg
> +struct timer_list *t
>  )
>  {
> ... when != _origarg
> _handletype *_handle =
> -(_handletype *)_origarg;
> +TIMER_CONTAINER(_handle, t, timer);
> ... when != _origarg
>  }
>
> run against drivers/net/wireless/ray_cs.c will fix join_net and
> start_net correctly:
>
> -static void join_net(u_long local);
> -static void start_net(u_long local);
> +static void join_net(struct timer_list *t);
> +static void start_net(struct timer_list *t);
>
> but misses  verify_dl_startup and authenticate_timeout.
>
> The difference is the latter have forward declarations without an argument 
> name:
>
> static void authenticate_timeout(u_long);
> static void verify_dl_startup(u_long);

This was the first use of u_long in the file, so it was considering it to
be a K parameter name.  Now, by default, as soon as there is any non-K
parameter, the parser gives up on trying to find K parameters.
--force-kr causes it to keep looking for K parameters, and --prevent-kr
causes it to never look for K parameters.

I don't know to what extent people are still working on K code.  Another
option would be to have --prevent-kr as the default.

In any case, the example works now with no extra command line arguments.

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


[Cocci] Automatic replacement of function declarations

2017-08-28 Thread Kees Cook
 Hi,

So, I noticed that if I replace argument types in a function,
coccinelle will normally replace them in any forward declarations too.
However, this:

@change_callback
 depends on patch@
identifier _callback;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@

 void _callback(
-_origtype _origarg
+struct timer_list *t
 )
 {
... when != _origarg
_handletype *_handle =
-(_handletype *)_origarg;
+TIMER_CONTAINER(_handle, t, timer);
... when != _origarg
 }

run against drivers/net/wireless/ray_cs.c will fix join_net and
start_net correctly:

-static void join_net(u_long local);
-static void start_net(u_long local);
+static void join_net(struct timer_list *t);
+static void start_net(struct timer_list *t);

but misses  verify_dl_startup and authenticate_timeout.

The difference is the latter have forward declarations without an argument name:

static void authenticate_timeout(u_long);
static void verify_dl_startup(u_long);

Is this a bug, or did I write my rule in some way that excludes these
forward declarations?

Thanks!

-Kees

-- 
Kees Cook
Pixel Security
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] Automatic replacement of function declarations

2017-08-28 Thread Julia Lawall


On Sun, 27 Aug 2017, Kees Cook wrote:

>  Hi,
>
> So, I noticed that if I replace argument types in a function,
> coccinelle will normally replace them in any forward declarations too.
> However, this:
>
> @change_callback
>  depends on patch@
> identifier _callback;
> type _origtype;
> identifier _origarg;
> type _handletype;
> identifier _handle;
> @@
>
>  void _callback(
> -_origtype _origarg
> +struct timer_list *t
>  )
>  {
> ... when != _origarg
> _handletype *_handle =
> -(_handletype *)_origarg;
> +TIMER_CONTAINER(_handle, t, timer);
> ... when != _origarg
>  }
>
> run against drivers/net/wireless/ray_cs.c will fix join_net and
> start_net correctly:
>
> -static void join_net(u_long local);
> -static void start_net(u_long local);
> +static void join_net(struct timer_list *t);
> +static void start_net(struct timer_list *t);
>
> but misses  verify_dl_startup and authenticate_timeout.
>
> The difference is the latter have forward declarations without an argument 
> name:
>
> static void authenticate_timeout(u_long);
> static void verify_dl_startup(u_long);
>
> Is this a bug, or did I write my rule in some way that excludes these
> forward declarations?

I think that the problem is with u_long.  Everything is fine if you
replace it with int.  I'm not sure what is going on, though because there
is no parse error.  Will check further.

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


Re: [Cocci] Automatic replacement of function declarations

2017-08-28 Thread Julia Lawall


On Sun, 27 Aug 2017, Kees Cook wrote:

>  Hi,
>
> So, I noticed that if I replace argument types in a function,
> coccinelle will normally replace them in any forward declarations too.
> However, this:
>
> @change_callback
>  depends on patch@
> identifier _callback;
> type _origtype;
> identifier _origarg;
> type _handletype;
> identifier _handle;
> @@
>
>  void _callback(
> -_origtype _origarg
> +struct timer_list *t
>  )
>  {
> ... when != _origarg
> _handletype *_handle =
> -(_handletype *)_origarg;
> +TIMER_CONTAINER(_handle, t, timer);
> ... when != _origarg
>  }
>
> run against drivers/net/wireless/ray_cs.c will fix join_net and
> start_net correctly:
>
> -static void join_net(u_long local);
> -static void start_net(u_long local);
> +static void join_net(struct timer_list *t);
> +static void start_net(struct timer_list *t);
>
> but misses  verify_dl_startup and authenticate_timeout.
>
> The difference is the latter have forward declarations without an argument 
> name:
>
> static void authenticate_timeout(u_long);
> static void verify_dl_startup(u_long);
>
> Is this a bug, or did I write my rule in some way that excludes these
> forward declarations?

It is supposed to work.  I will check on it.

julia

>
> Thanks!
>
> -Kees
>
> --
> Kees Cook
> Pixel Security
>
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci