Skip to contentSkip to conversation

ixgbe: add array bounds check

PATCH New Paul Greenwalt 3 participants 7 messages Oct 23, 2017 – Oct 25, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ixgbe: add array bounds check

Add bounds check for index fcoe_i of rx_ring array.

---
 drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c +2 -0
index a23c2b5..5772fe2 100644
@@ -698,6 +698,8 @@ void ixgbe_configure_fcoe(struct ixgbe_adapter *adapter)
 		}
 
 		fcoe_i = fcoe->offset + (i % fcoe->indices);
+		if (fcoe_i >= MAX_RX_QUEUES)
+			fcoe_i = MAX_RX_QUEUES - 1;
 		fcoe_i &= IXGBE_FCRETA_ENTRY_MASK;
 		fcoe_q = adapter->rx_ring[fcoe_i]->reg_idx;
 		fcoe_q |= fcoe_q_h;
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 ixgbe: add array bounds check

Quoted 12 lines · Paul Greenwalt

Add bounds check for index fcoe_i of rx_ring array.

---
 drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c +0 -0
index a23c2b5..5772fe2 100644

drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c void ixgbe_configure_fcoe(struct ixgbe_adapter *adapter) · line 702

Quoted 5 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c +2 -0
@@ -698,6 +698,8 @@ void ixgbe_configure_fcoe(struct ixgbe_adapter *adapter)
                }
 
                fcoe_i = fcoe->offset + (i % fcoe->indices);
+               if (fcoe_i >= MAX_RX_QUEUES)
+                       fcoe_i = MAX_RX_QUEUES - 1;

Instead of using MAX_RX_QUEUES why use fcoe->limit? If I am not mistake the upper limit is either 8 or 32 for the FCoE redirection table anyway so odds are you can't even use 64 queues if you wanted to. From what I can tell the only advantage of the approach you are using now is that you don't potentially zero out the value when it gets hit with the mask below.

Quoted 10 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c +0 -1
                fcoe_i &= IXGBE_FCRETA_ENTRY_MASK;
                fcoe_q = adapter->rx_ring[fcoe_i]->reg_idx;
                fcoe_q |= fcoe_q_h;
--

2.7.4

_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan at osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

#2 lore raw

PATCH 1/1 ixgbe: add array bounds check

Quoted 30 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Alexander Duyck
Sent: Tuesday, October 24, 2017 9:20 AM
To: Greenwalt, Paul <[email protected]>
Cc: intel-wired-lan <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH] ixgbe: add array bounds check

Review

Quoted 8 lines · Paul Greenwalt

Add bounds check for index fcoe_i of rx_ring array.

---
 drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c | 2 ++
 1 file changed, 2 insertions(+)
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c

drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c void ixgbe_configure_fcoe(struct ixgbe_adapter

Quoted 4 lines

index a23c2b5..5772fe2 100644

drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c +0 -0
@@ -698,6 +698,8 @@ void ixgbe_configure_fcoe(struct ixgbe_adapter

*adapter)

drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c void ixgbe_configure_fcoe(struct ixgbe_adapter *adapter) · line 702

Quoted 5 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c +2 -0
                }
 
                fcoe_i = fcoe->offset + (i % fcoe->indices);
+               if (fcoe_i >= MAX_RX_QUEUES)
+                       fcoe_i = MAX_RX_QUEUES - 1;
Quoted 8 lines

Instead of using MAX_RX_QUEUES why use fcoe->limit? If I am not mistake the upper limit is either 8 or 32 for the FCoE redirection table anyway so odds are you can't even use 64 queues if you wanted to. From what I can tell the only advantage of the approach you are using now is that you don't potentially zero out the value when it gets hit with the mask below.

Quoted 1 line
drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c +0 -0
                fcoe_i &= IXGBE_FCRETA_ENTRY_MASK;

Actually the check is added to protect from accessing rx_ring[fcoe_i] beyond it's boundaries. The above line was supposed to be removed. This is because IXGBE_FCRETA_ENTRY_MASK = 0x7f, and static checkers report possible out of bounds issue.

Thanks,
Emil

#3 lore raw

PATCH 1/1 ixgbe: add array bounds check

Quoted 39 lines · Emil S
Quoted 30 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Alexander Duyck
Sent: Tuesday, October 24, 2017 9:20 AM
To: Greenwalt, Paul <[email protected]>
Cc: intel-wired-lan <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH] ixgbe: add array bounds check

