Re: [PATCH] inotify: Ensure we alwasy write the terminating NULL.

From: Eric Paris
Date: Fri Aug 28 2009 - 10:19:02 EST


On Fri, 2009-08-28 at 06:29 -0700, Brian Rogers wrote:
> Eric W. Biederman wrote:
> > Before the rewrite copy_event_to_user always wrote a terqminating '\0'
> > byte to user space after the filename. Since the rewrite that
> > terminating byte was skipped if your filename is exactly a multiple of
> > event_size. Ouch!
> >
> > So add one byte to name_size before we round up and use clear_user to
> > set userspace to zero like /dev/zero does instead of copying the
> > strange nul_inotify_event. I can't quite convince myself len_to_zero
> > will never exceed 16 and even if it doesn't clear_user should be more
> > efficient and a more accurate reflection of what the code is trying to
> > do.
> >
> > Signed-off-by: Eric W. Biederman <ebiederm@xxxxxxxxxxxxxxxxxx>
> >
>
> I found that this change prevents my Ubuntu Karmic system from booting.
> It just idles forever very early in the process. Probably a boot script
> is waiting for an event that it doesn't receive properly.
>
> > - name_len = roundup(event->name_len, event_size);
> > + name_len = roundup(event->name_len + 1, event_size);
> >
>
> This means the test later on will now always evaluate to true:
> > if (name_len) {
>
> And in cases where that test previously would have failed, the code now
> outputs a block full of zeros. Assuming that's bad and the test was
> important, I coded the attached naive fix, which is working for me.

Thanks, I ask Linus to pull a (slightly modified) version. Don't know
if he'll get it before he runs out on vacation. Here's hoping.

-Eric

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/