Hunt for array users of roc_dointvec()
I'm trying to hunt for users of the proc_dointvec() handler in setups where more than one value is expected to be used. The way this old API works is it lets you specifiy in a structure the variables and the size of the variables. In the singular case the size will be maxlen = sizeof(int). If an array is used a user may use maxlen = 2*sizeof(int), or other things.
Since I am looking for unsigned int users of proc_dointvec() to later consider converting them to proc_douintvec() I can just focus for now when the is not maxlen = (unsigned int) or maxlen = sizeof(int), and then manually review the cases. Unfrotunately I cannot seem to construct grammar to query context for this.
Let's consider just trying to get context for the case where the size is not maxlen = sizeof(unsigned int). I tried this bug get no results:
virtual context
@ find_proc @
identifier ctls;
expression name;
@@
struct ctl_table ctls[] = {
{
.procname = name,
.proc_handler = proc_dointvec,
},
};@ singular_ints @
identifier find_proc.ctls;
expression find_proc.name;
@@
struct ctl_table ctls[] = {
{
.procname = name,
.maxlen = sizeof(unsigned int),
},
};@ array_ints depends on context && !singular_ints @ identifier find_proc.ctls;
expression find_proc.name, E;
@@
struct ctl_table ctls[] = {
{
* .procname = name,
* .maxlen = E,
},
};Quoted 7 lines · Luis R. Rodriguez
I'm trying to hunt for users of the
proc_dointvec()handler in setups where more than one value is expected to be used. The way this old API works is it lets you specifiy in a structure the variables and the size of the variables. In the singular case the size will be maxlen = sizeof(int). If an array is used a user may use maxlen = 2*sizeof(int), or other things.
Quoted 8 lines
Since I am looking for unsigned int users of
proc_dointvec()to later consider converting them toproc_douintvec()I can just focus for now when the is not maxlen = (unsigned int) or maxlen = sizeof(int), and then manually review the cases. Unfrotunately I cannot seem to construct grammar to query context for this.Let's consider just trying to get context for the case where the size is not maxlen = sizeof(unsigned int). I tried this bug get no results:
Do you have an example of a C file on which you expect to get a match?
julia
Quoted 43 lines
virtual context
@
find_proc@
identifier ctls;
expression name;
@@struct ctl_table ctls[] = { { .procname = name, .proc_handler = proc_dointvec, }, };@
singular_ints@
identifier find_proc.ctls;
expression find_proc.name;
@@struct ctl_table ctls[] = { { .procname = name, .maxlen = sizeof(unsigned int), }, };@
array_intsdepends on context && !singular_ints @ identifier find_proc.ctls;
expression find_proc.name, E;
@@struct ctl_table ctls[] = { { * .procname = name, * .maxlen = E, }, };_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 17 lines · Julia Lawall
Quoted 13 lines · Luis R. Rodriguez
I'm trying to hunt for users of the
proc_dointvec()handler in setups where more than one value is expected to be used. The way this old API works is it lets you specifiy in a structure the variables and the size of the variables. In the singular case the size will be maxlen = sizeof(int). If an array is used a user may use maxlen = 2*sizeof(int), or other things.Since I am looking for unsigned int users of
proc_dointvec()to later consider converting them toproc_douintvec()I can just focus for now when the is not maxlen = (unsigned int) or maxlen = sizeof(int), and then manually review the cases. Unfrotunately I cannot seem to construct grammar to query context for this.
Quoted 4 lines
Quoted 2 lines
Let's consider just trying to get context for the case where the size is not maxlen = sizeof(unsigned int). I tried this bug get no results:
Do you have an example of a C file on which you expect to get a match?
Sure,
ipv4_local_port_range() on the file net/ipv4/sysctl_net_ipv4.c has an example in C code on a functoin where it uses:
.maxlen = sizeof(range),
However the typical use seems to be static definitions as part of the file, as in kernel/sysctl.c on the line after:
static struct ctl_table kern_table[] = {
An example would be on the traceoff_on_warning. I know that's not an array but its an example to then manually inspect.
Luis
Quoted 21 lines · Luis R. Rodriguez
Quoted 20 lines · Julia Lawall
Quoted 15 lines · Luis R. Rodriguez
I'm trying to hunt for users of the
proc_dointvec()handler in setups where more than one value is expected to be used. The way this old API works is it lets you specifiy in a structure the variables and the size of the variables. In the singular case the size will be maxlen = sizeof(int). If an array is used a user may use maxlen = 2*sizeof(int), or other things.Since I am looking for unsigned int users of
proc_dointvec()to later consider converting them toproc_douintvec()I can just focus for now when the is not maxlen = (unsigned int) or maxlen = sizeof(int), and then manually review the cases. Unfrotunately I cannot seem to construct grammar to query context for this.Let's consider just trying to get context for the case where the size is not maxlen = sizeof(unsigned int). I tried this bug get no results:
Quoted 8 lines
Quoted 1 line
Do you have an example of a C file on which you expect to get a match?
Sure,
ipv4_local_port_range()on the filenet/ipv4/sysctl_net_ipv4.chas an example in C code on a functoin where it uses:.maxlen = sizeof(range),
This example doesn't have fields procname and proc_handler.
I'm trying to figure out what is the goal of your first rule:
@ find_proc @
identifier ctls;
expression name;
@@
struct ctl_table ctls[] = {
{
.procname = name,
.proc_handler = proc_dointvec,
},
};
julia
Quoted 10 lines
However the typical use seems to be static definitions as part of the file, as in
kernel/sysctl.con the line after:static struct
ctl_tablekern_table[] = {An example would be on the
traceoff_on_warning. I know that's not an array but its an example to then manually inspect.Luis
Quoted 27 lines · Julia Lawall
Quoted 23 lines · Luis R. Rodriguez
Quoted 21 lines · Julia Lawall
Quoted 7 lines · Luis R. Rodriguez
I'm trying to hunt for users of the
proc_dointvec()handler in setups where more than one value is expected to be used. The way this old API works is it lets you specifiy in a structure the variables and the size of the variables. In the singular case the size will be maxlen = sizeof(int). If an array is used a user may use maxlen = 2*sizeof(int), or other things.Quoted 8 lines
Since I am looking for unsigned int users of
proc_dointvec()to later consider converting them toproc_douintvec()I can just focus for now when the is not maxlen = (unsigned int) or maxlen = sizeof(int), and then manually review the cases. Unfrotunately I cannot seem to construct grammar to query context for this.Let's consider just trying to get context for the case where the size is not maxlen = sizeof(unsigned int). I tried this bug get no results:
Do you have an example of a C file on which you expect to get a match?
Quoted 8 lines
Quoted 6 lines
Sure,
ipv4_local_port_range()on the filenet/ipv4/sysctl_net_ipv4.chas an example in C code on a functoin where it uses:.maxlen = sizeof(range),
This example doesn't have fields procname and
proc_handler.
Ah you are right, but it then goes ahead and uses it directly:
ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
So I would need to capture this use in another rule. I can do that later once I iron out the first part, which is to first hunt for non maxlen = sizeof(unsigned int).
Quoted 7 lines
I'm trying to figure out what is the goal of your first rule:
@
find_proc@
identifier ctls;
expression name;
@@
Quoted 6 lines
struct
ctl_tablectls[] = {
{
.procname = name,
.proc_handler =proc_dointvec,
},
};
I am looking for all entries which use proc_handler = proc_dointvec. The subsequent rule then rlies on the name to again check for if the maxlen with unsigned int is present. The third rule is to look for the same but where no maxelen with the unsigned int is used.
Luis
Quoted 37 lines · Luis R. Rodriguez
Quoted 27 lines · Julia Lawall
Quoted 23 lines · Luis R. Rodriguez
Quoted 21 lines · Julia Lawall
Quoted 7 lines · Luis R. Rodriguez
I'm trying to hunt for users of the
proc_dointvec()handler in setups where more than one value is expected to be used. The way this old API works is it lets you specifiy in a structure the variables and the size of the variables. In the singular case the size will be maxlen = sizeof(int). If an array is used a user may use maxlen = 2*sizeof(int), or other things.Quoted 8 lines
Since I am looking for unsigned int users of
proc_dointvec()to later consider converting them toproc_douintvec()I can just focus for now when the is not maxlen = (unsigned int) or maxlen = sizeof(int), and then manually review the cases. Unfrotunately I cannot seem to construct grammar to query context for this.Let's consider just trying to get context for the case where the size is not maxlen = sizeof(unsigned int). I tried this bug get no results:
Do you have an example of a C file on which you expect to get a match?
Quoted 8 lines
Quoted 6 lines
Sure,
ipv4_local_port_range()on the filenet/ipv4/sysctl_net_ipv4.chas an example in C code on a functoin where it uses:.maxlen = sizeof(range),
This example doesn't have fields procname and
proc_handler.
Quoted 7 lines
Ah you are right, but it then goes ahead and uses it directly:
ret =
proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);So I would need to capture this use in another rule. I can do that later once I iron out the first part, which is to first hunt for non maxlen = sizeof(unsigned int).
Do you require that there is exactly one element in the arrays?
julia
Quoted 21 lines
Quoted 7 lines
I'm trying to figure out what is the goal of your first rule:
@
find_proc@
identifier ctls;
expression name;
@@Quoted 6 lines
struct
ctl_tablectls[] = {
{
.procname = name,
.proc_handler =proc_dointvec,
},
};I am looking for all entries which use
proc_handler=proc_dointvec. The subsequent rule then rlies on the name to again check for if the maxlen with unsigned int is present. The third rule is to look for the same but where no maxelen with the unsigned int is used.Luis
Quoted 10 lines · Julia Lawall
Quoted 7 lines · Luis R. Rodriguez
Ah you are right, but it then goes ahead and uses it directly:
ret =
proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);So I would need to capture this use in another rule. I can do that later once I iron out the first part, which is to first hunt for non maxlen = sizeof(unsigned int).
Do you require that there is exactly one element in the arrays?
Well my eventual hunt is for all array users. So I'm starting off by first looking for all simple setups with non-array cases, and then giving context for those that are not singular. So eventually I will write a rule that will show the entries which do not have
(
maxelen = sizeof(int),
|
maxlen = sizeof(unsigned int).,
)
I figure this list should be small enough to inspect with one's eyeballs then.
Luis
Quoted 7 lines
Quoted 1 line
Do you require that there is exactly one element in the arrays?
Well my eventual hunt is for all array users. So I'm starting off by first looking for all simple setups with non-array cases, and then giving context for those that are not singular. So eventually I will write a rule that will show the entries which do not have
Quoted 7 lines
(
maxelen = sizeof(int),
|
maxlen = sizeof(unsigned int).,
)I figure this list should be small enough to inspect with one's eyeballs then.
These arrays seem to need something to mark the end. So you need to put {}, in each of your rules. Here is an example match:
arch/x86/entry/vdso/vdso32-setup.c
static struct ctl_table abi_table2[] = {
{
.procname = "vsyscall32",
.data = &vdso32_enabled,
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec
},
{}
};
julia
Quoted 20 lines · Julia Lawall
Quoted 7 lines
Quoted 1 line
Do you require that there is exactly one element in the arrays?
Well my eventual hunt is for all array users. So I'm starting off by first looking for all simple setups with non-array cases, and then giving context for those that are not singular. So eventually I will write a rule that will show the entries which do not have
Quoted 7 lines
(
maxelen = sizeof(int),
|
maxlen = sizeof(unsigned int).,
)I figure this list should be small enough to inspect with one's eyeballs then.
These arrays seem to need something to mark the end. So you need to put {}, in each of your rules. Here is an example match:
arch/x86/entry/vdso/vdso32-setup.c
Quoted 10 lines
static struct
ctl_tableabi_table2[] = {
{
.procname = "vsyscall32",
.data =&vdso32_enabled,
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler =proc_dointvec
},
{}
};
That fixed it, thanks!
Luis