lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1682096818-30056-3-git-send-email-haiyangz@microsoft.com>
Date:   Fri, 21 Apr 2023 10:06:58 -0700
From:   Haiyang Zhang <haiyangz@...rosoft.com>
To:     linux-hyperv@...r.kernel.org, netdev@...r.kernel.org
Cc:     haiyangz@...rosoft.com, decui@...rosoft.com, kys@...rosoft.com,
        paulros@...rosoft.com, olaf@...fle.de, vkuznets@...hat.com,
        davem@...emloft.net, wei.liu@...nel.org, edumazet@...gle.com,
        kuba@...nel.org, pabeni@...hat.com, leon@...nel.org,
        longli@...rosoft.com, ssengar@...ux.microsoft.com,
        linux-rdma@...r.kernel.org, daniel@...earbox.net,
        john.fastabend@...il.com, bpf@...r.kernel.org, ast@...nel.org,
        sharmaajay@...rosoft.com, hawk@...nel.org,
        linux-kernel@...r.kernel.org
Subject: [PATCH net-next, 2/2] net: mana: Check if netdev/napi_alloc_frag returns single page

netdev/napi_alloc_frag() may fall back to single page which is smaller
than the requested size.
Add error checking to avoid memory overwritten.

Signed-off-by: Haiyang Zhang <haiyangz@...rosoft.com>
---
 drivers/net/ethernet/microsoft/mana/mana_en.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c
index db2887e25714..06d6292e09b3 100644
--- a/drivers/net/ethernet/microsoft/mana/mana_en.c
+++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
@@ -553,6 +553,14 @@ static int mana_pre_alloc_rxbufs(struct mana_port_context *mpc, int new_mtu)
 			va = netdev_alloc_frag(mpc->rxbpre_alloc_size);
 			if (!va)
 				goto error;
+
+			page = virt_to_head_page(va);
+			/* Check if the frag falls back to single page */
+			if (compound_order(page) <
+			    get_order(mpc->rxbpre_alloc_size)) {
+				put_page(page);
+				goto error;
+			}
 		} else {
 			page = dev_alloc_page();
 			if (!page)
@@ -1504,6 +1512,13 @@ static void *mana_get_rxfrag(struct mana_rxq *rxq, struct device *dev,
 
 		if (!va)
 			return NULL;
+
+		page = virt_to_head_page(va);
+		/* Check if the frag falls back to single page */
+		if (compound_order(page) < get_order(rxq->alloc_size)) {
+			put_page(page);
+			return NULL;
+		}
 	} else {
 		page = dev_alloc_page();
 		if (!page)
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