From nobody Thu Nov 10 19:15:15 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4N7WkW5pCqz4dnyt; Thu, 10 Nov 2022 19:15:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4N7WkW53jMz41NS; Thu, 10 Nov 2022 19:15:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668107715; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oNZCpmv85QiYo2/xFwGuQqyBMfFs37+aC4YeSFvXEm4=; b=AU43kI1QINTBy89XH5ymukBtcOjG8g28PE9+QN3KnLMuXgdeyvhnWM5V5qgmr9IC6GFi4l Q329f2qmmg+G2PtW3oWqknbyoO+65DHjfyyfX2RKFNClaNg+MdRQPj+oqlpt7jSoc9iqPs rwyIhLjz76GoLPsM/cih2dygOXb+Twu429gPMTIOtuvsf6SilZ/zS2EgwWkFT61u5UaHW0 ez7+l7QdU4pBLtI2/MG72w2x4M0pyv8Am8r8K2Gi73Xw/KFonlB2N/t/tixtHakBXMdJV8 NZuW7sxXGadn6BT4nmDGtTRuBHJ8LgWmBaDMHJtH+4XEcO8MS4iouBk73FQWHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668107715; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oNZCpmv85QiYo2/xFwGuQqyBMfFs37+aC4YeSFvXEm4=; b=CWiBW5yvo0kCpey/EcHcJ1wQ/yOxWMS+BLGlhB7XeYQb0FmDNJXRhepsQ3G2Q50kPBqgXI 2ZoGYMCxeuzYF/pIPLTNSc7SSNZm7U06UHKKk/8wrca5ngWrjiDovcOTwXdKexKPOU0EC7 +3515HJWkqHT2n+4m+TbOjHcvdJe8/nrejBPsCdcipwNq2axWLnRPVUu9HdySnoWwZHosQ s6XFGoBPi8/+WhEv7ORKU64m7jFkB2hSZ+NgIF99yG8Y+ZsGnG9hTiWFatO/8GRc+iqqCu XiqKrP3rEPb+Oz9maauraD5pGP1WsOUpnJwSEJj6gLT98hCTOGsv/4UmE25T8w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1668107715; a=rsa-sha256; cv=none; b=k9Xki0EGwvxB7KUcL/HtIEEno8CGCyNmRv9maa8JOm1v2/9BEMAV0IIX3FBxMLpW6Nbv0n UJSJuYdw/AVePg+nnp3+rVO3CFnmYFWpxeegd+U39RNMXBPPzz/jBZcbNFxwDUS8hZesE9 21TFTqYxeA7aNCpO5x68wXgbsn8dOEzRejawJeN6R2poNKA9NeNWsB+5SfbSS1vZAe3LDS hZg8k3mMAsINiZLefplSakWen0JRGRaTeJoipO2lCijlysRATb+m3Y+hK6aw0dD8z2TyKV XqBsqPjNch5Yr3XbkeRQ9dDM88SnuYjFJezntKmb19+bkZwb/Kp2HsGONdiLnA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4N7WkW483Rz1CgT; Thu, 10 Nov 2022 19:15:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2AAJFFZ8000980; Thu, 10 Nov 2022 19:15:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AAJFFCM000979; Thu, 10 Nov 2022 19:15:15 GMT (envelope-from git) Date: Thu, 10 Nov 2022 19:15:15 GMT Message-Id: <202211101915.2AAJFFCM000979@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: e4f4273d054a - stable/13 - Use thunks for compat ioctls using struct ifgroupreq. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: e4f4273d054abeb1c57c4aacb8e9ca962409885d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=e4f4273d054abeb1c57c4aacb8e9ca962409885d commit e4f4273d054abeb1c57c4aacb8e9ca962409885d Author: John Baldwin AuthorDate: 2021-05-05 20:59:00 +0000 Commit: John Baldwin CommitDate: 2022-11-10 18:26:06 +0000 Use thunks for compat ioctls using struct ifgroupreq. Reviewed by: brooks, kib Obtained from: CheriBSD Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D29893 (cherry picked from commit 01e9cbc4c56d6eecc52f1e4547d56124243f0dd2) --- sys/net/if.c | 99 +++++++++++++++++++++++++++--------------------------------- sys/net/if.h | 2 -- 2 files changed, 45 insertions(+), 56 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index eefa0ac93291..ae7b1087c249 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -165,6 +165,10 @@ struct ifgroupreq32 { uint32_t ifgru_groups; } ifgr_ifgru; }; +#define SIOCAIFGROUP32 _IOC_NEWTYPE(SIOCAIFGROUP, struct ifgroupreq32) +#define SIOCGIFGROUP32 _IOC_NEWTYPE(SIOCGIFGROUP, struct ifgroupreq32) +#define SIOCDIFGROUP32 _IOC_NEWTYPE(SIOCDIFGROUP, struct ifgroupreq32) +#define SIOCGIFGMEMB32 _IOC_NEWTYPE(SIOCGIFGMEMB, struct ifgroupreq32) struct ifmediareq32 { char ifm_name[IFNAMSIZ]; @@ -177,16 +181,7 @@ struct ifmediareq32 { }; #define SIOCGIFMEDIA32 _IOC_NEWTYPE(SIOCGIFMEDIA, struct ifmediareq32) #define SIOCGIFXMEDIA32 _IOC_NEWTYPE(SIOCGIFXMEDIA, struct ifmediareq32) - -#define _CASE_IOC_IFGROUPREQ_32(cmd) \ - _IOC_NEWTYPE((cmd), struct ifgroupreq32): case -#else /* !COMPAT_FREEBSD32 */ -#define _CASE_IOC_IFGROUPREQ_32(cmd) -#endif /* !COMPAT_FREEBSD32 */ - -#define CASE_IOC_IFGROUPREQ(cmd) \ - _CASE_IOC_IFGROUPREQ_32(cmd) \ - (cmd) +#endif /* COMPAT_FREEBSD32 */ union ifreq_union { struct ifreq ifr; @@ -195,13 +190,6 @@ union ifreq_union { #endif }; -union ifgroupreq_union { - struct ifgroupreq ifgr; -#ifdef COMPAT_FREEBSD32 - struct ifgroupreq32 ifgr32; -#endif -}; - SYSCTL_NODE(_net, PF_LINK, link, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, "Link layers"); SYSCTL_NODE(_net_link, 0, generic, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, @@ -1675,33 +1663,6 @@ if_delgroups(struct ifnet *ifp) IFNET_WUNLOCK(); } -static char * -ifgr_group_get(void *ifgrp) -{ - union ifgroupreq_union *ifgrup; - - ifgrup = ifgrp; -#ifdef COMPAT_FREEBSD32 - if (SV_CURPROC_FLAG(SV_ILP32)) - return (&ifgrup->ifgr32.ifgr_ifgru.ifgru_group[0]); -#endif - return (&ifgrup->ifgr.ifgr_ifgru.ifgru_group[0]); -} - -static struct ifg_req * -ifgr_groups_get(void *ifgrp) -{ - union ifgroupreq_union *ifgrup; - - ifgrup = ifgrp; -#ifdef COMPAT_FREEBSD32 - if (SV_CURPROC_FLAG(SV_ILP32)) - return ((struct ifg_req *)(uintptr_t) - ifgrup->ifgr32.ifgr_ifgru.ifgru_groups); -#endif - return (ifgrup->ifgr.ifgr_ifgru.ifgru_groups); -} - /* * Stores all groups from an interface in memory pointed to by ifgr. */ @@ -1721,7 +1682,7 @@ if_getgroup(struct ifgroupreq *ifgr, struct ifnet *ifp) } len = ifgr->ifgr_len; - ifgp = ifgr_groups_get(ifgr); + ifgp = ifgr->ifgr_groups; /* XXX: wire */ CK_STAILQ_FOREACH(ifgl, &ifp->if_groups, ifgl_next) { if (len < sizeof(ifgrq)) @@ -1766,7 +1727,7 @@ if_getgroupmembers(struct ifgroupreq *ifgr) } len = ifgr->ifgr_len; - ifgp = ifgr_groups_get(ifgr); + ifgp = ifgr->ifgr_groups; CK_STAILQ_FOREACH(ifgm, &ifg->ifg_members, ifgm_next) { if (len < sizeof(ifgrq)) { IFNET_RUNLOCK(); @@ -2902,16 +2863,17 @@ ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data, struct thread *td) error = if_gethwaddr(ifp, ifr); break; - case CASE_IOC_IFGROUPREQ(SIOCAIFGROUP): + case SIOCAIFGROUP: error = priv_check(td, PRIV_NET_ADDIFGROUP); if (error) return (error); - if ((error = if_addgroup(ifp, - ifgr_group_get((struct ifgroupreq *)data)))) + error = if_addgroup(ifp, + ((struct ifgroupreq *)data)->ifgr_group); + if (error != 0) return (error); break; - case CASE_IOC_IFGROUPREQ(SIOCGIFGROUP): + case SIOCGIFGROUP: { struct epoch_tracker et; @@ -2921,12 +2883,13 @@ ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data, struct thread *td) break; } - case CASE_IOC_IFGROUPREQ(SIOCDIFGROUP): + case SIOCDIFGROUP: error = priv_check(td, PRIV_NET_DELIFGROUP); if (error) return (error); - if ((error = if_delgroup(ifp, - ifgr_group_get((struct ifgroupreq *)data)))) + error = if_delgroup(ifp, + ((struct ifgroupreq *)data)->ifgr_group); + if (error != 0) return (error); break; @@ -2957,12 +2920,14 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) union { struct ifconf ifc; struct ifdrv ifd; + struct ifgroupreq ifgr; struct ifmediareq ifmr; } thunk; caddr_t saved_data; u_long saved_cmd; struct ifconf32 *ifc32; struct ifdrv32 *ifd32; + struct ifgroupreq32 *ifgr32; struct ifmediareq32 *ifmr32; #endif struct ifnet *ifp; @@ -3005,6 +2970,28 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) data = (caddr_t)&thunk.ifd; cmd = _IOC_NEWTYPE(cmd, struct ifdrv); break; + case SIOCAIFGROUP32: + case SIOCGIFGROUP32: + case SIOCDIFGROUP32: + case SIOCGIFGMEMB32: + ifgr32 = (struct ifgroupreq32 *)data; + memcpy(thunk.ifgr.ifgr_name, ifgr32->ifgr_name, + sizeof(thunk.ifgr.ifgr_name)); + thunk.ifgr.ifgr_len = ifgr32->ifgr_len; + switch (cmd) { + case SIOCAIFGROUP32: + case SIOCDIFGROUP32: + memcpy(thunk.ifgr.ifgr_group, ifgr32->ifgr_group, + sizeof(thunk.ifgr.ifgr_group)); + break; + case SIOCGIFGROUP32: + case SIOCGIFGMEMB32: + thunk.ifgr.ifgr_groups = PTRIN(ifgr32->ifgr_groups); + break; + } + data = (caddr_t)&thunk.ifgr; + cmd = _IOC_NEWTYPE(cmd, struct ifgroupreq); + break; case SIOCGIFMEDIA32: case SIOCGIFXMEDIA32: ifmr32 = (struct ifmediareq32 *)data; @@ -3060,7 +3047,7 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) error = if_clone_list((struct if_clonereq *)data); goto out_noref; - case CASE_IOC_IFGROUPREQ(SIOCGIFGMEMB): + case SIOCGIFGMEMB: error = if_getgroupmembers((struct ifgroupreq *)data); goto out_noref; @@ -3136,6 +3123,10 @@ out_noref: ("ifd_len was updated %u -> %zu", ifd32->ifd_len, thunk.ifd.ifd_len)); break; + case SIOCGIFGROUP32: + case SIOCGIFGMEMB32: + ifgr32->ifgr_len = thunk.ifgr.ifgr_len; + break; case SIOCGIFMEDIA32: case SIOCGIFXMEDIA32: ifmr32->ifm_current = thunk.ifmr.ifm_current; diff --git a/sys/net/if.h b/sys/net/if.h index e6073563bce2..782e792cf87c 100644 --- a/sys/net/if.h +++ b/sys/net/if.h @@ -530,10 +530,8 @@ struct ifgroupreq { char ifgru_group[IFNAMSIZ]; struct ifg_req *ifgru_groups; } ifgr_ifgru; -#ifndef _KERNEL #define ifgr_group ifgr_ifgru.ifgru_group #define ifgr_groups ifgr_ifgru.ifgru_groups -#endif }; /*