From patchwork Thu Feb 15 18:27:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Chen X-Patchwork-Id: 13559056 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com [209.85.167.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E766D13A886 for ; Thu, 15 Feb 2024 18:27:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708021662; cv=none; b=SR/wYCtqlcgHl98RjD14RXiGgijcpB4MIylK3O7PSvq/J9f5QmHF+z2UUv5ueBG0Q6SVQcWc8KbNMnodcJGGGSE+WkLvlPuYhXKVIWgByoBi0ubE7aRXJazY16Akxv3crEOJ+MzB3yDUmhO17CMbpASMXuCfthP9RERnqpoZ8UA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708021662; c=relaxed/simple; bh=ie+iGNEbrInmXeM7EUsBPBcgubCE4VG7+3jCyBzKxUo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=ik45w95OSo4bRT01qzO/i1HSjBNn6EcvsqKX3rShO/kD3frYtOhRGoC5sB6J6r6EFQiGpB5TN9BfmdxcjKizYOotaxbY4484YPneE5QF00WlK6TV965TIc7q292AzFAiRN/b/AuGZ9/RdvjLekySQw2e90bWb1yVjsWKn9sdASs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=dkocPXiw; arc=none smtp.client-ip=209.85.167.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="dkocPXiw" Received: by mail-oi1-f178.google.com with SMTP id 5614622812f47-3c132695f1bso923899b6e.2 for ; Thu, 15 Feb 2024 10:27:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1708021660; x=1708626460; darn=vger.kernel.org; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=DjN0KrN4K8ta78wKaCE8wWbE++XwSGRWgX9GpS4l5Vc=; b=dkocPXiwKxPjNKvKpn1Giz/yJsLYGr08t/1oDKqQPxhngCye9Toe5F12ArYExOYp1C nxN0p/eHoTUcsqSCPNyxJ5jvkdEWvA8w3PzC+FlZB+bG5KgONkTGQF7/jcyQOfTG4s8r HVqhkBI2cy05zn8sSdlCykqe8ApGLZq50vMOg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708021660; x=1708626460; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DjN0KrN4K8ta78wKaCE8wWbE++XwSGRWgX9GpS4l5Vc=; b=BE0InFPNsJOTs58+Hp5mqDVuJni9mX4q8fPWCFcLvACWu7BotljcNgCK6Uozmxt7MU 5NFCDHspMRxBgxh1abOBfqf3jH1A7jwnYfdpsXNZ1cwlgKbVIipvh00fbtruPUYJ/eYF ra7EK5gG+iZA2iK7TfqQ4wZlkNuJtIeVx4Mfu0OHlNRZpBmo3zlGqChB9GrEghzAbdlW MWY+9e+u2y9UIg7frfvFPmKlWxp51hqrfQ4uPo7QwKo6QXfDj08rySgRoeYhuyJOGDYF RE745zs+vrTRxenfy12HpTvNG407ZQ+C1FSW/x3TBluyAtjMcoz82sTnm9gAvu4/vK0O GUrw== X-Gm-Message-State: AOJu0Yyn+KqF3RsgAzcr+/dcwLzqoXfBf2nYslGmRspJYFfhIQbUlOnX j4+6GCGTPdlAUpUuQEnS1Ghu+6zmz0N+WyCzV3ezteugu/S3jHt1o7hn4oSOsP3ivY61j2CDsG/ QP+Briv1DYfqb5Wm3eHJkVTsZXTZJmdnzMXWmWSMdV2SQ//eurfxvQ2P/MeJ8L8PGCQXyHCsZ6Z FbUS4j8AIUq5sC6vK3uUkhWc+60qWAViLbTNQPX7nGwQ== X-Google-Smtp-Source: AGHT+IHmhET1pIJGjsljlBZCoPCqcZ+qIT9ia2lHH5LqZUw/o0RXU9TJFUjekxtmoP5WcjUZzAj/nQ== X-Received: by 2002:a05:6808:9a3:b0:3c0:326a:9cff with SMTP id e3-20020a05680809a300b003c0326a9cffmr2709373oig.23.1708021659611; Thu, 15 Feb 2024 10:27:39 -0800 (PST) Received: from stbirv-lnx-1.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id mf4-20020a0562145d8400b0068f13038031sm901515qvb.5.2024.02.15.10.27.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 10:27:39 -0800 (PST) From: Justin Chen To: netdev@vger.kernel.org Cc: Justin Chen , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Hangyu Hua , bcm-kernel-feedback-list@broadcom.com (open list:BROADCOM ASP 2.0 ETHERNET DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 2/2] net: bcmasp: Sanity check is off by one Date: Thu, 15 Feb 2024 10:27:32 -0800 Message-Id: <20240215182732.1536941-3-justin.chen@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240215182732.1536941-1-justin.chen@broadcom.com> References: <20240215182732.1536941-1-justin.chen@broadcom.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org A sanity check for OOB write is off by one leading to a false positive when the array is full. Fixes: 9b90aca97f6d ("net: ethernet: bcmasp: fix possible OOB write in bcmasp_netfilt_get_all_active()") Signed-off-by: Justin Chen Reviewed-by: Florian Fainelli --- drivers/net/ethernet/broadcom/asp2/bcmasp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c b/drivers/net/ethernet/broadcom/asp2/bcmasp.c index 29b04a274d07..80245c65cc90 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c @@ -535,9 +535,6 @@ int bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs, int j = 0, i; for (i = 0; i < NUM_NET_FILTERS; i++) { - if (j == *rule_cnt) - return -EMSGSIZE; - if (!priv->net_filters[i].claimed || priv->net_filters[i].port != intf->port) continue; @@ -547,6 +544,9 @@ int bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs, priv->net_filters[i - 1].wake_filter) continue; + if (j == *rule_cnt) + return -EMSGSIZE; + rule_locs[j++] = priv->net_filters[i].fs.location; }