From: Hans Verkuil <hverkuil@xs4all.nl>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
Linux Media Mailing List <linux-media@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
y2038 Mailman List <y2038@lists.linaro.org>
Subject: Re: [PATCH v4 5/8] media: v4l2-core: fix VIDIOC_DQEVENT for time64 ABI
Date: Tue, 26 Nov 2019 16:10:31 +0100 [thread overview]
Message-ID: <15a1a26c-b3ad-7449-4508-1207527ab21f@xs4all.nl> (raw)
In-Reply-To: <CAK8P3a3vHWBJU6EiUbRKJ01Zsv5E5Yfr+=h2Dg95atjvaHZ+Rg@mail.gmail.com>
On 11/26/19 3:43 PM, Arnd Bergmann wrote:
> On Mon, Nov 25, 2019 at 3:40 PM Hans Verkuil <hverkuil@xs4all.nl> wrote:
>> On 11/11/19 9:38 PM, Arnd Bergmann wrote:
>
>>> switch (cmd) {
>>> +#ifdef CONFIG_COMPAT_32BIT_TIME
>>> + case VIDIOC_DQEVENT_TIME32: {
>>> + struct v4l2_event_time32 ev32;
>>> + struct v4l2_event *ev = parg;
>>> +
>>> + memcpy(&ev32, ev, offsetof(struct v4l2_event, timestamp));
>>> + ev32.timestamp.tv_sec = ev->timestamp.tv_sec;
>>> + ev32.timestamp.tv_nsec = ev->timestamp.tv_nsec;
>>> + memcpy(&ev32.id, &ev->id, sizeof(*ev) - offsetof(struct v4l2_event, id));
>>
>> This looks dangerous: due to 64-bit alignment requirements the
>> v4l2_event struct may end with a 4-byte hole at the end of the struct,
>> which you do not want to copy to ev32.
>>
>> I think it is safer to just copy id and reserved separately:
>>
>> ev32.id = ev->id;
>> memcpy(ev32.reserved, ev->reserved, sizeof(ev->reserved));
>
> Actually I think it's that's also bad: The padding in *ev must already be
> cleared here (otherwise there is a leak of stack data in the kernel
> already), so *not* copying the padding requires at least adding a memset
> upfront.
>
> I would do the per-member copy like I did for v4l2_buffer in my
> other reply:
>
> struct v4l2_event *ev = parg;
> struct v4l2_event_time32 ev32 = {
> .type = ev->type,
> .pending = ev->pending,
> .sequence = ev->sequence,
> .timestamp.tv_sec = ev->timestamp.tv_sec,
> .timestamp.tv_nsec = ev->timestamp.tv_nsec,
> .id = ev->id,
> };
>
> memcpy(ev32.u, ev->u, sizeof(ev->u));
> memcpy(ev32.reserved, ev->reserved, sizeof(ev->reserved));
>
> if (copy_to_user(arg, &ev32, sizeof(ev32)))
> return -EFAULT;
>
> Unfortunately this is a little uglier because it still requires the two
> memcpy() for the arrays, but I think it's good enough.
I agree.
Hmm, can't you do .u = ev->u ? Or is that not allowed by this syntax?
>
> Any other ideas? Let me know if I should do a memset()
> plus individual member copy instead.
I think we have to, unless you have a better solution. This is leaking
information from the holes in the struct.
>>> + if (!(sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS))
>>> + return -ENOIOCTLCMD;
>>> +
>>> + rval = v4l2_event_dequeue(vfh, &ev, file->f_flags & O_NONBLOCK);
>>> +
>>> + memcpy(ev32, &ev, offsetof(struct v4l2_event, timestamp));
>>> + ev32->timestamp.tv_sec = ev.timestamp.tv_sec;
>>> + ev32->timestamp.tv_nsec = ev.timestamp.tv_nsec;
>>> + memcpy(&ev32->id, &ev.id,
>>> + sizeof(ev) - offsetof(struct v4l2_event, id));
>>
>> Ditto.
>
> Using the corresponding code here as well.
>
>>> +
>>> #define V4L2_EVENT_SUB_FL_SEND_INITIAL (1 << 0)
>>> #define V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK (1 << 1)
>>>
>>> @@ -2486,6 +2515,7 @@ struct v4l2_create_buffers {
>>> #define VIDIOC_S_DV_TIMINGS _IOWR('V', 87, struct v4l2_dv_timings)
>>> #define VIDIOC_G_DV_TIMINGS _IOWR('V', 88, struct v4l2_dv_timings)
>>> #define VIDIOC_DQEVENT _IOR('V', 89, struct v4l2_event)
>>> +#define VIDIOC_DQEVENT_TIME32 _IOR('V', 89, struct v4l2_event_time32)
>>
>> Shouldn't this be under #ifdef __KERNEL__?
>>
>> And should this be in the public header at all? media/v4l2-ioctl.h might be a better
>> place.
>
> Done.
>
> Arnd
>
Regards,
Hans
next prev parent reply other threads:[~2019-11-26 15:10 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-11 20:38 [PATCH v4 0/8] y2038 safety in v4l2 Arnd Bergmann
2019-11-11 20:38 ` [PATCH v4 1/8] media: documentation: fix video_event description Arnd Bergmann
2019-11-11 20:38 ` [PATCH v4 2/8] media: v4l2: abstract timeval handling in v4l2_buffer Arnd Bergmann
2019-11-25 15:52 ` Hans Verkuil
2019-11-26 11:34 ` Arnd Bergmann
2019-11-26 11:43 ` Hans Verkuil
2019-11-26 12:42 ` Arnd Bergmann
2019-11-11 20:38 ` [PATCH v4 3/8] media: v4l2-core: compat: ignore native command codes Arnd Bergmann
2019-11-11 20:38 ` [PATCH v4 4/8] media: v4l2-core: split out data copy from video_usercopy Arnd Bergmann
2019-11-11 20:38 ` [PATCH v4 5/8] media: v4l2-core: fix VIDIOC_DQEVENT for time64 ABI Arnd Bergmann
2019-11-25 14:40 ` Hans Verkuil
2019-11-26 14:43 ` Arnd Bergmann
2019-11-26 15:10 ` Hans Verkuil [this message]
2019-11-26 15:19 ` Arnd Bergmann
2019-11-11 20:38 ` [PATCH v4 6/8] media: v4l2-core: fix v4l2_buffer handling " Arnd Bergmann
2019-11-25 14:57 ` Hans Verkuil
2019-11-26 13:50 ` Arnd Bergmann
2019-11-26 14:15 ` Hans Verkuil
2019-11-26 15:17 ` Arnd Bergmann
2019-11-26 15:24 ` Hans Verkuil
2019-11-11 20:38 ` [PATCH v4 7/8] media: v4l2-core: fix compat VIDIOC_DQEVENT " Arnd Bergmann
2019-11-11 20:38 ` [PATCH v4 8/8] media: v4l2-core: fix compat v4l2_buffer handling " Arnd Bergmann
2019-11-25 16:02 ` [PATCH v4 0/8] y2038 safety in v4l2 Hans Verkuil
2019-11-26 11:13 ` Arnd Bergmann
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=15a1a26c-b3ad-7449-4508-1207527ab21f@xs4all.nl \
--to=hverkuil@xs4all.nl \
--cc=arnd@arndb.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=y2038@lists.linaro.org \
/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;
as well as URLs for NNTP newsgroup(s).