From: Laurent Vivier <laurent@vivier.eu>
To: Shu-Chun Weng <scw@google.com>
Cc: Josh Kunz <jkz@google.com>, riku.voipio@iki.fi, qemu-devel@nongnu.org
Subject: Re: [PATCH v2] linux-user: Add most IFTUN ioctls
Date: Sat, 26 Sep 2020 18:44:12 +0200 [thread overview]
Message-ID: <5f73f9b9-53dd-b483-4eed-07ab9d660ed1@vivier.eu> (raw)
In-Reply-To: <20200723231020.769893-1-scw@google.com>
Le 24/07/2020 à 01:10, Shu-Chun Weng a écrit :
> The three options handling `struct sock_fprog` (TUNATTACHFILTER,
> TUNDETACHFILTER, and TUNGETFILTER) are not implemented. Linux kernel
> keeps a user space pointer in them which we cannot correctly handle.
>
> Signed-off-by: Josh Kunz <jkz@google.com>
> Signed-off-by: Shu-Chun Weng <scw@google.com>
> ---
> v2:
> Title changed from "linux-user: Add several IFTUN ioctls"
>
> Properly specify the argument types for various options, including a custom
> implementation for TUNSETTXFILTER.
>
> #ifdef guards for macros introduced up to 5 years ago.
>
> linux-user/ioctls.h | 45 +++++++++++++++++++++++++++++++++++++++
> linux-user/syscall.c | 36 +++++++++++++++++++++++++++++++
> linux-user/syscall_defs.h | 32 ++++++++++++++++++++++++++++
> 3 files changed, 113 insertions(+)
>
> diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
> index 0713ae1311..b9fb01f558 100644
> --- a/linux-user/ioctls.h
> +++ b/linux-user/ioctls.h
> @@ -593,3 +593,48 @@
> IOCTL(KCOV_DISABLE, 0, TYPE_NULL)
> IOCTL(KCOV_INIT_TRACE, IOC_R, TYPE_ULONG)
> #endif
> +
> + IOCTL(TUNSETDEBUG, IOC_W, TYPE_INT)
> + IOCTL(TUNSETIFF, IOC_RW, MK_PTR(MK_STRUCT(STRUCT_short_ifreq)))
Why is this IOC_RW?
> + IOCTL(TUNSETPERSIST, IOC_W, TYPE_INT)
> + IOCTL(TUNSETOWNER, IOC_W, TYPE_INT)
> + IOCTL(TUNSETLINK, IOC_W, TYPE_INT)
> + IOCTL(TUNSETGROUP, IOC_W, TYPE_INT)
> + IOCTL(TUNGETFEATURES, IOC_R, MK_PTR(TYPE_INT))
> + IOCTL(TUNSETOFFLOAD, IOC_W, TYPE_LONG)
Why is this long?
> + IOCTL_SPECIAL(TUNSETTXFILTER, IOC_W, do_ioctl_TUNSETTXFILTER,
> + /*
> + * We can't represent `struct tun_filter` in thunk so leaving
> + * this empty. do_ioctl_TUNSETTXFILTER will do the conversion.
> + */
> + TYPE_NULL)
You should use TYPE_PTRVOID to allow QEMU_STRACE to display the pointer.
Or implement the function to dump the structure (see STRUCT_termios and
struct_termios_def).
> + IOCTL(TUNGETIFF, IOC_R, MK_PTR(MK_STRUCT(STRUCT_short_ifreq)))
> + IOCTL(TUNGETSNDBUF, IOC_R, MK_PTR(TYPE_INT))
> + IOCTL(TUNSETSNDBUF, IOC_W, MK_PTR(TYPE_INT))
> + /*
> + * TUNATTACHFILTER and TUNDETACHFILTER are not supported. Linux kernel keeps a
> + * user pointer in TUNATTACHFILTER, which we are not able to correctly handle.
> + */
> + IOCTL(TUNGETVNETHDRSZ, IOC_R, MK_PTR(TYPE_INT))
> + IOCTL(TUNSETVNETHDRSZ, IOC_W, MK_PTR(TYPE_INT))
> + IOCTL(TUNSETQUEUE, IOC_W, MK_PTR(MK_STRUCT(STRUCT_short_ifreq)))
> + IOCTL(TUNSETIFINDEX , IOC_W, MK_PTR(TYPE_INT))
> + /* TUNGETFILTER is not supported: see TUNATTACHFILTER. */
> + IOCTL(TUNSETVNETLE, IOC_W, MK_PTR(TYPE_INT))
> + IOCTL(TUNGETVNETLE, IOC_R, MK_PTR(TYPE_INT))
> +#ifdef TUNSETVNETBE
> + IOCTL(TUNSETVNETBE, IOC_W, MK_PTR(TYPE_INT))
> + IOCTL(TUNGETVNETBE, IOC_R, MK_PTR(TYPE_INT))
> +#endif
> +#ifdef TUNSETSTEERINGEBPF
> + IOCTL(TUNSETSTEERINGEBPF, IOC_W, MK_PTR(TYPE_INT))
> +#endif
> +#ifdef TUNSETFILTEREBPF
> + IOCTL(TUNSETFILTEREBPF, IOC_W, MK_PTR(TYPE_INT))
> +#endif
> +#ifdef TUNSETCARRIER
> + IOCTL(TUNSETCARRIER, IOC_W, MK_PTR(TYPE_INT))
> +#endif
> +#ifdef TUNGETDEVNETNS
> + IOCTL(TUNGETDEVNETNS, IOC_R, TYPE_NULL)
> +#endif
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 1211e759c2..7f1efed189 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -56,6 +56,7 @@
> #include <linux/wireless.h>
> #include <linux/icmp.h>
> #include <linux/icmpv6.h>
> +#include <linux/if_tun.h>
> #include <linux/errqueue.h>
> #include <linux/random.h>
> #ifdef CONFIG_TIMERFD
> @@ -5422,6 +5423,41 @@ static abi_long do_ioctl_drm(const IOCTLEntry *ie, uint8_t *buf_temp,
>
> #endif
>
> +static abi_long do_ioctl_TUNSETTXFILTER(const IOCTLEntry *ie, uint8_t *buf_temp,
> + int fd, int cmd, abi_long arg)
> +{
> + struct tun_filter *filter = (struct tun_filter *)buf_temp;
> + struct tun_filter *target_filter;
> + char *target_addr;
> +
> + assert(ie->access == IOC_W);
> +
> + target_filter = lock_user(VERIFY_READ, arg, sizeof(*filter), 1);
sizeof(*target_filter) vould be more coherent: we lock the target memory
so use the size of the type of the target.
> + if (!target_filter) {
> + return -TARGET_EFAULT;
> + }
> + filter->flags = tswap16(target_filter->flags);
> + filter->count = tswap16(target_filter->count);
> + unlock_user(target_filter, arg, sizeof(*filter));
unlock_user(target_filter, arg, 0) as we don't need to copy the value
back to the target.
> +
> + if (filter->count) {
> + if (sizeof(*filter) + filter->count * ETH_ALEN > MAX_STRUCT_SIZE) {
Rather than sizeof() use offsetof(struct tun_filter, addr)
> + return -TARGET_EFAULT;
> + }
> +
> + target_addr = lock_user(VERIFY_READ, arg + sizeof(*filter),
Rather than sizeof() use offsetof(struct tun_filter, addr)
> + filter->count * ETH_ALEN, 1);
> + if (!target_addr) {
> + return -TARGET_EFAULT;
> + }
> + memcpy(filter->addr, target_addr, filter->count * ETH_ALEN);
> + unlock_user(target_addr, arg + sizeof(*filter),
offsetof(struct tun_filter, addr)
Thanks,
Laurent
next prev parent reply other threads:[~2020-09-26 16:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-23 23:10 [PATCH v2] linux-user: Add most IFTUN ioctls Shu-Chun Weng
2020-08-05 23:22 ` Shu-Chun Weng
2020-09-17 7:24 ` Shu-Chun Weng
2020-09-26 16:44 ` Laurent Vivier [this message]
2020-09-28 16:52 ` Shu-Chun Weng
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=5f73f9b9-53dd-b483-4eed-07ab9d660ed1@vivier.eu \
--to=laurent@vivier.eu \
--cc=jkz@google.com \
--cc=qemu-devel@nongnu.org \
--cc=riku.voipio@iki.fi \
--cc=scw@google.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;
as well as URLs for NNTP newsgroup(s).