From: Jonathan Corbet <corbet@lwn.net>
To: luca.boccassi@gmail.com, linux-fsdevel@vger.kernel.org
Cc: christian@brauner.io, linux-kernel@vger.kernel.org, oleg@redhat.com
Subject: Re: [PATCH v9] pidfd: add ioctl to retrieve pid info
Date: Wed, 09 Oct 2024 13:20:28 -0600 [thread overview]
Message-ID: <87msjd9j7n.fsf@trenco.lwn.net> (raw)
In-Reply-To: <20241008121930.869054-1-luca.boccassi@gmail.com>
luca.boccassi@gmail.com writes:
> As discussed at LPC24, add an ioctl with an extensible struct
> so that more parameters can be added later if needed. Start with
> returning pid/tgid/ppid and creds unconditionally, and cgroupid
> optionally.
I was looking this over, and a couple of questions came to mind...
> Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com>
> ---
[...]
> diff --git a/fs/pidfs.c b/fs/pidfs.c
> index 80675b6bf884..15cdc7fe4968 100644
> --- a/fs/pidfs.c
> +++ b/fs/pidfs.c
> @@ -2,6 +2,7 @@
> #include <linux/anon_inodes.h>
> #include <linux/file.h>
> #include <linux/fs.h>
> +#include <linux/cgroup.h>
> #include <linux/magic.h>
> #include <linux/mount.h>
> #include <linux/pid.h>
> @@ -114,6 +115,83 @@ static __poll_t pidfd_poll(struct file *file, struct poll_table_struct *pts)
> return poll_flags;
> }
>
> +static long pidfd_info(struct task_struct *task, unsigned int cmd, unsigned long arg)
> +{
> + struct pidfd_info __user *uinfo = (struct pidfd_info __user *)arg;
> + size_t usize = _IOC_SIZE(cmd);
> + 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;
You don't check request_mask for unrecognized flags, so user space will
not get an error if it puts random gunk there. That, in turn, can make
it harder to add new options in the future.
> + c = get_task_cred(task);
> + if (!c)
> + return -ESRCH;
[...]
> +
> + /*
> + * If userspace and the kernel have the same struct size it can just
> + * be copied. If userspace provides an older struct, only the bits that
> + * userspace knows about will be copied. If userspace provides a new
> + * struct, only the bits that the kernel knows about will be copied and
> + * the size value will be set to the size the kernel knows about.
> + */
> + if (copy_to_user(uinfo, &kinfo, min(usize, sizeof(kinfo))))
> + return -EFAULT;
Which "size value" are you referring to here; I can't see it.
If user space has a bigger struct, should you perhaps zero-fill the part
the kernel doesn't know about?
> + return 0;
> +}
Thanks,
jon
next prev parent reply other threads:[~2024-10-09 19:20 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-08 12:18 luca.boccassi
2024-10-08 13:06 ` Christian Brauner
2024-10-08 13:10 ` Luca Boccassi
2024-10-09 20:52 ` Aleksa Sarai
2024-10-10 9:38 ` Christian Brauner
2024-10-08 13:23 ` Christian Brauner
2024-10-09 19:20 ` Jonathan Corbet [this message]
2024-10-09 20:56 ` Aleksa Sarai
2024-10-09 21:06 ` Aleksa Sarai
2024-10-09 22:05 ` Jonathan Corbet
2024-10-13 5:57 ` Aleksa Sarai
2024-10-10 9:36 ` Christian Brauner
2024-10-10 12:41 ` Jonathan Corbet
2024-10-10 13:16 ` David Laight
2024-10-10 9:26 ` Christian Brauner
2024-10-09 20:50 ` Aleksa Sarai
2024-10-10 9:46 ` Christian Brauner
2024-10-10 15:55 ` Luca Boccassi
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=87msjd9j7n.fsf@trenco.lwn.net \
--to=corbet@lwn.net \
--cc=christian@brauner.io \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luca.boccassi@gmail.com \
--cc=oleg@redhat.com \
/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
all inboxes | Powered by JetHome®