lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 18 Nov 2019 20:47:02 +0000
From:   Michael Kelley <mikelley@...rosoft.com>
To:     Haiyang Zhang <haiyangz@...rosoft.com>,
        vkuznets <vkuznets@...hat.com>
CC:     KY Srinivasan <kys@...rosoft.com>,
        Stephen Hemminger <sthemmin@...rosoft.com>,
        "olaf@...fle.de" <olaf@...fle.de>,
        "davem@...emloft.net" <davem@...emloft.net>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "sashal@...nel.org" <sashal@...nel.org>,
        "linux-hyperv@...r.kernel.org" <linux-hyperv@...r.kernel.org>,
        "netdev@...r.kernel.org" <netdev@...r.kernel.org>
Subject: RE: [PATCH net, 1/2] hv_netvsc: Fix offset usage in
 netvsc_send_table()

From: Haiyang Zhang <haiyangz@...rosoft.com> Sent: Monday, November 18, 2019 10:40 AM
> > -----Original Message-----
> > From: Vitaly Kuznetsov <vkuznets@...hat.com>
> > Sent: Monday, November 18, 2019 12:29 PM
> >
> > Haiyang Zhang <haiyangz@...rosoft.com> writes:
> >
> > > To reach the data region, the existing code adds offset in struct
> > > nvsp_5_send_indirect_table on the beginning of this struct. But the
> > > offset should be based on the beginning of its container,
> > > struct nvsp_message. This bug causes the first table entry missing,
> > > and adds an extra zero from the zero pad after the data region.
> > > This can put extra burden on the channel 0.
> > >
> > > So, correct the offset usage. Also add a boundary check to ensure
> > > not reading beyond data region.
> > >
> > > Fixes: 5b54dac856cb ("hyperv: Add support for virtual Receive Side Scaling
> > (vRSS)")
> > > Signed-off-by: Haiyang Zhang <haiyangz@...rosoft.com>
> > > ---
> > >  drivers/net/hyperv/hyperv_net.h |  3 ++-
> > >  drivers/net/hyperv/netvsc.c     | 26 ++++++++++++++++++--------
> > >  2 files changed, 20 insertions(+), 9 deletions(-)
> > >
> > > diff --git a/drivers/net/hyperv/hyperv_net.h
> > b/drivers/net/hyperv/hyperv_net.h
> > > index 670ef68..fb547f3 100644
> > > --- a/drivers/net/hyperv/hyperv_net.h
> > > +++ b/drivers/net/hyperv/hyperv_net.h
> > > @@ -609,7 +609,8 @@ struct nvsp_5_send_indirect_table {
> > >  	/* The number of entries in the send indirection table */
> > >  	u32 count;
> > >
> > > -	/* The offset of the send indirection table from top of this struct.
> > > +	/* The offset of the send indirection table from the beginning of
> > > +	 * struct nvsp_message.
> > >  	 * The send indirection table tells which channel to put the send
> > >  	 * traffic on. Each entry is a channel number.
> > >  	 */
> > > diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
> > > index d22a36f..efd30e2 100644
> > > --- a/drivers/net/hyperv/netvsc.c
> > > +++ b/drivers/net/hyperv/netvsc.c
> > > @@ -1178,20 +1178,28 @@ static int netvsc_receive(struct net_device *ndev,
> > >  }
> > >
> > >  static void netvsc_send_table(struct net_device *ndev,
> > > -			      const struct nvsp_message *nvmsg)
> > > +			      const struct nvsp_message *nvmsg,
> > > +			      u32 msglen)
> > >  {
> > >  	struct net_device_context *net_device_ctx = netdev_priv(ndev);
> > > -	u32 count, *tab;
> > > +	u32 count, offset, *tab;
> > >  	int i;
> > >
> > >  	count = nvmsg->msg.v5_msg.send_table.count;
> > > +	offset = nvmsg->msg.v5_msg.send_table.offset;
> > > +
> > >  	if (count != VRSS_SEND_TAB_SIZE) {
> > >  		netdev_err(ndev, "Received wrong send-table size:%u\n",
> > count);
> > >  		return;
> > >  	}
> > >
> > > -	tab = (u32 *)((unsigned long)&nvmsg->msg.v5_msg.send_table +
> > > -		      nvmsg->msg.v5_msg.send_table.offset);
> > > +	if (offset + count * sizeof(u32) > msglen) {
> >
> > Nit: I think this can overflow.
> 
> To prevent overflow, I will change it to:
> 	if (offset > msglen || offset + count * sizeof(u32) > msglen) {
> Thanks,
> - Haiyang

Actually, this would be simpler since we already trust msglen and count
to have good values:

	if (offset > msglen - count * sizeof(u32)) {

Michael


Powered by blists - more mailing lists