All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ibmveth: Fix off-by-one error in ibmveth_change_mtu()
@ 2015-04-13  5:39 ` David Gibson
  0 siblings, 0 replies; 4+ messages in thread
From: David Gibson @ 2015-04-13  5:39 UTC (permalink / raw)
  To: anton, benh, michael; +Cc: linuxppc-dev, linux-kernel, David Gibson

AFAIK the PAPR document which defines the virtual device interface used by
the ibmveth driver doesn't specify a specific maximum MTU.  So, in the
ibmveth driver, the maximum allowed MTU is determined by the maximum
allocated buffer size of 64k (corresponding to one page in the common case)
minus the per-buffer overhead IBMVETH_BUFF_OH (which has value 22 for 14
bytes of ethernet header, plus 8 bytes for an opaque handle).

This suggests a maximum allowable MTU of 65514 bytes, but in fact the
driver only permits a maximum MTU of 65513.  This is because there is a <
instead of an <= in ibmveth_change_mtu(), which only permits an MTU which
is strictly smaller than the buffer size, rather than allowing the buffer
to be completely filled.

This patch fixes the buglet.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 drivers/net/ethernet/ibm/ibmveth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
index cd7675a..3aa280a 100644
--- a/drivers/net/ethernet/ibm/ibmveth.c
+++ b/drivers/net/ethernet/ibm/ibmveth.c
@@ -1257,7 +1257,7 @@ static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)
 	for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) {
 		adapter->rx_buff_pool[i].active = 1;
 
-		if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) {
+		if (new_mtu_oh <= adapter->rx_buff_pool[i].buff_size) {
 			dev->mtu = new_mtu;
 			vio_cmo_set_dev_desired(viodev,
 						ibmveth_get_desired_dma
-- 
2.1.0


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

* [PATCH] ibmveth: Fix off-by-one error in ibmveth_change_mtu()
@ 2015-04-13  5:39 ` David Gibson
  0 siblings, 0 replies; 4+ messages in thread
From: David Gibson @ 2015-04-13  5:39 UTC (permalink / raw)
  To: anton, benh, michael; +Cc: linux-kernel, linuxppc-dev, David Gibson

AFAIK the PAPR document which defines the virtual device interface used by
the ibmveth driver doesn't specify a specific maximum MTU.  So, in the
ibmveth driver, the maximum allowed MTU is determined by the maximum
allocated buffer size of 64k (corresponding to one page in the common case)
minus the per-buffer overhead IBMVETH_BUFF_OH (which has value 22 for 14
bytes of ethernet header, plus 8 bytes for an opaque handle).

This suggests a maximum allowable MTU of 65514 bytes, but in fact the
driver only permits a maximum MTU of 65513.  This is because there is a <
instead of an <= in ibmveth_change_mtu(), which only permits an MTU which
is strictly smaller than the buffer size, rather than allowing the buffer
to be completely filled.

