From: JiSheng Zhang <jszhang3@mail.ustc.edu.cn>
To: Mikael Pettersson <mikpe@it.uu.se>
Cc: stefanr@s5r6.in-berlin.de, linux-kernel@vger.kernel.org,
linux1394-devel@lists.sourceforge.net, krh@bitplanet.net
Subject: Re: PATCH] firewire: add padding to some struct
Date: Mon, 21 Jul 2008 15:37:57 +0800 [thread overview]
Message-ID: <416625990.17901@ustc.edu.cn> (raw)
Message-ID: <20080721153757.460c6a48@debian> (raw)
In-Reply-To: <416625421.30590@ustc.edu.cn>
On Sat, 19 Jul 2008 12:09:18 +0200
Mikael Pettersson <mikpe@it.uu.se> wrote:
> JiSheng Zhang writes:
> > On Fri, 18 Jul 2008 17:27:44 +0200
> > Mikael Pettersson <mikpe@it.uu.se> wrote:
> >
> > > JiSheng Zhang writes:
> > > > Hi,
> > > > >From: Stefan Richter <stefanr@s5r6.in-berlin.de>
> > > > >Reply-To:
> > > > >To: JiSheng Zhang <jszhang3@mail.ustc.edu.cn>
> > > > >Subject: Re: PATCH] firewire: add padding to some struct
> > > > >Date:Fri, 18 Jul 2008 13:38:25 +0200
> > > > >
> > > > >JiSheng Zhang wrote:
> > > > > > If p is a pointer to struct fw_cdev_event_response), p->data will point to
> > > > the
> > > > > > padding data rather than the right place, it will cause problem under some
> > >
> > > Define "the right place". If p->data[] isn't the place for the data,
> > > then something's seriously wrong with either the producer or the
> > > consumer of that data -- or the data type definition if either is HW.
> > >
> > > > > > platforms. For example, in the function handle_device_event of
> > > > libraw1394(ported
> > > > > > to juju stack):
> > > > > > .....
> > > > > > case FW_CDEV_EVENT_RESPONSE:
> > > > > > rc = u64_to_ptr(u->response.closure);
> > > > > > if (rc->data != NULL)
> > > > > > memcpy(rc->data, u->response.data, rc->length);//here it will lost the last
> > > > four
> > > > > > bytes
> > > > > > errcode = juju_to_raw1394_errcode(u->response.rcode);
> > > > > > .....
> > > > > >
> > > > > > Although this problem can be solved by add the offset to the pointer, but the
> > > > > > member:__u32 data[0] lost its original meaning.
> > > > >
> > > > > I don't understand what the problem is. As long as both kernel and
> > > > > library use "response.data" or "&response + offsetof(typeof(response),
> > > > > data)", they will write and read at the correct location.
> > > > >
> > > > This patch can fix the problem while not changing the struct definition.
> > > >
> > > >
> > > > Thanks in advance,
> > > > JiSheng
> > > >
> > > > --- old/drivers/firewire/fw-cdev.c 2008-07-14 05:51:29.000000000 +0800
> > > > +++ new/drivers/firewire/fw-cdev.c 2008-07-18 20:20:45.841328585 +0800
> > > > @@ -382,9 +382,9 @@
> > > >
> > > > response->response.type = FW_CDEV_EVENT_RESPONSE;
> > > > response->response.rcode = rcode;
> > > > - queue_event(client, &response->event,
> > > > - &response->response, sizeof(response->response),
> > > > - response->response.data, response->response.length);
> > > > + queue_event(client, &response->event, &response->response,
> > > > + sizeof(response->response) + response->response.length,
> > > > + NULL, 0);
> > > > }
> > >
> > > Neither of these look correct.
> > > If sizeof(struct ...) != offsetof(struct ..., data) as you claim is possible,
> > > then the old code will copy too much to/from ->response but the correct amount
> > > to/from ->response.data, and the new code will copy too much to/from ->response.data.
> > The old code will copy 4 extra bytes totally on some platforms, the new code
> > is correct.
> The new code is only correct if the variable length payload starts
> after the struct, i.e. (void*)(&response->response + 1), and not at
> the data field, i.e. (void*)response->response.data.
> Which is it? That's why I asked:
Yes, the payload starts at the data field(including the padding bytes). But
there is no problem, "As long as both kernel and library use response.data"
as Stefan said.
>
> > > Define "the right place". If p->data[] isn't the place for the data,
> > > then something's seriously wrong with either the producer or the
> > > consumer of that data -- or the data type definition if either is HW.
next prev parent reply other threads:[~2008-07-21 7:39 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-18 12:31 JiSheng Zhang
2008-07-18 15:27 ` Mikael Pettersson
[not found] ` <416443505.10974@ustc.edu.cn>
[not found] ` <20080719154115.21334197.jszhang3@mail.ustc.edu.cn>
2008-07-19 7:41 ` JiSheng Zhang
2008-07-19 10:32 ` Stefan Richter
[not found] ` <416463624.22263@ustc.edu.cn>
[not found] ` <20080720142027.772e5d03@debian>
2008-07-20 6:20 ` JiSheng Zhang
2008-07-19 10:09 ` Mikael Pettersson
[not found] ` <416625421.30590@ustc.edu.cn>
[not found] ` <20080721153757.460c6a48@debian>
2008-07-21 7:37 ` JiSheng Zhang [this message]
-- strict thread matches above, loose matches on Subject: below --
2008-07-18 12:07 JiSheng Zhang
2008-07-18 11:16 JiSheng Zhang
2008-07-18 11:38 ` Stefan Richter
2008-07-18 11:58 ` Stefan Richter
2008-07-18 8:58 JiSheng Zhang
2008-07-18 10:49 ` Stefan Richter
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=416625990.17901@ustc.edu.cn \
--to=jszhang3@mail.ustc.edu.cn \
--cc=krh@bitplanet.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux1394-devel@lists.sourceforge.net \
--cc=mikpe@it.uu.se \
--cc=stefanr@s5r6.in-berlin.de \
/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
Powered by JetHome