Return-Path: Received: from mail-sn1nam02on0118.outbound.protection.outlook.com ([104.47.36.118]:9930 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932574AbeARVEa (ORCPT ); Thu, 18 Jan 2018 16:04:30 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Michal Schmidt , "David S . Miller" , Sasha Levin Subject: [added to the 4.1 stable tree] bnx2x: fix possible overrun of VFPF multicast addresses array Date: Thu, 18 Jan 2018 21:01:01 +0000 Message-ID: <20180118205908.3220-182-alexander.levin@microsoft.com> References: <20180118205908.3220-1-alexander.levin@microsoft.com> In-Reply-To: <20180118205908.3220-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Michal Schmidt This patch has been added to the stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 22118d861cec5da6ed525aaf12a3de9bfeffc58f ] It is too late to check for the limit of the number of VF multicast addresses after they have already been copied to the req->multicast[] array, possibly overflowing it. Do the check before copying. Also fix the error path to not skip unlocking vf2pf_mutex. Signed-off-by: Michal Schmidt Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c | 23 +++++++++++---------= --- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c b/drivers/net= /ethernet/broadcom/bnx2x/bnx2x_vfpf.c index 06b8c0d8fd3b..996d2dc21bde 100644 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c @@ -852,7 +852,7 @@ int bnx2x_vfpf_set_mcast(struct net_device *dev) struct bnx2x *bp =3D netdev_priv(dev); struct vfpf_set_q_filters_tlv *req =3D &bp->vf2pf_mbox->req.set_q_filters= ; struct pfvf_general_resp_tlv *resp =3D &bp->vf2pf_mbox->resp.general_resp= ; - int rc, i =3D 0; + int rc =3D 0, i =3D 0; struct netdev_hw_addr *ha; =20 if (bp->state !=3D BNX2X_STATE_OPEN) { @@ -867,6 +867,15 @@ int bnx2x_vfpf_set_mcast(struct net_device *dev) /* Get Rx mode requested */ DP(NETIF_MSG_IFUP, "dev->flags =3D %x\n", dev->flags); =20 + /* We support PFVF_MAX_MULTICAST_PER_VF mcast addresses tops */ + if (netdev_mc_count(dev) > PFVF_MAX_MULTICAST_PER_VF) { + DP(NETIF_MSG_IFUP, + "VF supports not more than %d multicast MAC addresses\n", + PFVF_MAX_MULTICAST_PER_VF); + rc =3D -EINVAL; + goto out; + } + netdev_for_each_mc_addr(ha, dev) { DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n", bnx2x_mc_addr(ha)); @@ -874,16 +883,6 @@ int bnx2x_vfpf_set_mcast(struct net_device *dev) i++; } =20 - /* We support four PFVF_MAX_MULTICAST_PER_VF mcast - * addresses tops - */ - if (i >=3D PFVF_MAX_MULTICAST_PER_VF) { - DP(NETIF_MSG_IFUP, - "VF supports not more than %d multicast MAC addresses\n", - PFVF_MAX_MULTICAST_PER_VF); - return -EINVAL; - } - req->n_multicast =3D i; req->flags |=3D VFPF_SET_Q_FILTERS_MULTICAST_CHANGED; req->vf_qid =3D 0; @@ -908,7 +907,7 @@ int bnx2x_vfpf_set_mcast(struct net_device *dev) out: bnx2x_vfpf_finalize(bp, &req->first_tlv); =20 - return 0; + return rc; } =20 int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp) --=20 2.11.0