linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] gve: fix zero size queue page list allocation
@ 2022-02-14  2:41 Haiyue Wang
  2022-02-15  5:17 ` [PATCH net-next v2] gve: enhance no queue page list detection Haiyue Wang
  2022-02-15  5:21 ` [PATCH v1] gve: fix zero size queue page list allocation Jakub Kicinski
  0 siblings, 2 replies; 7+ messages in thread
From: Haiyue Wang @ 2022-02-14  2:41 UTC (permalink / raw)
  To: netdev
  Cc: Haiyue Wang, Jeroen de Borst, Catherine Sullivan,
	David Awogbemila, David S. Miller, Jakub Kicinski,
	Willem de Bruijn, Bailey Forrest, Tao Liu, Christophe JAILLET,
	John Fraker, Yangchun Fu, open list

According to the two functions 'gve_num_tx/rx_qpls', only the queue with
GVE_GQI_QPL_FORMAT format has queue page list.

The 'queue_format == GVE_GQI_RDA_FORMAT' may lead to request zero sized
memory allocation, like if the queue format is GVE_DQO_RDA_FORMAT.

The kernel memory subsystem will return ZERO_SIZE_PTR, which is not NULL
address, so the driver can run successfully. Also the code still checks
the queue page list number firstly, then accesses the allocated memory,
so zero number queue page list allocation will not lead to access fault.

Use the queue page list number to detect no QPLs, it can avoid zero size
queue page list memory allocation.

Fixes: a5886ef4f4bf ("gve: Introduce per netdev `enum gve_queue_format`")
Signed-off-by: Haiyue Wang <haiyue.wang@intel.com>
---
 drivers/net/ethernet/google/gve/gve_main.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c
index 54e51c8221b8..6cafee55efc3 100644
--- a/drivers/net/ethernet/google/gve/gve_main.c
+++ b/drivers/net/ethernet/google/gve/gve_main.c
@@ -857,8 +857,7 @@ static int gve_alloc_qpls(struct gve_priv *priv)
 	int i, j;
 	int err;
 
-	/* Raw addressing means no QPLs */
-	if (priv->queue_format == GVE_GQI_RDA_FORMAT)
+	if (num_qpls == 0)
 		return 0;
 
 	priv->qpls = kvcalloc(num_qpls, sizeof(*priv->qpls), GFP_KERNEL);
@@ -901,8 +900,7 @@ static void gve_free_qpls(struct gve_priv *priv)
 	int num_qpls = gve_num_tx_qpls(priv) + gve_num_rx_qpls(priv);
 	int i;
 
-	/* Raw addressing means no QPLs */
-	if (priv->queue_format == GVE_GQI_RDA_FORMAT)
+	if (num_qpls == 0)
 		return;
 
 	kvfree(priv->qpl_cfg.qpl_id_map);
-- 
2.35.1


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

* [PATCH net-next v2] gve: enhance no queue page list detection
  2022-02-14  2:41 [PATCH v1] gve: fix zero size queue page list allocation Haiyue Wang
@ 2022-02-15  5:17 ` Haiyue Wang
  2022-02-15 18:04   ` Bailey Forrest
  2022-02-15  5:21 ` [PATCH v1] gve: fix zero size queue page list allocation Jakub Kicinski
  1 sibling, 1 reply; 7+ messages in thread
From: Haiyue Wang @ 2022-02-15  5:17 UTC (permalink / raw)
  To: netdev
  Cc: Haiyue Wang, Jeroen de Borst, Catherine Sullivan,
	David Awogbemila, David S. Miller, Jakub Kicinski,
	Willem de Bruijn, Bailey Forrest, Christophe JAILLET, Tao Liu,
	John Fraker, Yangchun Fu, open list

The commit
a5886ef4f4bf ("gve: Introduce per netdev `enum gve_queue_format`")
introduces three queue format type, only GVE_GQI_QPL_FORMAT queue has
page list. So it should use the queue page list number to detect the
zero size queue page list. Correct the design logic.

Using the 'queue_format == GVE_GQI_RDA_FORMAT' may lead to request zero
sized memory allocation, like if the queue format is GVE_DQO_RDA_FORMAT.

The kernel memory subsystem will return ZERO_SIZE_PTR, which is not NULL
address, so the driver can run successfully. Also the code still checks
the queue page list number firstly, then accesses the allocated memory,
so zero number queue page list allocation will not lead to access fault.

Signed-off-by: Haiyue Wang <haiyue.wang@intel.com>
---
 drivers/net/ethernet/google/gve/gve_main.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c
index 54e51c8221b8..6cafee55efc3 100644
--- a/drivers/net/ethernet/google/gve/gve_main.c
+++ b/drivers/net/ethernet/google/gve/gve_main.c
@@ -857,8 +857,7 @@ static int gve_alloc_qpls(struct gve_priv *priv)
 	int i, j;
 	int err;
 
-	/* Raw addressing means no QPLs */
-	if (priv->queue_format == GVE_GQI_RDA_FORMAT)
+	if (num_qpls == 0)
 		return 0;
 
 	priv->qpls = kvcalloc(num_qpls, sizeof(*priv->qpls), GFP_KERNEL);
@@ -901,8 +900,7 @@ static void gve_free_qpls(struct gve_priv *priv)
 	int num_qpls = gve_num_tx_qpls(priv) + gve_num_rx_qpls(priv);
 	int i;
 
-	/* Raw addressing means no QPLs */
-	if (priv->queue_format == GVE_GQI_RDA_FORMAT)
+	if (num_qpls == 0)
 		return;
 
 	kvfree(priv->qpl_cfg.qpl_id_map);
-- 
2.35.1


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

* Re: [PATCH v1] gve: fix zero size queue page list allocation
  2022-02-14  2:41 [PATCH v1] gve: fix zero size queue page list allocation Haiyue Wang
  2022-02-15  5:17 ` [PATCH net-next v2] gve: enhance no queue page list detection Haiyue Wang