This patch fixes the buglet.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 drivers/net/ethernet/ibm/ibmveth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
index cd7675a..3aa280a 100644
--- a/drivers/net/ethernet/ibm/ibmveth.c
+++ b/drivers/net/ethernet/ibm/ibmveth.c
@@ -1257,7 +1257,7 @@ static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)
 	for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) {
 		adapter->rx_buff_pool[i].active = 1;
 
-		if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) {
+		if (new_mtu_oh <= adapter->rx_buff_pool[i].buff_size) {
 			dev->mtu = new_mtu;
 			vio_cmo_set_dev_desired(viodev,
 						ibmveth_get_desired_dma
-- 
2.1.0

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

* Re: [PATCH] ibmveth: Fix off-by-one error in ibmveth_change_mtu()
  2015-04-13  5:39 ` David Gibson
  (?)
@ 2015-04-14 15:33 ` Thomas Falcon
  2015-04-16  5:15   ` David Gibson
  -1 siblings, 1 reply; 4+ messages in thread
From: Thomas Falcon @ 2015-04-14 15:33 UTC (permalink / raw)
  To: David Gibson, anton, benh, michael; +Cc: linux-kernel, linuxppc-dev

On 04/13/2015 12:39 AM, David Gibson wrote:
> AFAIK the PAPR document which defines the virtual device interface used by
> the ibmveth driver doesn't specify a specific maximum MTU.  So, in the
> ibmveth driver, the maximum allowed MTU is determined by the maximum
> allocated buffer size of 64k (corresponding to one page in the common case)
> minus the per-buffer overhead IBMVETH_BUFF_OH (which has value 22 for 14
> bytes of ethernet header, plus 8 bytes for an opaque handle).
>
> This suggests a maximum allowable MTU of 65514 bytes, but in fact the
> driver only permits a maximum MTU of 65513.  This is because there is a <
> instead of an <= in ibmveth_change_mtu(), which only permits an MTU which
> is strictly smaller than the buffer size, rather than allowing the buffer
> to be completely filled.
>
> This patch fixes the buglet.


The same expression is made using < just a few lines above.  Shouldn't this be changed to <= too?

@@ -1238,7 +1238,7 @@ static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)
                return -EINVAL;
 
        for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++)
-               if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size)
+               if (new_mtu_oh <= adapter->rx_buff_pool[i].buff_size)
                        break;
 
        if (i == IBMVETH_NUM_BUFF_POOLS)

Thanks,

Tom
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> ---
>  drivers/net/ethernet/ibm/ibmveth.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
> index cd7675a..3aa280a 100644
> --- a/drivers/net/ethernet/ibm/ibmveth.c
> +++ b/drivers/net/ethernet/ibm/ibmveth.c
> @@ -1257,7 +1257,7 @@ static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)
>  	for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) {
>  		adapter->rx_buff_pool[i].active = 1;
>  
> -		if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) {
> +		if (new_mtu_oh <= adapter->rx_buff_pool[i].buff_size) {
>  			dev->mtu = new_mtu;
>  			vio_cmo_set_dev_desired(viodev,
>  						ibmveth_get_desired_dma


-- 
Tom Falcon
Software Engineer
IBM LTC Austin


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

* Re: [PATCH] ibmveth: Fix off-by-one error in ibmveth_change_mtu()
  2015-04-14 15:33 ` Thomas Falcon
@ 2015-04-16  5:15   ` David Gibson
  0 siblings, 0 replies; 4+ messages in thread
From: David Gibson @ 2015-04-16  5:15 UTC (permalink / raw)
  To: Thomas Falcon; +Cc: anton, benh, michael, linux-kernel, linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 1724 bytes --]

On Tue, Apr 14, 2015 at 10:33:18AM -0500, Thomas Falcon wrote:
> On 04/13/2015 12:39 AM, David Gibson wrote:
> > AFAIK the PAPR document which defines the virtual device interface used by
> > the ibmveth driver doesn't specify a specific maximum MTU.  So, in the
> > ibmveth driver, the maximum allowed MTU is determined by the maximum
> > allocated buffer size of 64k (corresponding to one page in the common case)
> > minus the per-buffer overhead IBMVETH_BUFF_OH (which has value 22 for 14
> > bytes of ethernet header, plus 8 bytes for an opaque handle).
> >
> > This suggests a maximum allowable MTU of 65514 bytes, but in fact the
> > driver only permits a maximum MTU of 65513.  This is because there is a <
> > instead of an <= in ibmveth_change_mtu(), which only permits an MTU which
> > is strictly smaller than the buffer size, rather than allowing the buffer
> > to be completely filled.
> >
> > This patch fixes the buglet.
> 
> 
> The same expression is made using < just a few lines above.  Shouldn't this be changed to <= too?
> 
> @@ -1238,7 +1238,7 @@ static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)
>                 return -EINVAL;
>  
>         for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++)
> -               if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size)
> +               if (new_mtu_oh <= adapter->rx_buff_pool[i].buff_size)
>                         break;
>  
>         if (i == IBMVETH_NUM_BUFF_POOLS)

Yes, yes it should.

Good catch, thanks.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

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

end of thread, other threads:[~2015-04-16  5:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-13  5:39 [PATCH] ibmveth: Fix off-by-one error in ibmveth_change_mtu() David Gibson
2015-04-13  5:39 ` David Gibson
2015-04-14 15:33 ` Thomas Falcon
2015-04-16  5:15   ` David Gibson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.