aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2024-07-09 14:10:45 +0000
committerMark Johnston <markj@FreeBSD.org>2024-07-09 14:26:16 +0000
commit5dc4682c32691b9d0a20abdc5479d6ce2b36915e (patch)
treec6344399c725396af72c2ceba819e8566730d9e9
parent9207f9d206a4017001f01ca27d3d25a26c268a95 (diff)
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
-rw-r--r--sys/dev/usb/net/if_urndis.c22
1 files 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");