@ 2022-02-15  5:21 ` Jakub Kicinski
  2022-02-15  5:25   ` Wang, Haiyue
  1 sibling, 1 reply; 7+ messages in thread
From: Jakub Kicinski @ 2022-02-15  5:21 UTC (permalink / raw)
  To: Haiyue Wang
  Cc: netdev, Jeroen de Borst, Catherine Sullivan, David Awogbemila,
	David S. Miller, Willem de Bruijn, Bailey Forrest, Tao Liu,
	Christophe JAILLET, John Fraker, Yangchun Fu, open list

On Mon, 14 Feb 2022 10:41:29 +0800 Haiyue Wang wrote:
> According to the two functions 'gve_num_tx/rx_qpls', only the queue with
> GVE_GQI_QPL_FORMAT format has queue page list.
> 
> The 'queue_format == GVE_GQI_RDA_FORMAT' may lead to request zero sized
> memory allocation, like if the queue format is GVE_DQO_RDA_FORMAT.
> 
> The kernel memory subsystem will return ZERO_SIZE_PTR, which is not NULL
> address, so the driver can run successfully. Also the code still checks
> the queue page list number firstly, then accesses the allocated memory,
> so zero number queue page list allocation will not lead to access fault.
> 
> Use the queue page list number to detect no QPLs, it can avoid zero size
> queue page list memory allocation.

There's no bug here, strictly speaking, the driver will function
correctly? In that case please repost without the Fixes tag and
with [PATCH net-next] in the subject.

> Fixes: a5886ef4f4bf ("gve: Introduce per netdev `enum gve_queue_format`")
> Signed-off-by: Haiyue Wang <haiyue.wang@intel.com>

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

