* Re: type mismatch
2015-05-10 13:20 type mismatch Julia Lawall
@ 2015-05-10 19:57 ` Dan Carpenter
2015-05-10 20:03 ` Julia Lawall
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2015-05-10 19:57 UTC (permalink / raw)
To: kernel-janitors
I don't really have a strong opinion either way... It's unlikely that
we will introduce a bug here and if we did, I think it would be caught
immediately in testing.
It's pretty common to treat the first member of a struct as special.
What annoys me is when people do
struct foo {
int one, two, three;
whatever;
};
memcpy(&foo.one, src, sizoef(struct foo));
Argh!? These triger buffer overflows warnings in Smatch and I don't
see the point since &foo.one is less readable than &foo! Oh well, I
think these were common enough, I had to treat it as idiomatic and add a
special case for them.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: type mismatch
2015-05-10 13:20 type mismatch Julia Lawall
2015-05-10 19:57 ` Dan Carpenter
@ 2015-05-10 20:03 ` Julia Lawall
2015-05-11 7:18 ` Nicholas Mc Guire
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Julia Lawall @ 2015-05-10 20:03 UTC (permalink / raw)
To: kernel-janitors
On Sun, 10 May 2015, Dan Carpenter wrote:
> I don't really have a strong opinion either way... It's unlikely that
> we will introduce a bug here and if we did, I think it would be caught
> immediately in testing.
>
> It's pretty common to treat the first member of a struct as special.
> What annoys me is when people do
>
> struct foo {
> int one, two, three;
> whatever;
> };
>
> memcpy(&foo.one, src, sizoef(struct foo));
>
> Argh!? These triger buffer overflows warnings in Smatch and I don't
> see the point since &foo.one is less readable than &foo! Oh well, I
> think these were common enough, I had to treat it as idiomatic and add a
> special case for them.
OK, thanks.
julia
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: type mismatch
2015-05-10 13:20 type mismatch Julia Lawall
2015-05-10 19:57 ` Dan Carpenter
2015-05-10 20:03 ` Julia Lawall
@ 2015-05-11 7:18 ` Nicholas Mc Guire
2015-05-11 7:32 ` Julia Lawall
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Nicholas Mc Guire @ 2015-05-11 7:18 UTC (permalink / raw)
To: kernel-janitors
On Sun, 10 May 2015, Dan Carpenter wrote:
> I don't really have a strong opinion either way... It's unlikely that
> we will introduce a bug here and if we did, I think it would be caught
> immediately in testing.
>
> It's pretty common to treat the first member of a struct as special.
> What annoys me is when people do
>
> struct foo {
> int one, two, three;
> whatever;
> };
>
> memcpy(&foo.one, src, sizoef(struct foo));
>
> Argh!? These triger buffer overflows warnings in Smatch and I don't
> see the point since &foo.one is less readable than &foo! Oh well, I
> think these were common enough, I had to treat it as idiomatic and add a
> special case for them.
>
just ran a naive scanner for that pattern but only could find this one instance
./net/sctp/sm_make_chunk.c:3103 ugly memset
3102 if (af->is_any(&addr))
3103 memcpy(&addr.v4, sctp_source(asconf), sizeof(addr));
my scanner ist:
@uses_first@
identifier f;
idexpression s;
identifier e;
position p;
@@
f(...){
<+...
* memcpy@p(&s.e,...,sizeof(s));
...+>
}
@script:python@
p << uses_first.p;
@@
print "%s:%s ugly memset" % (p[0].file,p[0].line)
so is my scanner broken/incomplete or has this pattern lost its popularity ?
thx!
hofrat
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: type mismatch
2015-05-10 13:20 type mismatch Julia Lawall
` (2 preceding siblings ...)
2015-05-11 7:18 ` Nicholas Mc Guire
@ 2015-05-11 7:32 ` Julia Lawall
2015-05-11 8:14 ` Dan Carpenter
2015-05-11 8:29 ` Nicholas Mc Guire
5 siblings, 0 replies; 7+ messages in thread
From: Julia Lawall @ 2015-05-11 7:32 UTC (permalink / raw)
To: kernel-janitors
On Mon, 11 May 2015, Nicholas Mc Guire wrote:
> On Sun, 10 May 2015, Dan Carpenter wrote:
>
> > I don't really have a strong opinion either way... It's unlikely that
> > we will introduce a bug here and if we did, I think it would be caught
> > immediately in testing.
> >
> > It's pretty common to treat the first member of a struct as special.
> > What annoys me is when people do
> >
> > struct foo {
> > int one, two, three;
> > whatever;
> > };
> >
> > memcpy(&foo.one, src, sizoef(struct foo));
> >
> > Argh!? These triger buffer overflows warnings in Smatch and I don't
> > see the point since &foo.one is less readable than &foo! Oh well, I
> > think these were common enough, I had to treat it as idiomatic and add a
> > special case for them.
> >
> just ran a naive scanner for that pattern but only could find this one instance
>
> ./net/sctp/sm_make_chunk.c:3103 ugly memset
> 3102 if (af->is_any(&addr))
> 3103 memcpy(&addr.v4, sctp_source(asconf), sizeof(addr));
>
> my scanner ist:
>
> @uses_first@
> identifier f;
> idexpression s;
Maybe generalize s (ie expression) and the size (ie, don't specify
anything)? The sizeof could be a type also.
julia
> identifier e;
> position p;
> @@
>
> f(...){
> <+...
> * memcpy@p(&s.e,...,sizeof(s));
> ...+>
> }
>
> @script:python@
> p << uses_first.p;
> @@
> print "%s:%s ugly memset" % (p[0].file,p[0].line)
>
> so is my scanner broken/incomplete or has this pattern lost its popularity ?
>
> thx!
> hofrat
>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: type mismatch
2015-05-10 13:20 type mismatch Julia Lawall
` (3 preceding siblings ...)
2015-05-11 7:32 ` Julia Lawall
@ 2015-05-11 8:14 ` Dan Carpenter
2015-05-11 8:29 ` Nicholas Mc Guire
5 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2015-05-11 8:14 UTC (permalink / raw)
To: kernel-janitors
Hm... You're right. I'm going to retract some things.
1) I didn't end up adding a special case handling for this, I only
wanted to but never got around to it.
2) Also these aren't *that* common as I was thinking. They're mostly
limitted to emulex.
drivers/net/ethernet/emulex/benet/be_cmds.c
3173
3174 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
^^^^^^^^^
First element.
3175 OPCODE_COMMON_SET_HSW_CONFIG, sizeof(*req), wrb,
^^^^^^^^^^^^
Here is the sizeof().
3176 NULL);
3177
3) It's also obvious why emulex would do this because the req struct
could be defined a lot of different ways so long as the first element
is a header. It's like a union.
Sorry for the misinformation. My bad.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: type mismatch
2015-05-10 13:20 type mismatch Julia Lawall
` (4 preceding siblings ...)
2015-05-11 8:14 ` Dan Carpenter
@ 2015-05-11 8:29 ` Nicholas Mc Guire
5 siblings, 0 replies; 7+ messages in thread
From: Nicholas Mc Guire @ 2015-05-11 8:29 UTC (permalink / raw)
To: kernel-janitors
On Mon, 11 May 2015, Julia Lawall wrote:
>
>
> On Mon, 11 May 2015, Nicholas Mc Guire wrote:
>
> > On Sun, 10 May 2015, Dan Carpenter wrote:
> >
> > > I don't really have a strong opinion either way... It's unlikely that
> > > we will introduce a bug here and if we did, I think it would be caught
> > > immediately in testing.
> > >
> > > It's pretty common to treat the first member of a struct as special.
> > > What annoys me is when people do
> > >
> > > struct foo {
> > > int one, two, three;
> > > whatever;
> > > };
> > >
> > > memcpy(&foo.one, src, sizoef(struct foo));
> > >
> > > Argh!? These triger buffer overflows warnings in Smatch and I don't
> > > see the point since &foo.one is less readable than &foo! Oh well, I
> > > think these were common enough, I had to treat it as idiomatic and add a
> > > special case for them.
> > >
> > just ran a naive scanner for that pattern but only could find this one instance
> >
> > ./net/sctp/sm_make_chunk.c:3103 ugly memset
> > 3102 if (af->is_any(&addr))
> > 3103 memcpy(&addr.v4, sctp_source(asconf), sizeof(addr));
> >
> > my scanner ist:
> >
> > @uses_first@
> > identifier f;
> > idexpression s;
>
> Maybe generalize s (ie expression) and the size (ie, don't specify
> anything)? The sizeof could be a type also.
>
yup - adding the type check case finds two additional cases
but generalizing s to an expression did not change results
@uses_first@
identifier f;
type T;
idexpression T s;
identifier e;
position p;
@@
f(...){
<+...
(
* memcpy@p(&s.e,...,sizeof(s));
|
* memcpy@p(&s.e,...,sizeof(T));
)
...+>
}
./drivers/infiniband/hw/ehca/ehca_mcast.c:80 ugly memset
./drivers/infiniband/hw/ehca/ehca_mcast.c:117 ugly memset
./net/sctp/sm_make_chunk.c:3103 ugly memset
thx!
hofrat
^ permalink raw reply [flat|nested] 7+ messages in thread