Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1869334lql; Wed, 13 Mar 2024 10:16:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU9zf2RXuoNd9vNsSdTRuVM+22/TiI05Oc5IQApVaFjrgBpgTugQll9KGe+Ngk5pXzDOHot5kWmy/BZUTV5yLoJ7rQ6BMjOgPEHOdtkLA== X-Google-Smtp-Source: AGHT+IFKBluaB0KURxvf68rk8aMt3Cbm/COvhbNKYcMnENaHRw/vLGgFp90ng1ayQkrHLhWt2m6U X-Received: by 2002:a05:6a21:a598:b0:1a1:67e8:ba40 with SMTP id gd24-20020a056a21a59800b001a167e8ba40mr4435562pzc.13.1710350170487; Wed, 13 Mar 2024 10:16:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710350170; cv=pass; d=google.com; s=arc-20160816; b=IYTwk1PM7QrWESqAtDWHPb9C5NWA0xhK08T2wuP/eAgnf6CA+lXhM7WxpeFQEVeaI8 oBmhyzkCNoFN41ubmRaA4jJZOSWj7qZUm/UvfH/g3sdCg7Yu3W+/NVrRf4rde3AzcKK1 q38jvZVC2TSNnaq2lq3hH9OyRn8QhaYTh0GpYfGWAOgzgVMTd69m35AL4bZYnNAd6Bv2 pVDCzYQ/95UhE3f4wfLoSixWS02WtViLhHvhHouyHTLlK/SCaZ+njCR1gHMtDt+18cok NphBQVAm2uHEU4Rqi02j96KKyGeIYfyoUuJtWtN5wTavZvyLYHqJ0AWwaBbiAdMB8Uxh 5rcg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=mkwLhnOIMTHdPHhi5X0niLv5HQFLJnqXdJrKMCIS4aY=; fh=2Q/U9VJ17ssjm+8gudEYNXVjsAxcHSELcc38Oe5VV04=; b=Y2DWo2X9txOaDyjLyAIYml3HISUNXrVUKWEL+JC/5MY5rnuPtjS6AYSzjPf4pqI8eU LvX0xwOccNew1AZX3a5ZdakH5XNeyUX3PAdDmtj11TB/aQc+D+OLywZ6DOSX/nzQrrsE mlyEX7NrYK2dvPUNHFpsOXf2uqVInjey3gn+x4P6gZKPL+g2FBoXgC2rox1we378eSRb A3Kc3ML9KMjbKlZXcfL2IlMATdk8bwpcxWKJVgClLQLUEwNo+Pke/hCHdJFod7yao/ge 6XB9t1GoDH1omC/5ZdGShano+R6XBQ4Mc4Y8YgnvTkoqOdWsDdqWmTLoxklXagOb2B6Y Hm/Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TpVvKH9J; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-101876-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101876-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id z197-20020a6333ce000000b005dab535faabsi9366863pgz.231.2024.03.13.10.16.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:16:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101876-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TpVvKH9J; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-101876-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101876-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 62F68B2428E for ; Wed, 13 Mar 2024 17:05:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 486B076F1C; Wed, 13 Mar 2024 16:40:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TpVvKH9J" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BFB376C97; Wed, 13 Mar 2024 16:40:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710348010; cv=none; b=fdhgMXFX4/6SqDZP7Xv5IoEmKNVGycUIaVuijvLpx3erR3Fe9RHqFdw9/QbjRf29bzcYn0XHlB7EwUe+5Po3rTmI65VeWnS+65GxtRlkudDSrDUUi5fZUr+pMbo05w4+xFXy83HhV6OBu1525nfomTUWGEAy69rUJZVpEhhxeKc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710348010; c=relaxed/simple; bh=BPbJntuskVES4ughBqn58IDptAR3zQxTerFw4OXbovw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bnFn/RK/2OBvTGLxfinL822/JetEINbRlgeHzhiyVkkOoCpJPxFV3DFRTMn/ufbWDqKM9hlTi4ZX9qN7YJnbgmb60xeeqwg3Q1KTpB11uSlFFbYaDv0Gd4TDsJ/XLIPllg7j6RDKUxE8FaPmtg0uPJ3rgmXVL+M4A/7b2vWrwms= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TpVvKH9J; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4304CC433B1; Wed, 13 Mar 2024 16:40:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710348010; bh=BPbJntuskVES4ughBqn58IDptAR3zQxTerFw4OXbovw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TpVvKH9J9U1RHwkNpqwVzQ4Vua/1k6oqsnU8/5auj7110dov2ZOg0IPp2uTOKoDr/ 45PMH/toF1JZncter90l7J+rKwWv582MTGUCaQlGdNB3wm2i/fEwsEwvO4vJHY7GaR ztZTgrq2GOsHWyDBBJJEwksH3elO+CehWXxtM1dNqcZHOFxq/GAti3niq0Cz8qtJdC KgFsZ6rRTYpSHwB/8Pv+CLEf7izD3vYJ4FRuMyEahJYzfeyMxzvU/0tKvlrhaXONiO Qigc5LiLEobHRUisYPnTcMETOWG3xopMWuT/Uss9qDmQwB/F06L5a2hnd4W/TN3E5B e94Kw2bJzt2wg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Horatiu Vultur , Simon Horman , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.1 08/71] net: sparx5: Fix use after free inside sparx5_del_mact_entry Date: Wed, 13 Mar 2024 12:38:54 -0400 Message-ID: <20240313163957.615276-9-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240313163957.615276-1-sashal@kernel.org> References: <20240313163957.615276-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v6.x/stable-review/patch-6.1.82-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-6.1.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 6.1.82-rc1 X-KernelTest-Deadline: 2024-03-15T16:39+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Horatiu Vultur [ Upstream commit 89d72d4125e94aa3c2140fedd97ce07ba9e37674 ] Based on the static analyzis of the code it looks like when an entry from the MAC table was removed, the entry was still used after being freed. More precise the vid of the mac_entry was used after calling devm_kfree on the mac_entry. The fix consists in first using the vid of the mac_entry to delete the entry from the HW and after that to free it. Fixes: b37a1bae742f ("net: sparx5: add mactable support") Signed-off-by: Horatiu Vultur Reviewed-by: Simon Horman Link: https://lore.kernel.org/r/20240301080608.3053468-1-horatiu.vultur@microchip.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c b/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c index 4af285918ea2a..75868b3f548ec 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c @@ -347,10 +347,10 @@ int sparx5_del_mact_entry(struct sparx5 *sparx5, list) { if ((vid == 0 || mact_entry->vid == vid) && ether_addr_equal(addr, mact_entry->mac)) { + sparx5_mact_forget(sparx5, addr, mact_entry->vid); + list_del(&mact_entry->list); devm_kfree(sparx5->dev, mact_entry); - - sparx5_mact_forget(sparx5, addr, mact_entry->vid); } } mutex_unlock(&sparx5->mact_lock); -- 2.43.0