* RE: [PATCH v1] gve: fix zero size queue page list allocation
  2022-02-15  5:21 ` [PATCH v1] gve: fix zero size queue page list allocation Jakub Kicinski
@ 2022-02-15  5:25   ` Wang, Haiyue
  2022-02-15  5:31     ` Jakub Kicinski
  0 siblings, 1 reply; 7+ messages in thread
From: Wang, Haiyue @ 2022-02-15  5:25 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: netdev, Jeroen de Borst, Catherine Sullivan, David Awogbemila,
	David S. Miller, Willem de Bruijn, Forrest, Bailey, Tao Liu,
	Christophe JAILLET, John Fraker, Yangchun Fu, open list

> -----Original Message-----
> From: Jakub Kicinski <kuba@kernel.org>
> Sent: Tuesday, February 15, 2022 13:22
> To: Wang, Haiyue <haiyue.wang@intel.com>
> Cc: netdev@vger.kernel.org; Jeroen de Borst <jeroendb@google.com>; Catherine Sullivan
> <csully@google.com>; David Awogbemila <awogbemila@google.com>; David S. Miller <davem@davemloft.net>;
> Willem de Bruijn <willemb@google.com>; Forrest, Bailey <bcf@google.com>; Tao Liu <xliutaox@google.com>;
> Christophe JAILLET <christophe.jaillet@wanadoo.fr>; John Fraker <jfraker@google.com>; Yangchun Fu
> <yangchun@google.com>; open list <linux-kernel@vger.kernel.org>
> Subject: Re: [PATCH v1] gve: fix zero size queue page list allocation
> 
> On Mon, 14 Feb 2022 10:41:29 +0800 Haiyue Wang wrote:
> > According to the two functions 'gve_num_tx/rx_qpls', only the queue with
> > GVE_GQI_QPL_FORMAT format has queue page list.
> >
> > The 'queue_format == GVE_GQI_RDA_FORMAT' may lead to request zero sized
> > memory allocation, like if the queue format is GVE_DQO_RDA_FORMAT.
> >
> > The kernel memory subsystem will return ZERO_SIZE_PTR, which is not NULL
> > address, so the driver can run successfully. Also the code still checks
> > the queue page list number firstly, then accesses the allocated memory,
> > so zero number queue page list allocation will not lead to access fault.
> >
> > Use the queue page list number to detect no QPLs, it can avoid zero size
> > queue page list memory allocation.
> 
> There's no bug here, strictly speaking, the driver will function
> correctly? In that case please repost without the Fixes tag and

Code design bug, the 'queue_format == GVE_GQI_RDA_FORMAT' is not correct. But,
yes, it works. So still need to remove the tag ?

> with [PATCH net-next] in the subject.
> 
> > Fixes: a5886ef4f4bf ("gve: Introduce per netdev `enum gve_queue_format`")
> > Signed-off-by: Haiyue Wang <haiyue.wang@intel.com>

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

* Re: [PATCH v1] gve: fix zero size queue page list allocation
  2022-02-15  5:25   ` Wang, Haiyue
@ 2022-02-15  5:31     ` Jakub Kicinski
  2022-02-15  5:34       ` Wang, Haiyue
  0 siblings, 1 reply; 7+ messages in thread
From: Jakub Kicinski @ 2022-02-15  5:31 UTC (permalink / raw)
  To: Wang, Haiyue
  Cc: netdev, Jeroen de Borst, Catherine Sullivan, David Awogbemila,
	David S. Miller, Willem de Bruijn, Forrest, Bailey, Tao Liu,
	Christophe JAILLET, John Fraker, Yangchun Fu, open list

On Tue, 15 Feb 2022 05:25:49 +0000 Wang, Haiyue wrote:
> > On Mon, 14 Feb 2022 10:41:29 +0800 Haiyue Wang wrote:  
> > > According to the two functions 'gve_num_tx/rx_qpls', only the queue with
> > > GVE_GQI_QPL_FORMAT format has queue page list.
> > >
> > > The 'queue_format == GVE_GQI_RDA_FORMAT' may lead to request zero sized
> > > memory allocation, like if the queue format is GVE_DQO_RDA_FORMAT.
> > >
> > > The kernel memory subsystem will return ZERO_SIZE_PTR, which is not NULL
> > > address, so the driver can run successfully. Also the code still checks
> > > the queue page list number firstly, then accesses the allocated memory,
> > > so zero number queue page list allocation will not lead to access fault.
> > >
> > > Use the queue page list number to detect no QPLs, it can avoid zero size
> > > queue page list memory allocation.  
> > 
> > There's no bug here, strictly speaking, the driver will function
> > correctly? In that case please repost without the Fixes tag and  
> 
> Code design bug, the 'queue_format == GVE_GQI_RDA_FORMAT' is not correct. But,
> yes, it works. So still need to remove the tag ?

A bug is something that users can notice. If there are conditions under
which this may lead to user-visible mis-behavior then we should keep
the tag and send the patch to stable as well.

If there is no user-visible problem here, then the patch is just
future-proofing / refactoring and we should not risk introducing real
bugs by making people backport it (which is what adding a Fixes will
do).

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

* RE: [PATCH v1] gve: fix zero size queue page list allocation
  2022-02-15  5:31     ` Jakub Kicinski
@ 2022-02-15  5:34       ` Wang, Haiyue
  0 siblings, 0 replies; 7+ messages in thread
From: Wang, Haiyue @ 2022-02-15  5:34 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: netdev, Jeroen de Borst, Catherine Sullivan, David Awogbemila,
	David S. Miller, Willem de Bruijn, Forrest, Bailey, Tao Liu,
	Christophe JAILLET, John Fraker, Yangchun Fu, open list

