Re: [patch 4/4] prctl: PR_SET_MM -- Introduce PR_SET_MM_MAP operation, v3

From: Andrew Morton
Date: Fri Aug 22 2014 - 02:49:32 EST


On Fri, 22 Aug 2014 10:32:42 +0400 Cyrill Gorcunov <gorcunov@xxxxxxxxx> wrote:

> > > + error |= __prctl_check_addr_space(start_code);
> > > + error |= __prctl_check_addr_space(end_code);
> > > + error |= __prctl_check_addr_space(start_data);
> > > + error |= __prctl_check_addr_space(end_data);
> > > + error |= __prctl_check_addr_space(start_stack);
> > > + error |= __prctl_check_addr_space(start_brk);
> > > + error |= __prctl_check_addr_space(brk);
> > > + error |= __prctl_check_addr_space(arg_start);
> > > + error |= __prctl_check_addr_space(arg_end);
> > > + error |= __prctl_check_addr_space(env_start);
> > > + error |= __prctl_check_addr_space(env_end);
> >
> > Boy this is verbose. I had a little fiddle and came up with
> ...
> >
> > +
> > + for (i = 0; i < ARRAY_SIZE(offsets); i++) {
> > + u64 val = ((u64 *)prctl_map)[offsets[i]];
> > +
> > + if (val < mmap_min_addr || val >= mmap_max_addr) {
> > + error = -EINVAL;
> > + goto out;
> > + }
> > + }
> > + }
> >
> > and it saved 400 bytes of text.
> >
> > But it's a bit hacky. Can anyone think of anything smarter?
>
> Looks good to me and not that hacky actually.

Hacky :( I guess it's pretty safe because this is a userspace-visible
structure so we'll never be changing it.

Or will we? What happens if we later decide that some additional field
needs to be added? Do we version the interface? Add a new prctl()
mode? Let's cook up a plan for that and at least add to changelog?

> Should I update on top for -mm tree?

Spose so. Let's see what the code savings are when the other two sites
are similarly changed?

To save a bit more space offsets[] could be an array of uchar, I guess.
A BUILD_BUG_ON(sizeof(struct prctl_map) >= 256) would keep that sane.

--
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/