[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <4d61f086-c7b4-4762-b025-0ba5df08968b@moroto.mountain>
Date: Thu, 5 Oct 2023 16:57:21 +0300
From: Dan Carpenter <dan.carpenter@...aro.org>
To: Jinjie Ruan <ruanjinjie@...wei.com>
Cc: Jesse Brandeburg <jesse.brandeburg@...el.com>,
Tony Nguyen <anthony.l.nguyen@...el.com>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Jacob Keller <jacob.e.keller@...el.com>,
Simon Horman <horms@...nel.org>, intel-wired-lan@...ts.osuosl.org,
netdev@...r.kernel.org, kernel-janitors@...r.kernel.org
Subject: [PATCH net-next 1/2] igb: Fix an end of loop test
When we exit a list_for_each_entry() without hitting a break statement,
the list iterator isn't NULL, it just point to an offset off the
list_head. In that situation, it wouldn't be too surprising for
entry->free to be true and we end up corrupting memory.
The way to test for these is to just set a flag.
Fixes: c1fec890458a ("ethernet/intel: Use list_for_each_entry() helper")
Signed-off-by: Dan Carpenter <dan.carpenter@...aro.org>
---
drivers/net/ethernet/intel/igb/igb_main.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index 2ac9dffd0bf8..c45b1e7cde58 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -7857,7 +7857,8 @@ static int igb_set_vf_mac_filter(struct igb_adapter *adapter, const int vf,
{
struct pci_dev *pdev = adapter->pdev;
struct vf_data_storage *vf_data = &adapter->vf_data[vf];
- struct vf_mac_filter *entry = NULL;
+ struct vf_mac_filter *entry;
+ bool found = false;
int ret = 0;
if ((vf_data->flags & IGB_VF_FLAG_PF_SET_MAC) &&
@@ -7888,11 +7889,13 @@ static int igb_set_vf_mac_filter(struct igb_adapter *adapter, const int vf,
case E1000_VF_MAC_FILTER_ADD:
/* try to find empty slot in the list */
list_for_each_entry(entry, &adapter->vf_macs.l, l) {
- if (entry->free)
+ if (entry->free) {
+ found = true;
break;
+ }
}
- if (entry && entry->free) {
+ if (found) {
entry->free = false;
entry->vf = vf;
ether_addr_copy(entry->vf_mac, addr);
--
2.39.2
Powered by blists - more mailing lists