Review

Quoted 8 lines · Paul Greenwalt

Add bounds check for index fcoe_i of rx_ring array.

---
 drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c | 2 ++
 1 file changed, 2 insertions(+)
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c

drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c void ixgbe_configure_fcoe(struct ixgbe_adapter

Quoted 4 lines

index a23c2b5..5772fe2 100644

drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c +0 -0
@@ -698,6 +698,8 @@ void ixgbe_configure_fcoe(struct ixgbe_adapter

*adapter)

drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c void ixgbe_configure_fcoe(struct ixgbe_adapter *adapter) · line 702

Quoted 5 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c +2 -0
                }
 
                fcoe_i = fcoe->offset + (i % fcoe->indices);
+               if (fcoe_i >= MAX_RX_QUEUES)
+                       fcoe_i = MAX_RX_QUEUES - 1;
Quoted 8 lines

Instead of using MAX_RX_QUEUES why use fcoe->limit? If I am not mistake the upper limit is either 8 or 32 for the FCoE redirection table anyway so odds are you can't even use 64 queues if you wanted to. From what I can tell the only advantage of the approach you are using now is that you don't potentially zero out the value when it gets hit with the mask below.

Quoted 1 line
drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c +0 -0
                fcoe_i &= IXGBE_FCRETA_ENTRY_MASK;
Quoted 7 lines

Actually the check is added to protect from accessing rx_ring[fcoe_i] beyond it's boundaries. The above line was supposed to be removed. This is because IXGBE_FCRETA_ENTRY_MASK = 0x7f, and static checkers report possible out of bounds issue.

Thanks,
Emil

So is this actually fixing a bug, or just making some static analysis tool happy? If it is about a static analysis tool I would stay just identify it as a false hit since this value should be configured and limited by the code in ixgbe_lib.c that is configuring the offset and indices.

Thanks.

- Alex

#4 lore raw

PATCH 1/1 ixgbe: add array bounds check

Quoted 57 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Alexander Duyck
Sent: Tuesday, October 24, 2017 11:49 AM
To: Tantilov, Emil S <[email protected]>
Cc: intel-wired-lan <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH] ixgbe: add array bounds check

Quoted 37 lines · Emil S
Quoted 37 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Alexander Duyck
Sent: Tuesday, October 24, 2017 9:20 AM
To: Greenwalt, Paul <[email protected]>
Cc: intel-wired-lan <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH] ixgbe: add array bounds check

Review

Quoted 8 lines · Paul Greenwalt

Add bounds check for index fcoe_i of rx_ring array.

---
 drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c | 2 ++
 1 file changed, 2 insertions(+)
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c

drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c void ixgbe_configure_fcoe(struct ixgbe_adapter

Quoted 4 lines

index a23c2b5..5772fe2 100644

drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c +0 -0
@@ -698,6 +698,8 @@ void ixgbe_configure_fcoe(struct ixgbe_adapter

*adapter)

drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c void ixgbe_configure_fcoe(struct ixgbe_adapter *adapter) · line 702

Quoted 5 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c +2 -0
                }
 
                fcoe_i = fcoe->offset + (i % fcoe->indices);
+               if (fcoe_i >= MAX_RX_QUEUES)
+                       fcoe_i = MAX_RX_QUEUES - 1;

Instead of using MAX_RX_QUEUES why use fcoe->limit? If I am not mistake the upper limit is either 8 or 32 for the FCoE redirection table anyway so odds are you can't even use 64 queues if you wanted to. From what I can tell the only advantage of the approach you are using now is that you don't potentially zero out the value when it gets hit with the mask below.

Quoted 3 lines
Quoted 1 line

drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c void ixgbe_configure_fcoe(struct ixgbe_adapter *adapter) · line 703

Quoted 1 line
drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c +0 -0
                fcoe_i &= IXGBE_FCRETA_ENTRY_MASK;

Actually the check is added to protect from accessing rx_ring[fcoe_i]

beyond

Quoted 1 line

it's boundaries. The above line was supposed to be removed. This is

because

Quoted 1 line

IXGBE_FCRETA_ENTRY_MASK = 0x7f, and static checkers report possible

out of

Quoted 2 lines

bounds issue.

Quoted 8 lines
Quoted 2 lines

Thanks,
Emil

