netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] i40e: Add length check for IFLA_AF_SPEC parsing
@ 2023-07-23  7:50 Lin Ma
  2023-07-24 17:44 ` Leon Romanovsky
  0 siblings, 1 reply; 7+ messages in thread
From: Lin Ma @ 2023-07-23  7:50 UTC (permalink / raw)
  To: jesse.brandeburg, anthony.l.nguyen, davem, edumazet, kuba, pabeni,
	richardcochran, ast, daniel, hawk, john.fastabend,
	intel-wired-lan, netdev, linux-kernel
  Cc: Lin Ma

The nla_for_each_nested parsing in function i40e_ndo_bridge_setlink()
does not check the length of the attribute. This can lead to an
out-of-attribute read and allow a malformed nlattr (e.g., length 0) to
be viewed as a 2 byte integer.

This patch adds the check based on nla_len() just as other code does,
see how bnxt_bridge_setlink (drivers/net/ethernet/broadcom/bnxt/bnxt.c)
parses IFLA_AF_SPEC: type checking plus length checking.

Fixes: 51616018dd1b ("i40e: Add support for getlink, setlink ndo ops")
Signed-off-by: Lin Ma <linma@zju.edu.cn>
---
 drivers/net/ethernet/intel/i40e/i40e_main.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
index 29ad1797adce..6363357bdeeb 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
@@ -13186,6 +13186,9 @@ static int i40e_ndo_bridge_setlink(struct net_device *dev,
 		if (nla_type(attr) != IFLA_BRIDGE_MODE)
 			continue;
 
+		if (nla_len(attr) < sizeof(mode))
+			return -EINVAL;
+
 		mode = nla_get_u16(attr);
 		if ((mode != BRIDGE_MODE_VEPA) &&
 		    (mode != BRIDGE_MODE_VEB))
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-07-25 18:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-23  7:50 [PATCH v1] i40e: Add length check for IFLA_AF_SPEC parsing Lin Ma
2023-07-24 17:44 ` Leon Romanovsky
2023-07-24 21:21   ` Jakub Kicinski
2023-07-25  0:00     ` Lin Ma
2023-07-25  5:40     ` Leon Romanovsky
2023-07-25 16:53       ` Jakub Kicinski
2023-07-25 18:36         ` Leon Romanovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).