> -----Original Message-----
> From: Jakub Kicinski <kuba@kernel.org>
> Sent: Tuesday, February 15, 2022 13:31
> To: Wang, Haiyue <haiyue.wang@intel.com>
> Cc: netdev@vger.kernel.org; Jeroen de Borst <jeroendb@google.com>; Catherine Sullivan
> <csully@google.com>; David Awogbemila <awogbemila@google.com>; David S. Miller <davem@davemloft.net>;
> Willem de Bruijn <willemb@google.com>; Forrest, Bailey <bcf@google.com>; Tao Liu <xliutaox@google.com>;
> Christophe JAILLET <christophe.jaillet@wanadoo.fr>; John Fraker <jfraker@google.com>; Yangchun Fu
> <yangchun@google.com>; open list <linux-kernel@vger.kernel.org>
> Subject: Re: [PATCH v1] gve: fix zero size queue page list allocation
> 
> On Tue, 15 Feb 2022 05:25:49 +0000 Wang, Haiyue wrote:
> > > On Mon, 14 Feb 2022 10:41:29 +0800 Haiyue Wang wrote:
> > > > According to the two functions 'gve_num_tx/rx_qpls', only the queue with
> > > > GVE_GQI_QPL_FORMAT format has queue page list.
> > > >
> > > > The 'queue_format == GVE_GQI_RDA_FORMAT' may lead to request zero sized
> > > > memory allocation, like if the queue format is GVE_DQO_RDA_FORMAT.
> > > >
> > > > The kernel memory subsystem will return ZERO_SIZE_PTR, which is not NULL
> > > > address, so the driver can run successfully. Also the code still checks
> > > > the queue page list number firstly, then accesses the allocated memory,
> > > > so zero number queue page list allocation will not lead to access fault.
> > > >
> > > > Use the queue page list number to detect no QPLs, it can avoid zero size
> > > > queue page list memory allocation.
> > >
> > > There's no bug here, strictly speaking, the driver will function
> > > correctly? In that case please repost without the Fixes tag and
> >
> > Code design bug, the 'queue_format == GVE_GQI_RDA_FORMAT' is not correct. But,
> > yes, it works. So still need to remove the tag ?
> 
> A bug is something that users can notice. If there are conditions under
> which this may lead to user-visible mis-behavior then we should keep
> the tag and send the patch to stable as well.
> 
> If there is no user-visible problem here, then the patch is just
> future-proofing / refactoring and we should not risk introducing real
> bugs by making people backport it (which is what adding a Fixes will
> do).

OK. Will remove the tag in v2.

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

* Re: [PATCH net-next v2] gve: enhance no queue page list detection
  2022-02-15  5:17 ` [PATCH net-next v2] gve: enhance no queue page list detection Haiyue Wang
@ 2022-02-15 18:04   ` Bailey Forrest
  0 siblings, 0 replies; 7+ messages in thread
From: Bailey Forrest @ 2022-02-15 18:04 UTC (permalink / raw)
  To: Haiyue Wang
  Cc: Networking, Jeroen de Borst, Catherine Sullivan,
	David Awogbemila, David S. Miller, Jakub Kicinski,
	Willem de Bruijn, Christophe JAILLET, Tao Liu, John Fraker,
	Yangchun Fu, open list

On Mon, Feb 14, 2022 at 9:52 PM Haiyue Wang <haiyue.wang@intel.com> wrote:
>
> The commit
> a5886ef4f4bf ("gve: Introduce per netdev `enum gve_queue_format`")
> introduces three queue format type, only GVE_GQI_QPL_FORMAT queue has
> page list. So it should use the queue page list number to detect the
> zero size queue page list. Correct the design logic.
>
> Using the 'queue_format == GVE_GQI_RDA_FORMAT' may lead to request zero
> sized memory allocation, like if the queue format is GVE_DQO_RDA_FORMAT.
>
> The kernel memory subsystem will return ZERO_SIZE_PTR, which is not NULL
> address, so the driver can run successfully. Also the code still checks
> the queue page list number firstly, then accesses the allocated memory,
> so zero number queue page list allocation will not lead to access fault.
>
> Signed-off-by: Haiyue Wang <haiyue.wang@intel.com>

Reviewed-by: Bailey Forrest <bcf@google.com>

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

end of thread, other threads:[~2022-02-15 18:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-14  2:41 [PATCH v1] gve: fix zero size queue page list allocation Haiyue Wang
2022-02-15  5:17 ` [PATCH net-next v2] gve: enhance no queue page list detection Haiyue Wang
2022-02-15 18:04   ` Bailey Forrest
2022-02-15  5:21 ` [PATCH v1] gve: fix zero size queue page list allocation Jakub Kicinski
2022-02-15  5:25   ` Wang, Haiyue
2022-02-15  5:31     ` Jakub Kicinski
2022-02-15  5:34       ` Wang, Haiyue

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).