Re: [PATCH] fadvise: avoid EINVAL if user input is valid

From: Eric Wong
Date: Sun Feb 26 2012 - 03:44:41 EST


Hillf Danton <dhillf@xxxxxxxxx> wrote:
> On Sat, Feb 25, 2012 at 10:27 AM, Eric Wong <normalperson@xxxxxxxx> wrote:
> > index 469491e0..f9e48dd 100644
> > --- a/mm/fadvise.c
> > +++ b/mm/fadvise.c
> > @@ -43,13 +43,13 @@ SYSCALL_DEFINE(fadvise64_64)(int fd, loff_t offset, loff_t len, int advice)
> > Â Â Â Â Â Â Â Âgoto out;
> > Â Â Â Â}
> >
> > - Â Â Â mapping = file->f_mapping;
> > - Â Â Â if (!mapping || len < 0) {
> > + Â Â Â if (len < 0) {
>
> Current code makes sure mapping is valid after the above check,

Right. I moved the !mapping check down a few lines.

> > Â Â Â Â Â Â Â Âret = -EINVAL;
> > Â Â Â Â Â Â Â Âgoto out;
> > Â Â Â Â}

Now the check hits the "goto out" the get_xip_mem check hits:

> > - Â Â Â if (mapping->a_ops->get_xip_mem) {
> > + Â Â Â mapping = file->f_mapping;
> > + Â Â Â if (!mapping || mapping->a_ops->get_xip_mem) {
> > Â Â Â Â Â Â Â Âswitch (advice) {
> > Â Â Â Â Â Â Â Âcase POSIX_FADV_NORMAL:
> > Â Â Â Â Â Â Â Âcase POSIX_FADV_RANDOM:

case POSIX_FADV_SEQUENTIAL:
case POSIX_FADV_WILLNEED:
case POSIX_FADV_NOREUSE:
case POSIX_FADV_DONTNEED:
/* no bad return value, but ignore advice */
break;
default:
ret = -EINVAL;
}
goto out; <------ we hit this if (mapping == NULL)
}

> but backing devices info is no longer evaluated with that
> guarantee in your change.
>
> -hd
>
> 75: bdi = mapping->backing_dev_info;

The above line still doesn't evaluated because of the goto.

out:
fput(file);
return ret;
}
--
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/