Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Jul 2024 13:19:35 GMT
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 030cbcc4c231 - stable/14 - if_urndis: Organize buffer layouts more naturally
Message-ID:  <202407231319.46NDJZMG004433@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=030cbcc4c231be94b5ded668930e5be17cb9d3d5

commit 030cbcc4c231be94b5ded668930e5be17cb9d3d5
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-07-09 14:10:45 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-07-23 13:01:37 +0000

    if_urndis: Organize buffer layouts more naturally
    
    - Group the request header and I/O buffer in one structure, rather than
      assuming that both request structures have the same size.
    - Pass a pointer to the whole structure to urndis_ctrl_query() and
      urndis_ctrl_set() rather than just the header.  Otherwise, on CHERI
      platforms, these functions violate subobject bounds since they modify
      the buffer following the header.
    
    While here, there is no apparent reason for the request structure used
    in urndis_attach() to be allocated statically.  Change it so that it's
    allocated on the stack.
    
    No functional change intended.
    
    Reviewed by:    jhb
    MFC after:      2 weeks
    Sponsored by:   Innovate UK
    Differential Revision:  https://reviews.freebsd.org/D45866
    
    (cherry picked from commit 5dc4682c32691b9d0a20abdc5479d6ce2b36915e)
---
 sys/dev/usb/net/if_urndis.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/sys/dev/usb/net/if_urndis.c b/sys/dev/usb/net/if_urndis.c
index 824609aa869f..0a7cb3fed953 100644
--- a/sys/dev/usb/net/if_urndis.c
+++ b/sys/dev/usb/net/if_urndis.c
@@ -214,15 +214,15 @@ urndis_attach_post(struct usb_ether *ue)
 static int
 urndis_attach(device_t dev)
 {
-	static struct {
-		union {
+	union {
+		struct {
 			struct rndis_query_req query;
+			uint8_t addr[ETHER_ADDR_LEN];
+		} eaddr;
+		struct {
 			struct rndis_set_req set;
-		} hdr;
-		union {
-			uint8_t eaddr[ETHER_ADDR_LEN];
 			uint32_t filter;
-		} ibuf;
+		} filter;
 	} msg;
 	struct urndis_softc *sc = device_get_softc(dev);
 	struct usb_ether *ue = &sc->sc_ue;
@@ -278,10 +278,10 @@ urndis_attach(device_t dev)
 	}
 
 	/* Determine MAC address */
-	memset(msg.ibuf.eaddr, 0, sizeof(msg.ibuf.eaddr));
+	memset(msg.eaddr.addr, 0, sizeof(msg.eaddr.addr));
 	URNDIS_LOCK(sc);
 	error = urndis_ctrl_query(sc, OID_802_3_PERMANENT_ADDRESS,
-	    &msg.hdr.query, sizeof(msg.hdr.query) + sizeof(msg.ibuf.eaddr),
+	    (struct rndis_query_req *)&msg.eaddr, sizeof(msg.eaddr),
 	    &buf, &bufsz);
 	URNDIS_UNLOCK(sc);
 	if (error != (int)RNDIS_STATUS_SUCCESS) {
@@ -297,10 +297,10 @@ urndis_attach(device_t dev)
 	/* Initialize packet filter */
 	sc->sc_filter = NDIS_PACKET_TYPE_BROADCAST |
 	    NDIS_PACKET_TYPE_ALL_MULTICAST;
-	msg.ibuf.filter = htole32(sc->sc_filter);
+	msg.filter.filter = htole32(sc->sc_filter);
 	URNDIS_LOCK(sc);
 	error = urndis_ctrl_set(sc, OID_GEN_CURRENT_PACKET_FILTER,
-	    &msg.hdr.set, sizeof(msg.hdr.set) + sizeof(msg.ibuf.filter));
+	    (struct rndis_set_req *)&msg.filter, sizeof(msg.filter));
 	URNDIS_UNLOCK(sc);
 	if (error != (int)RNDIS_STATUS_SUCCESS) {
 		device_printf(dev, "Unable to set data filters\n");
@@ -641,7 +641,7 @@ urndis_ctrl_handle_reset(struct urndis_softc *sc,
 		msg_filter.filter = htole32(sc->sc_filter);
 
 		rval = urndis_ctrl_set(sc, OID_GEN_CURRENT_PACKET_FILTER,
-		    &msg_filter.hdr, sizeof(msg_filter));
+		    (struct rndis_set_req *)&msg_filter, sizeof(msg_filter));
 
 		if (rval != RNDIS_STATUS_SUCCESS) {
 			DPRINTF("unable to reset data filters\n");



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202407231319.46NDJZMG004433>