From nobody Tue Feb 10 00:59:56 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1608287159; cv=none; d=zohomail.com; s=zohoarc; b=TMFZdQYPRqv/KtsEm/DZna13kO40z32BHdqsC7zXQV6cPG7sKe9RKErxh3RDExz4AjJeUt2jjpZxk7g3a1q81Qy6TZJPrqXPkzIu6TPOIpr80yTF+7REiBL9IjNfEIz09GXrJRTMMd8ynW50juE4KJ4iFib2mJyeVg0oFTgTDho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608287159; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hkH8JA8nlDuDoAGbyzS7H9Y2ZbD7mQLGuamZ5kbnZIA=; b=iDCE5iaPllTBULVjRwso1aocbvyNMmgzRalld/pko8N2Sy/4NacH4B3jbP3XcXcQTtX/6GIvmHflDwezWWuIOl72DcsLQItaJ5EDgrZuTNZV9DG/PnQXSA2CkhXXljTVLk8JiUToeuJ+9XM/eMMb/MUTKTo4XtTRSa1mpBOU8Wo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608287159544890.9694019056187; Fri, 18 Dec 2020 02:25:59 -0800 (PST) Received: from localhost ([::1]:47286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqCxS-0004ea-7Q for importer@patchew.org; Fri, 18 Dec 2020 05:25:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqCvt-0002xf-B3 for qemu-devel@nongnu.org; Fri, 18 Dec 2020 05:24:21 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:50493) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqCvp-00074A-Kj for qemu-devel@nongnu.org; Fri, 18 Dec 2020 05:24:21 -0500 Received: from localhost.localdomain ([82.252.144.198]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MDQqe-1kyUfY3ity-00AScE; Fri, 18 Dec 2020 11:24:15 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 10/14] linux-user: Add most IFTUN ioctls Date: Fri, 18 Dec 2020 11:24:03 +0100 Message-Id: <20201218102407.597566-11-laurent@vivier.eu> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201218102407.597566-1-laurent@vivier.eu> References: <20201218102407.597566-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:WX4zhIraeXJ57QngkiIZ3VOefRuMouUQGqnpfcJ6Og/w2Ds0DbP tNpEtW/0GGrRUCzitk0M4IA42CNz+DaB1oQ9n+GpcqegWtjDwdExK1kkxuXw0W3rUXEWHip w10RJwJfQCgZi95w8sXwFsmSVdxCip+Abh317HxMKiUmF/cfNzW50X6TtU4UzhMW2bnt24W Riy+dy3zLx6ZHVX+hIAHw== X-UI-Out-Filterresults: notjunk:1;V03:K0:B0qMyKwVQc0=:JOZBwyKfwdaX6MU8jtQHTP 2at2DlsSpeO0ms0LVapSh4+on2BMfoAmVy5YHzIA4xUXW3uS09ZwdQ2G6CuHoV/eSdy8xsIRf zAT/tPCFEY/u3qH0FQ7PJnp9AsSByCKVrN5NBP8KSxQzRJeIyHXeIACSHPrcYPR3wRqIVEGOW POz2hopNn5GXM5ghyEtJci6mnFiTH1bEKEAuR8i1dOHBCqgx/gZXX+akMNpRpqFsanewppOBJ yzKj5ZSr+7PQ587e6+vgDnggOZeeFSckj3HM/OVMnOjiPztzhmHAeIHuaXZ6mjjKR7Fuf8vCo 4sUO9dgHYxZ3sCUFk55nCTFdmRfdzvZX/FfCoQhstfElMOqhdQxgj24jxPgwfwIVD0zOpB+NF r2rFaZkETjfOfHZkcU+bAFPfzzocDt0i+MPvLYOYI74cILPGkhAn//co/TFP+ Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=217.72.192.73; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Josh Kunz , Shu-Chun Weng , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Shu-Chun Weng 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 Signed-off-by: Shu-Chun Weng Reviewed-by: Laurent Vivier Message-Id: <20200929014801.655524-1-scw@google.com> [lv: use 0 size in unlock_user()] Signed-off-by: Laurent Vivier --- linux-user/ioctls.h | 46 +++++++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 37 +++++++++++++++++++++++++++++++ linux-user/syscall_defs.h | 32 +++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h index 8efb4d38c014..661b5daa9fd8 100644 --- a/linux-user/ioctls.h +++ b/linux-user/ioctls.h @@ -720,3 +720,49 @@ 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))) + 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) + IOCTL_SPECIAL(TUNSETTXFILTER, IOC_W, do_ioctl_TUNSETTXFILTER, + /* + * We can't represent `struct tun_filter` in thunk so leav= ing + * it uninterpreted. do_ioctl_TUNSETTXFILTER will do the + * conversion. + */ + TYPE_PTRVOID) + 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 k= eeps a + * user pointer in TUNATTACHFILTER, which we are not able to correctly h= andle. + */ + 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 6091a449fbf0..d182890ff04a 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #ifdef CONFIG_TIMERFD @@ -5709,6 +5710,42 @@ static abi_long do_ioctl_drm_i915(const IOCTLEntry *= ie, uint8_t *buf_temp, =20 #endif =20 +static abi_long do_ioctl_TUNSETTXFILTER(const IOCTLEntry *ie, uint8_t *buf= _temp, + int fd, int cmd, abi_long arg) +{ + struct tun_filter *filter =3D (struct tun_filter *)buf_temp; + struct tun_filter *target_filter; + char *target_addr; + + assert(ie->access =3D=3D IOC_W); + + target_filter =3D lock_user(VERIFY_READ, arg, sizeof(*target_filter), = 1); + if (!target_filter) { + return -TARGET_EFAULT; + } + filter->flags =3D tswap16(target_filter->flags); + filter->count =3D tswap16(target_filter->count); + unlock_user(target_filter, arg, 0); + + if (filter->count) { + if (offsetof(struct tun_filter, addr) + filter->count * ETH_ALEN > + MAX_STRUCT_SIZE) { + return -TARGET_EFAULT; + } + + target_addr =3D lock_user(VERIFY_READ, + arg + 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 + offsetof(struct tun_filter, addr), = 0); + } + + return get_errno(safe_ioctl(fd, ie->host_cmd, filter)); +} + IOCTLEntry ioctl_entries[] =3D { #define IOCTL(cmd, access, ...) \ { TARGET_ ## cmd, cmd, #cmd, access, 0, { __VA_ARGS__ } }, diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index b934d0b60676..a00bfc2647c7 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -929,6 +929,38 @@ struct target_rtc_pll_info { =20 #define TARGET_SIOCGIWNAME 0x8B01 /* get name =3D=3D wireless= protocol */ =20 +/* From */ + +#define TARGET_TUNSETDEBUG TARGET_IOW('T', 201, int) +#define TARGET_TUNSETIFF TARGET_IOW('T', 202, int) +#define TARGET_TUNSETPERSIST TARGET_IOW('T', 203, int) +#define TARGET_TUNSETOWNER TARGET_IOW('T', 204, int) +#define TARGET_TUNSETLINK TARGET_IOW('T', 205, int) +#define TARGET_TUNSETGROUP TARGET_IOW('T', 206, int) +#define TARGET_TUNGETFEATURES TARGET_IOR('T', 207, unsigned int) +#define TARGET_TUNSETOFFLOAD TARGET_IOW('T', 208, unsigned int) +#define TARGET_TUNSETTXFILTER TARGET_IOW('T', 209, unsigned int) +#define TARGET_TUNGETIFF TARGET_IOR('T', 210, unsigned int) +#define TARGET_TUNGETSNDBUF TARGET_IOR('T', 211, int) +#define TARGET_TUNSETSNDBUF TARGET_IOW('T', 212, int) +/* + * TUNATTACHFILTER and TUNDETACHFILTER are not supported. Linux kernel kee= ps a + * user pointer in TUNATTACHFILTER, which we are not able to correctly han= dle. + */ +#define TARGET_TUNGETVNETHDRSZ TARGET_IOR('T', 215, int) +#define TARGET_TUNSETVNETHDRSZ TARGET_IOW('T', 216, int) +#define TARGET_TUNSETQUEUE TARGET_IOW('T', 217, int) +#define TARGET_TUNSETIFINDEX TARGET_IOW('T', 218, unsigned int) +/* TUNGETFILTER is not supported: see TUNATTACHFILTER. */ +#define TARGET_TUNSETVNETLE TARGET_IOW('T', 220, int) +#define TARGET_TUNGETVNETLE TARGET_IOR('T', 221, int) +#define TARGET_TUNSETVNETBE TARGET_IOW('T', 222, int) +#define TARGET_TUNGETVNETBE TARGET_IOR('T', 223, int) +#define TARGET_TUNSETSTEERINGEBPF TARGET_IOR('T', 224, int) +#define TARGET_TUNSETFILTEREBPF TARGET_IOR('T', 225, int) +#define TARGET_TUNSETCARRIER TARGET_IOW('T', 226, int) +#define TARGET_TUNGETDEVNETNS TARGET_IO('T', 227) + /* From */ =20 #define TARGET_RNDGETENTCNT TARGET_IOR('R', 0x00, int) --=20 2.29.2