So is this actually fixing a bug, or just making some static analysis tool happy? If it is about a static analysis tool I would stay just identify it as a false hit since this value should be configured and limited by the code in ixgbe_lib.c that is configuring the offset and indices.

It's a bit of both in my opinion since the line limiting the value of fcoe_i:

	fcoe_i &= IXGBE_FCRETA_ENTRY_MASK;

Is clearly wrong since IXGBE_FCRETA_ENTRY_MASK exceeds MAX_RX_QUEUES.

Why even do this if we are sure that the limits are enforced in some other part of the code?

Thanks,
Emil

#5 lore raw

PATCH 1/1 ixgbe: add array bounds check

Quoted 65 lines · Emil S
Quoted 57 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Alexander Duyck
Sent: Tuesday, October 24, 2017 11:49 AM
To: Tantilov, Emil S <[email protected]>
Cc: intel-wired-lan <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH] ixgbe: add array bounds check

Quoted 37 lines · Emil S
Quoted 37 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Alexander Duyck
Sent: Tuesday, October 24, 2017 9:20 AM
To: Greenwalt, Paul <[email protected]>
Cc: intel-wired-lan <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH] ixgbe: add array bounds check

Review

Quoted 8 lines · Paul Greenwalt

Add bounds check for index fcoe_i of rx_ring array.

---
 drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c | 2 ++
 1 file changed, 2 insertions(+)
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c

drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c void ixgbe_configure_fcoe(struct ixgbe_adapter

Quoted 4 lines

index a23c2b5..5772fe2 100644

drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c +0 -0
@@ -698,6 +698,8 @@ void ixgbe_configure_fcoe(struct ixgbe_adapter

*adapter)

drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c void ixgbe_configure_fcoe(struct ixgbe_adapter *adapter) · line 702

Quoted 5 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c +2 -0
                }
 
                fcoe_i = fcoe->offset + (i % fcoe->indices);
+               if (fcoe_i >= MAX_RX_QUEUES)
+                       fcoe_i = MAX_RX_QUEUES - 1;

Instead of using MAX_RX_QUEUES why use fcoe->limit? If I am not mistake the upper limit is either 8 or 32 for the FCoE redirection table anyway so odds are you can't even use 64 queues if you wanted to. From what I can tell the only advantage of the approach you are using now is that you don't potentially zero out the value when it gets hit with the mask below.

Quoted 3 lines
Quoted 1 line

drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c void ixgbe_configure_fcoe(struct ixgbe_adapter *adapter) · line 703

Quoted 1 line
drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c +0 -0
                fcoe_i &= IXGBE_FCRETA_ENTRY_MASK;

Actually the check is added to protect from accessing rx_ring[fcoe_i]

beyond

Quoted 1 line

it's boundaries. The above line was supposed to be removed. This is

because

Quoted 1 line

IXGBE_FCRETA_ENTRY_MASK = 0x7f, and static checkers report possible

out of

Quoted 2 lines

bounds issue.

Quoted 8 lines
Quoted 2 lines

Thanks,
Emil

So is this actually fixing a bug, or just making some static analysis tool happy? If it is about a static analysis tool I would stay just identify it as a false hit since this value should be configured and limited by the code in ixgbe_lib.c that is configuring the offset and indices.

Quoted 8 lines

It's a bit of both in my opinion since the line limiting the value of fcoe_i:

        fcoe_i &= IXGBE_FCRETA_ENTRY_MASK;

Is clearly wrong since IXGBE_FCRETA_ENTRY_MASK exceeds MAX_RX_QUEUES.

Why even do this if we are sure that the limits are enforced in some other part of the code?

That is a very good question. Odds are that line isn't the correct solution for this either. The thing we need to mask is actually fcoe_q which isn't defined until a few lines lower down.

We should probably just be making certain that fcoe->offset + fcoe->indices cannot exceed the maximum ring size which I think we already do. We would probably be better off handling/verifying this is occuring in ixgbe_lib.c where we configure RING_F_FCOE.

- Alex

#6 lore raw

PATCH 1/1 ixgbe: add array bounds check

In reply to Paul Greenwalt
Quoted 7 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Paul Greenwalt
Sent: Monday, October 23, 2017 8:22 AM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH] ixgbe: add array bounds check

Quoted 6 lines

Add bounds check for index fcoe_i of rx_ring array.

---
 drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c | 2 ++
 1 file changed, 2 insertions(+)