Re: [PATCH v7] pidfd: add ioctl to retrieve pid info
From: Luca Boccassi
Date: Mon Oct 07 2024 - 09:05:54 EST
On Mon, 7 Oct 2024 at 13:27, Christian Brauner <brauner@xxxxxxxxxx> wrote:
>
> On Mon, Oct 07, 2024 at 10:43:28AM GMT, luca.boccassi@xxxxxxxxx wrote:
> > From: Luca Boccassi <luca.boccassi@xxxxxxxxx>
> > + struct pidfd_info kinfo = {};
> > + struct user_namespace *user_ns;
> > + const struct cred *c;
> > + __u64 request_mask;
> > +
> > + if (!uinfo)
> > + return -EINVAL;
> > + if (usize < sizeof(struct pidfd_info))
> > + return -EINVAL; /* First version, no smaller struct possible */
> > +
> > + if (copy_from_user(&request_mask, &uinfo->request_mask, sizeof(request_mask)))
> > + return -EFAULT;
>
> Use copy_struct_from_user() here it's not strictly needed as we
> technically don't care whether userspace passes unitialized stuff as
> this is an output-only struct right now but imho it's just good hygiene.
Here I was intentionally only copying the request_mask field, as we
really don't need the rest of the userspace struct and the mask is
fixed size, so I thought it would be simpler. Should I still change to
copy the whole thing instead?