Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 Oct 2021 03:37:42 GMT
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 000aad3d093a - stable/12 - loader: allocate properly aligned buffer for network packet
Message-ID:  <202110070337.1973bgRH073900@gitrepo.freebsd.org>

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

URL: https://cgit.FreeBSD.org/src/commit/?id=000aad3d093a376bb1104a284b4102149db43155

commit 000aad3d093a376bb1104a284b4102149db43155
Author:     Toomas Soome <tsoome@FreeBSD.org>
AuthorDate: 2020-01-13 18:22:54 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2021-10-07 03:36:34 +0000

    loader: allocate properly aligned buffer for network packet
    
    Use memalign(4, size) to ensure we have properly aligned buffer.
    
    (cherry picked from commit 659bf32dfc595b6cd6aeda7f05cb57872c64d2d1)
---
 stand/efi/libefi/efinet.c | 2 +-
 stand/i386/libi386/pxe.c  | 2 +-
 stand/libofw/ofw_net.c    | 2 +-
 stand/uboot/lib/net.c     | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/stand/efi/libefi/efinet.c b/stand/efi/libefi/efinet.c
index 418790524e4a..989b2efdaac2 100644
--- a/stand/efi/libefi/efinet.c
+++ b/stand/efi/libefi/efinet.c
@@ -178,7 +178,7 @@ efinet_get(struct iodesc *desc, void **pkt, time_t timeout)
 		return (ret);
 
 	bufsz = net->Mode->MaxPacketSize + ETHER_HDR_LEN + ETHER_CRC_LEN;
-	buf = malloc(bufsz + ETHER_ALIGN);
+	buf = memalign(4, bufsz + ETHER_ALIGN);
 	if (buf == NULL)
 		return (ret);
 	ptr = buf + ETHER_ALIGN;
diff --git a/stand/i386/libi386/pxe.c b/stand/i386/libi386/pxe.c
index e80a1961e191..e94c63878284 100644
--- a/stand/i386/libi386/pxe.c
+++ b/stand/i386/libi386/pxe.c
@@ -501,7 +501,7 @@ pxe_netif_receive_isr(t_PXENV_UNDI_ISR *isr, void **pkt, ssize_t *retsize)
 			 * multiple GET_NEXT calls.
 			 */
 			size = isr->FrameLength;
-			buf = malloc(size + ETHER_ALIGN);
+			buf = memalign(4, size + ETHER_ALIGN);
 			if (buf == NULL)
 				return (ENOMEM);
 
diff --git a/stand/libofw/ofw_net.c b/stand/libofw/ofw_net.c
index 14494ecc2b2e..a037c3defaf5 100644
--- a/stand/libofw/ofw_net.c
+++ b/stand/libofw/ofw_net.c
@@ -142,7 +142,7 @@ ofwn_get(struct iodesc *desc, void **pkt, time_t timeout)
 	 * a small shortcut here.
 	 */
 	len = ETHER_MAX_LEN;
-	buf = malloc(len + ETHER_ALIGN);
+	buf = memalign(4, len + ETHER_ALIGN);
 	if (buf == NULL)
 		return (-1);
 	ptr = buf + ETHER_ALIGN;
diff --git a/stand/uboot/lib/net.c b/stand/uboot/lib/net.c
index 81b8c5bc9f5b..3d0ba5fdc6d3 100644
--- a/stand/uboot/lib/net.c
+++ b/stand/uboot/lib/net.c
@@ -302,7 +302,7 @@ net_get(struct iodesc *desc, void **pkt, time_t timeout)
 #endif
 
 	if (rlen > 0) {
-		buf = malloc(rlen + ETHER_ALIGN);
+		buf = memalign(4, rlen + ETHER_ALIGN);
 		if (buf == NULL)
 			return (-1);
 		memcpy(buf + ETHER_ALIGN, sc->sc_rxbuf, rlen);



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