* [PATCH net-next 1/2] igb: Fix an end of loop test
@ 2023-10-05 13:57 Dan Carpenter
2023-10-05 13:58 ` [PATCH net-next 2/2] ixgbe: fix end of loop test in ixgbe_set_vf_macvlan() Dan Carpenter
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Dan Carpenter @ 2023-10-05 13:57 UTC (permalink / raw)
To: Jinjie Ruan
Cc: Jesse Brandeburg, Tony Nguyen, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Jacob Keller, Simon Horman,
intel-wired-lan, netdev, kernel-janitors
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@linaro.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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next 2/2] ixgbe: fix end of loop test in ixgbe_set_vf_macvlan()
2023-10-05 13:57 [PATCH net-next 1/2] igb: Fix an end of loop test Dan Carpenter
@ 2023-10-05 13:58 ` Dan Carpenter
2023-10-06 11:21 ` Simon Horman
2023-10-09 15:18 ` [Intel-wired-lan] " Jesse Brandeburg
2023-10-06 11:20 ` [PATCH net-next 1/2] igb: Fix an end of loop test Simon Horman
2023-10-09 15:17 ` Jesse Brandeburg
2 siblings, 2 replies; 8+ messages in thread
From: Dan Carpenter @ 2023-10-05 13:58 UTC (permalink / raw)
To: Jinjie Ruan
Cc: Jesse Brandeburg, Tony Nguyen, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Jacob Keller, Simon Horman,
intel-wired-lan, netdev, kernel-janitors
The list iterator in a list_for_each_entry() loop can never be NULL.
If the loop exits without hitting a break then the iterator points
to an offset off the list head and dereferencing it is an out of
bounds access.
Before we transitioned to using list_for_each_entry() loops, then
it was possible for "entry" to be NULL and the comments mention
this. I have updated the comments to match the new code.
Fixes: c1fec890458a ("ethernet/intel: Use list_for_each_entry() helper")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
.../net/ethernet/intel/ixgbe/ixgbe_sriov.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
index 4c6e2a485d8e..a703ba975205 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
@@ -639,6 +639,7 @@ static int ixgbe_set_vf_macvlan(struct ixgbe_adapter *adapter,
int vf, int index, unsigned char *mac_addr)
{
struct vf_macvlans *entry;
+ bool found = false;
int retval = 0;
if (index <= 1) {
@@ -660,22 +661,22 @@ static int ixgbe_set_vf_macvlan(struct ixgbe_adapter *adapter,
if (!index)
return 0;
- entry = NULL;
-
list_for_each_entry(entry, &adapter->vf_mvs.l, l) {
- if (entry->free)
+ if (entry->free) {
+ found = true;
break;
+ }
}
/*
* If we traversed the entire list and didn't find a free entry
- * then we're out of space on the RAR table. Also entry may
- * be NULL because the original memory allocation for the list
- * failed, which is not fatal but does mean we can't support
- * VF requests for MACVLAN because we couldn't allocate
- * memory for the list management required.
+ * then we're out of space on the RAR table. It's also possible
+ * for the &adapter->vf_mvs.l list to be empty because the original
+ * memory allocation for the list failed, which is not fatal but does
+ * mean we can't support VF requests for MACVLAN because we couldn't
+ * allocate memory for the list management required.
*/
- if (!entry || !entry->free)
+ if (!found)
return -ENOSPC;
retval = ixgbe_add_mac_filter(adapter, mac_addr, vf);
--
2.39.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net-next 1/2] igb: Fix an end of loop test
2023-10-05 13:57 [PATCH net-next 1/2] igb: Fix an end of loop test Dan Carpenter
2023-10-05 13:58 ` [PATCH net-next 2/2] ixgbe: fix end of loop test in ixgbe_set_vf_macvlan() Dan Carpenter
@ 2023-10-06 11:20 ` Simon Horman
2023-10-09 15:17 ` Jesse Brandeburg
2 siblings, 0 replies; 8+ messages in thread
From: Simon Horman @ 2023-10-06 11:20 UTC (permalink / raw)
To: Dan Carpenter
Cc: Jinjie Ruan, Jesse Brandeburg, Tony Nguyen, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Jacob Keller,
intel-wired-lan, netdev, kernel-janitors
On Thu, Oct 05, 2023 at 04:57:21PM +0300, Dan Carpenter wrote:
> 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@linaro.org>
Reviewed-by: Simon Horman <horms@kernel.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net-next 2/2] ixgbe: fix end of loop test in ixgbe_set_vf_macvlan()
2023-10-05 13:58 ` [PATCH net-next 2/2] ixgbe: fix end of loop test in ixgbe_set_vf_macvlan() Dan Carpenter
@ 2023-10-06 11:21 ` Simon Horman
2023-10-09 15:18 ` [Intel-wired-lan] " Jesse Brandeburg
1 sibling, 0 replies; 8+ messages in thread
From: Simon Horman @ 2023-10-06 11:21 UTC (permalink / raw)
To: Dan Carpenter
Cc: Jinjie Ruan, Jesse Brandeburg, Tony Nguyen, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Jacob Keller,
intel-wired-lan, netdev, kernel-janitors
On Thu, Oct 05, 2023 at 04:58:01PM +0300, Dan Carpenter wrote:
> The list iterator in a list_for_each_entry() loop can never be NULL.
> If the loop exits without hitting a break then the iterator points
> to an offset off the list head and dereferencing it is an out of
> bounds access.
>
> Before we transitioned to using list_for_each_entry() loops, then
> it was possible for "entry" to be NULL and the comments mention
> this. I have updated the comments to match the new code.
>
> Fixes: c1fec890458a ("ethernet/intel: Use list_for_each_entry() helper")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Simon Horman <horms@kernel.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net-next 1/2] igb: Fix an end of loop test
2023-10-05 13:57 [PATCH net-next 1/2] igb: Fix an end of loop test Dan Carpenter
2023-10-05 13:58 ` [PATCH net-next 2/2] ixgbe: fix end of loop test in ixgbe_set_vf_macvlan() Dan Carpenter
2023-10-06 11:20 ` [PATCH net-next 1/2] igb: Fix an end of loop test Simon Horman
@ 2023-10-09 15:17 ` Jesse Brandeburg
2023-10-16 10:25 ` [Intel-wired-lan] " Romanowski, Rafal
2 siblings, 1 reply; 8+ messages in thread
From: Jesse Brandeburg @ 2023-10-09 15:17 UTC (permalink / raw)
To: Dan Carpenter, Jinjie Ruan
Cc: Tony Nguyen, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Jacob Keller, Simon Horman, intel-wired-lan, netdev,
kernel-janitors
On 10/5/2023 6:57 AM, Dan Carpenter wrote:
> 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@linaro.org>
Reviewed-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Intel-wired-lan] [PATCH net-next 2/2] ixgbe: fix end of loop test in ixgbe_set_vf_macvlan()
2023-10-05 13:58 ` [PATCH net-next 2/2] ixgbe: fix end of loop test in ixgbe_set_vf_macvlan() Dan Carpenter
2023-10-06 11:21 ` Simon Horman
@ 2023-10-09 15:18 ` Jesse Brandeburg
2023-10-16 10:25 ` Romanowski, Rafal
1 sibling, 1 reply; 8+ messages in thread
From: Jesse Brandeburg @ 2023-10-09 15:18 UTC (permalink / raw)
To: Dan Carpenter, Jinjie Ruan
Cc: intel-wired-lan, kernel-janitors, Eric Dumazet, Tony Nguyen,
Simon Horman, netdev, Jacob Keller, Jakub Kicinski, Paolo Abeni,
David S. Miller
On 10/5/2023 6:58 AM, Dan Carpenter wrote:
> The list iterator in a list_for_each_entry() loop can never be NULL.
> If the loop exits without hitting a break then the iterator points
> to an offset off the list head and dereferencing it is an out of
> bounds access.
>
> Before we transitioned to using list_for_each_entry() loops, then
> it was possible for "entry" to be NULL and the comments mention
> this. I have updated the comments to match the new code.
>
> Fixes: c1fec890458a ("ethernet/intel: Use list_for_each_entry() helper")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [Intel-wired-lan] [PATCH net-next 1/2] igb: Fix an end of loop test
2023-10-09 15:17 ` Jesse Brandeburg
@ 2023-10-16 10:25 ` Romanowski, Rafal
0 siblings, 0 replies; 8+ messages in thread
From: Romanowski, Rafal @ 2023-10-16 10:25 UTC (permalink / raw)
To: Brandeburg, Jesse, Dan Carpenter, Jinjie Ruan
Cc: intel-wired-lan@lists.osuosl.org, kernel-janitors@vger.kernel.org,
Eric Dumazet, Nguyen, Anthony L, Simon Horman,
netdev@vger.kernel.org, Keller, Jacob E, Jakub Kicinski,
Paolo Abeni, David S. Miller
> -----Original Message-----
> From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf Of
> Jesse Brandeburg
> Sent: Monday, October 9, 2023 5:18 PM
> To: Dan Carpenter <dan.carpenter@linaro.org>; Jinjie Ruan
> <ruanjinjie@huawei.com>
> Cc: intel-wired-lan@lists.osuosl.org; kernel-janitors@vger.kernel.org; Eric
> Dumazet <edumazet@google.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; Simon Horman <horms@kernel.org>;
> netdev@vger.kernel.org; Keller, Jacob E <jacob.e.keller@intel.com>; Jakub
> Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; David S.
> Miller <davem@davemloft.net>
> Subject: Re: [Intel-wired-lan] [PATCH net-next 1/2] igb: Fix an end of loop test
>
> On 10/5/2023 6:57 AM, Dan Carpenter wrote:
> > 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@linaro.org>
>
> Reviewed-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
>
>
> _______________________________________________
> Intel-wired-lan mailing list
> Intel-wired-lan@osuosl.org
> https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Tested-by: Rafal Romanowski <rafal.romanowski@intel.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [Intel-wired-lan] [PATCH net-next 2/2] ixgbe: fix end of loop test in ixgbe_set_vf_macvlan()
2023-10-09 15:18 ` [Intel-wired-lan] " Jesse Brandeburg
@ 2023-10-16 10:25 ` Romanowski, Rafal
0 siblings, 0 replies; 8+ messages in thread
From: Romanowski, Rafal @ 2023-10-16 10:25 UTC (permalink / raw)
To: Brandeburg, Jesse, Dan Carpenter, Jinjie Ruan
Cc: netdev@vger.kernel.org, kernel-janitors@vger.kernel.org,
Eric Dumazet, Nguyen, Anthony L, Simon Horman, Jakub Kicinski,
Keller, Jacob E, intel-wired-lan@lists.osuosl.org, Paolo Abeni,
David S. Miller
> -----Original Message-----
> From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf Of
> Jesse Brandeburg
> Sent: Monday, October 9, 2023 5:18 PM
> To: Dan Carpenter <dan.carpenter@linaro.org>; Jinjie Ruan
> <ruanjinjie@huawei.com>
> Cc: netdev@vger.kernel.org; kernel-janitors@vger.kernel.org; Eric Dumazet
> <edumazet@google.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; Simon Horman <horms@kernel.org>; Jakub
> Kicinski <kuba@kernel.org>; Keller, Jacob E <jacob.e.keller@intel.com>; intel-
> wired-lan@lists.osuosl.org; Paolo Abeni <pabeni@redhat.com>; David S.
> Miller <davem@davemloft.net>
> Subject: Re: [Intel-wired-lan] [PATCH net-next 2/2] ixgbe: fix end of loop test
> in ixgbe_set_vf_macvlan()
>
> On 10/5/2023 6:58 AM, Dan Carpenter wrote:
> > The list iterator in a list_for_each_entry() loop can never be NULL.
> > If the loop exits without hitting a break then the iterator points to
> > an offset off the list head and dereferencing it is an out of bounds
> > access.
> >
> > Before we transitioned to using list_for_each_entry() loops, then it
> > was possible for "entry" to be NULL and the comments mention this. I
> > have updated the comments to match the new code.
> >
> > Fixes: c1fec890458a ("ethernet/intel: Use list_for_each_entry()
> > helper")
> > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
>
> Reviewed-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
>
>
> _______________________________________________
> Intel-wired-lan mailing list
> Intel-wired-lan@osuosl.org
> https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Tested-by: Rafal Romanowski <rafal.romanowski@intel.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-10-16 10:25 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-05 13:57 [PATCH net-next 1/2] igb: Fix an end of loop test Dan Carpenter
2023-10-05 13:58 ` [PATCH net-next 2/2] ixgbe: fix end of loop test in ixgbe_set_vf_macvlan() Dan Carpenter
2023-10-06 11:21 ` Simon Horman
2023-10-09 15:18 ` [Intel-wired-lan] " Jesse Brandeburg
2023-10-16 10:25 ` Romanowski, Rafal
2023-10-06 11:20 ` [PATCH net-next 1/2] igb: Fix an end of loop test Simon Horman
2023-10-09 15:17 ` Jesse Brandeburg
2023-10-16 10:25 ` [Intel-wired-lan] " Romanowski, Rafal
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).