From: Arnd Bergmann <arnd@arndb.de>
To: Sargun Dhillon <sargun@sargun.me>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Linux Containers <containers@lists.linux-foundation.org>,
Linux API <linux-api@vger.kernel.org>,
Linux FS-devel Mailing List <linux-fsdevel@vger.kernel.org>,
Tycho Andersen <tycho@tycho.ws>, Jann Horn <jannh@google.com>,
Aleksa Sarai <cyphar@cyphar.com>,
Christian Brauner <christian.brauner@ubuntu.com>,
Oleg Nesterov <oleg@redhat.com>,
Andy Lutomirski <luto@amacapital.net>,
Al Viro <viro@zeniv.linux.org.uk>,
gpascutto@mozilla.com, ealvarez@mozilla.com,
Florian Weimer <fweimer@redhat.com>,
jld@mozilla.com
Subject: Re: [PATCH v4 2/5] pid: Add PIDFD_IOCTL_GETFD to fetch file descriptors from processes
Date: Thu, 19 Dec 2019 09:03:09 +0100 [thread overview]
Message-ID: <CAK8P3a2eT=bHkUamyp-P3Y2adNq1KBk7UknCYBY5_aR4zJmYaQ@mail.gmail.com> (raw)
In-Reply-To: <20191218235459.GA17271@ircssh-2.c.rugged-nimbus-611.internal>
On Thu, Dec 19, 2019 at 12:55 AM Sargun Dhillon <sargun@sargun.me> wrote:
> +#define PIDFD_IOCTL_GETFD _IOWR('p', 0xb0, __u32)
This describes an ioctl command that reads and writes a __u32 variable
using a pointer passed as the argument, which doesn't match the
implementation:
> +static long pidfd_getfd(struct pid *pid, u32 fd)
> +{
...
> + return retfd;
This function passes an fd as the argument and returns a new
fd, so the command number would be
#define PIDFD_IOCTL_GETFD _IO('p', 0xb0)
While this implementation looks easy enough, and it is roughly what
I would do in case of a system call, I would recommend for an ioctl
implementation to use the __u32 pointer instead:
static long pidfd_getfd_ioctl(struct pid *pid, u32 __user *arg)
{
int their_fd, new_fd;
int ret;
ret = get_user(their_fd, arg);
if (ret)
return ret;
new_fd = pidfd_getfd(pid, their_fd);
if (new_fd < 0)
return new_fd;
return put_user(new_fd, arg);
}
Direct argument passing in ioctls may confuse readers because it
is fairly unusual, and it doesn't work with this:
> const struct file_operations pidfd_fops = {
> .release = pidfd_release,
> .poll = pidfd_poll,
> + .unlocked_ioctl = pidfd_ioctl,
> + .compat_ioctl = compat_ptr_ioctl,
compat_ptr_ioctl() only works if the argument is a pointer, as it
mangles the argument to turn it from a 32-bit pointer value into
a 64-bit pointer value. These are almost always the same
(arch/s390 being the sole exception), but you should not rely
on it. For now it would be find to do '.compat_ioctl = pidfd_ioctl',
but that in turn is wrong if you ever add another ioctl command
that does pass a pointer.
Arnd
next prev parent reply other threads:[~2019-12-19 8:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-18 23:55 [PATCH v4 2/5] pid: Add PIDFD_IOCTL_GETFD to fetch file descriptors from processes Sargun Dhillon
2019-12-19 8:03 ` Arnd Bergmann [this message]
2019-12-19 10:35 ` Christian Brauner
2019-12-19 11:31 ` Arnd Bergmann
2019-12-19 16:15 ` Sargun Dhillon
2019-12-20 4:35 ` Aleksa Sarai
2019-12-21 13:53 ` Arnd Bergmann
2019-12-19 10:23 ` Christian Brauner
2019-12-20 1:43 ` Andy Lutomirski
2019-12-20 5:21 ` Sargun Dhillon
2019-12-20 9:20 ` Christian Brauner
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='CAK8P3a2eT=bHkUamyp-P3Y2adNq1KBk7UknCYBY5_aR4zJmYaQ@mail.gmail.com' \
--to=arnd@arndb.de \
--cc=christian.brauner@ubuntu.com \
--cc=containers@lists.linux-foundation.org \
--cc=cyphar@cyphar.com \
--cc=ealvarez@mozilla.com \
--cc=fweimer@redhat.com \
--cc=gpascutto@mozilla.com \
--cc=jannh@google.com \
--cc=jld@mozilla.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=oleg@redhat.com \
--cc=sargun@sargun.me \
--cc=tycho@tycho.ws \
--cc=viro@zeniv.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).