From nobody Sun Feb 8 18:09:12 2026 Received: from mx0b-0064b401.pphosted.com (mx0b-0064b401.pphosted.com [205.220.178.238]) (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 DDD5D1A7045; Mon, 28 Apr 2025 07:46:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.178.238 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745826381; cv=none; b=haeqx8/tmm8W1jzWtf5ji9N8Vza9x1hKuCyjo5Yi0gpCiq+1N9KKoZibECgQOpLiXnmrmsg6SLNWTd6zo/dDcYts9DGVcXeyNiky62vbfkp7eQHobqLFPAEuzdzOGnb+dC0bqIrnXBOx8PRUbgZDYZI/yp7dDQmdFQSWiZtOCRw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745826381; c=relaxed/simple; bh=8DTAecAt9r8ellcs7EaFiom0OPFEFDsj/CyPT0H59Jw=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=CWm7ppZ9XvYg1UrTyTsfRhQntnfz6d8aj1ysX087/JiYHnJ6xn9vuxaVm0XwPgm5Z4kNEczA1dBxv9F+yTEM/CqB/vXRNjWwpIPvlDIHVRZr5cq2RSb35cXNjkY9IRCl5MSxAF2YfunyMSWWKm2QeyUdsL/TmBdt5eiDIHpvLz0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=windriver.com; spf=pass smtp.mailfrom=windriver.com; arc=none smtp.client-ip=205.220.178.238 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=windriver.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=windriver.com Received: from pps.filterd (m0250812.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53S4USKV031481; Mon, 28 Apr 2025 07:45:56 GMT Received: from ala-exchng01.corp.ad.wrs.com (ala-exchng01.wrs.com [147.11.82.252]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 468pf92kcv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Mon, 28 Apr 2025 07:45:55 +0000 (GMT) Received: from ALA-EXCHNG02.corp.ad.wrs.com (147.11.82.254) by ala-exchng01.corp.ad.wrs.com (147.11.82.252) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.43; Mon, 28 Apr 2025 00:45:54 -0700 Received: from pek-lpg-core1.wrs.com (147.11.136.210) by ALA-EXCHNG02.corp.ad.wrs.com (147.11.82.254) with Microsoft SMTP Server id 15.1.2507.43 via Frontend Transport; Mon, 28 Apr 2025 00:45:51 -0700 From: To: , CC: , , , , , , , , , , , Subject: [PATCH 6.1.y v2] net/sched: act_mirred: don't override retval if we already lost the skb Date: Mon, 28 Apr 2025 15:45:50 +0800 Message-ID: <20250428074550.4155739-1-jianqi.ren.cn@windriver.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: VFwVoa9xvISlTfXPcQrXoyM0FLbjBtAh X-Authority-Analysis: v=2.4 cv=EavIQOmC c=1 sm=1 tr=0 ts=680f3233 cx=c_pps a=/ZJR302f846pc/tyiSlYyQ==:117 a=/ZJR302f846pc/tyiSlYyQ==:17 a=XR8D0OoHHMoA:10 a=VwQbUJbxAAAA:8 a=pGLkceISAAAA:8 a=QyXUC8HyAAAA:8 a=A7XncKjpAAAA:8 a=J1Y8HTJGAAAA:8 a=t7CeM3EgAAAA:8 a=46DbhiKqDBczhwNKROYA:9 a=R9rPLQDAdC6-Ub70kJmZ:22 a=y1Q9-5lHfBjTkpIzbSAN:22 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNDI4MDA2MyBTYWx0ZWRfX+ri3JQ2l4NZh hpQRsn7oGEnlYHXnxBebjYZ4rLaFklzJOoVuqhpZ9RcPS2mZlvy82kkEZI6ouLI7rqevKy4YrXe WwMwDAA67hSu+XyrkWU8htqB5thMGCr8odepqczsUtdXQsEIeorGwTP/uub9woTOUx0H5fmtC3Y BKYJHM1Vpn2LLlicocwcAefdPio39YS+ZlLiUpzHE+yIhhdWrxe/2HhNAJHcNhjyQszsn6NbJzT /YBDIa9PxKX02bjQMqZTua3f9qSLstSZCPfyh07cZRgl+M+ER0r9oqaXCHN4Ljn8JsF7DDAIpzu ibet87itcqppLoqWl+4UvdDQtcLFgAvCrCKU9f9t4gsaQS+E+TULUu6x7019Syxtj+2rANPUe9C qv2Ze+NK/axRY9soNcvV0MzrZTJP6DKvpC5dZpNmqfAS1S40QUwu4YD2+O9PKzGyR7qtqJ/w X-Proofpoint-ORIG-GUID: VFwVoa9xvISlTfXPcQrXoyM0FLbjBtAh X-Sensitive_Customer_Information: Yes X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-04-28_02,2025-04-24_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 malwarescore=0 lowpriorityscore=0 spamscore=0 bulkscore=0 adultscore=0 suspectscore=0 phishscore=0 mlxscore=0 clxscore=1015 mlxlogscore=999 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.21.0-2504070000 definitions=main-2504280063 Content-Type: text/plain; charset="utf-8" From: Jakub Kicinski [ Upstream commit 166c2c8a6a4dc2e4ceba9e10cfe81c3e469e3210 ] If we're redirecting the skb, and haven't called tcf_mirred_forward(), yet, we need to tell the core to drop the skb by setting the retcode to SHOT. If we have called tcf_mirred_forward(), however, the skb is out of our hands and returning SHOT will lead to UaF. Move the retval override to the error path which actually need it. Reviewed-by: Michal Swiatkowski Fixes: e5cf1baf92cb ("act_mirred: use TC_ACT_REINSERT when possible") Signed-off-by: Jakub Kicinski Acked-by: Jamal Hadi Salim Signed-off-by: David S. Miller [Minor conflict resolved due to code context change.] Signed-off-by: Jianqi Ren Signed-off-by: He Zhe --- v2: Fix the following issue net/sched/act_mirred.c:265:6: error: variable 'is_redirect' is used uninitialized whenever 'if' condition is true found by the following tuxmake(https://lore.kernel.org/stable/CA+G9fYu+FEZ-3ye30Hk2sk1+LFsw7iO5AHu= eUa9H1Ub=3DJO-k2g@mail.gmail.com/) tuxmake --runtime podman --target-arch arm --toolchain clang-20 --kconfig a= llmodconfig LLVM=3D1 LLVM_IAS=3D1 Verified the build test Signed-off-by: Jianqi Ren --- net/sched/act_mirred.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c index 36395e5db3b4..bbc34987bd09 100644 --- a/net/sched/act_mirred.c +++ b/net/sched/act_mirred.c @@ -255,31 +255,31 @@ static int tcf_mirred_act(struct sk_buff *skb, const = struct tc_action *a, =20 m_mac_header_xmit =3D READ_ONCE(m->tcfm_mac_header_xmit); m_eaction =3D READ_ONCE(m->tcfm_eaction); + is_redirect =3D tcf_mirred_is_act_redirect(m_eaction); retval =3D READ_ONCE(m->tcf_action); dev =3D rcu_dereference_bh(m->tcfm_dev); if (unlikely(!dev)) { pr_notice_once("tc mirred: target device is gone\n"); - goto out; + goto err_cant_do; } =20 if (unlikely(!(dev->flags & IFF_UP)) || !netif_carrier_ok(dev)) { net_notice_ratelimited("tc mirred to Houston: device %s is down\n", dev->name); - goto out; + goto err_cant_do; } =20 /* we could easily avoid the clone only if called by ingress and clsact; * since we can't easily detect the clsact caller, skip clone only for * ingress - that covers the TC S/W datapath. */ - is_redirect =3D tcf_mirred_is_act_redirect(m_eaction); at_ingress =3D skb_at_tc_ingress(skb); use_reinsert =3D at_ingress && is_redirect && tcf_mirred_can_reinsert(retval); if (!use_reinsert) { skb2 =3D skb_clone(skb, GFP_ATOMIC); if (!skb2) - goto out; + goto err_cant_do; } =20 want_ingress =3D tcf_mirred_act_wants_ingress(m_eaction); @@ -321,12 +321,16 @@ static int tcf_mirred_act(struct sk_buff *skb, const = struct tc_action *a, } =20 err =3D tcf_mirred_forward(want_ingress, skb2); - if (err) { -out: + if (err) tcf_action_inc_overlimit_qstats(&m->common); - if (tcf_mirred_is_act_redirect(m_eaction)) - retval =3D TC_ACT_SHOT; - } + __this_cpu_dec(mirred_nest_level); + + return retval; + +err_cant_do: + if (is_redirect) + retval =3D TC_ACT_SHOT; + tcf_action_inc_overlimit_qstats(&m->common); __this_cpu_dec(mirred_nest_level); =20 return retval; --=20 2.34.1