From nobody Fri Apr 3 22:38:23 2026 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 C3DCC36E47A for ; Mon, 23 Mar 2026 08:08:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774253297; cv=none; b=U8Mzdi4EDJCjPcBobp0gmk5ThUk9Kptd9+GuexP2iiT/CYovfcUqkzKjXrvWNIhiQ1WPvRQXM4Qpqv3lhuinjtT6J/JlD5vxDSuV37vc/YfbS2HmhGZlELJeG7G0G0Yx6GJYCmzRlF3vup90G34K5feKkZHtZp5EZ4SiAVxKB+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774253297; c=relaxed/simple; bh=5Zy0XUwX6iIi5GwhjGoPNY3Vg2jY5I/S4eF+tYiFOFE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=s+0SqDKiMPGc3czuqcJLzpz1hnYn455c5oQuH/uTCkkUTn9W4aqh1ugypipLoN5lmipwT4GGU+E41u1TeJiAo7mMFC3Gcsi7o6cSHOYLV24qg8edrk9yuJB5JERwIAq6Ml8uQ+6JCGUQ1C/361UFfYr7ULdAze/fTIo+DLIKq58= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XWFwbUKZ; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XWFwbUKZ" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2ad9516a653so17346835ad.0 for ; Mon, 23 Mar 2026 01:08:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774253295; x=1774858095; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=/oxuEK0aKiR5BZiJwQM9QbFzk9FiV34b8im9vtCPOQo=; b=XWFwbUKZWo7I3MG3tqXs8n0H4sRxFopjfXPGPFNcbMZKUu9ob+LOAD7gOq5j2nuA/X SZqmeBdfuZgAcfVUtUUx3/m+RIZ3mAtmrgx4crJLSj1uCP4QmtmMbXOp4hyckRkY2XyF rsYS8KX8Vv6mtlMvf90hGC1PDsmJurpXe7iSnSKf1+aGPo2vrX3JEO+v/zolES91AWm6 +jMGK3AbIFCydspdkPFlCWUMwEXuKqLvdQOYRewVHX91HbrGDrGEiuj4W+dPuQHr6wPv z9poGwhtAdUGB/ACXoZV3A3EgwtvM+TsqS04Ia+US+OepwuSqWQ+W9WIUilDuKk5ARUY XoZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774253295; x=1774858095; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=/oxuEK0aKiR5BZiJwQM9QbFzk9FiV34b8im9vtCPOQo=; b=JeeUyMhoWzwYqOyUYLZMEXBu6UrN5LI267V6AfF3gGQHmpGedz9n/5DKcFFAuv38qr JCVbKcFdsHjYNY57De7mqxOSau5JiL+VNiI2YrbtOArtV33xuqJE0daUatH/Nrrq+Rba LeX/kmX0rGkmnD6TnnmGSTiPUY9AEMD+5BjYIFJdCYoNnNfk6xm/psEWLFMfcyGbEqAh BlUauVJilv+lTYB50JAcTAl9rrX3at/PltJlhQppD952jot9IrUM3aco3Z+deya/nKJ9 x1DI0OenPYSSzSoEPxdtz1ghxjZzwlC11vMsmL/Yu43eU+oUAY91d8svQcGnyn/I/H4U z1fQ== X-Forwarded-Encrypted: i=1; AJvYcCX7h1xBYpwO9TmT01wfd+tOXJtmeGcB7nNtscubDCC/sgXiC6PIV7MIxFfxwSdnEp99QVf4au410wer7aw=@vger.kernel.org X-Gm-Message-State: AOJu0YxOlNOzCoLXaIs3vsPAJAaJT0pJSpofAHfIg5JNbLbS4J3+YPuB MOu4jvEwV4JOQfOcCmpA6QbUV18nbTxn1NT3W5N9uK8ZM0eN8mwHrQD0 X-Gm-Gg: ATEYQzyWZUSXG+ETBvfR9nVuddCn0uQjw9KngOFomaoFP+Vp32esKt+lKNsHmf2cl3g G9oFsPTHmNtQBvJ7I8WYfuYLepzTvHJSYLbEwx9qjKTPwsX1Ko/S9W4TcjXzUGFwtLVd4G+DzHo PjobLtfmmTZ83obSKvgAK3186v8tu2FX1fYatwniN0ekEPFIwzC0T4ZBnn5Z9nn01nY+ebd/+2m MEdF6E4BGIaoJQlcj/7OlFVcR4+5U2YxHphzKqIQt83HEaQ9HMvzBis2i/UJc3Y2R+J2Pz0BjnJ oi4Q0SO60ibK0i5U/iXQ+ez+N5YHY6hRwH6btYhGguTReZ4XfOkgG83TUXcxkvzUnsL2DLXUqro /0mqr3TWHruG8wli0gmDo7ktBd4yhY44IrKGMDB4r6TaNFIBrSjSSXotI9w/89NpDeqJ7UqXM9V 7c5XkchsHPJCr4FkMElrszHVoKkBzqgDPrGlpFcKXJYP5jAyhFaTRejKcSnJHWaaXbIR+0WgkUW mm8sAm4R9Y= X-Received: by 2002:a17:903:1a0f:b0:2b0:4f82:74b1 with SMTP id d9443c01a7336-2b0827c165emr102975785ad.44.1774253294945; Mon, 23 Mar 2026 01:08:14 -0700 (PDT) Received: from SLSGDTSWING002.tail0ac356.ts.net ([129.126.109.177]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b083549f63sm99706195ad.30.2026.03.23.01.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 01:08:14 -0700 (PDT) From: Weiming Shi To: Pablo Neira Ayuso , Florian Westphal , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Phil Sutter , Simon Horman , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Xiang Mei , Weiming Shi Subject: [PATCH nf] netfilter: nf_conntrack_sip: fix use of uninitialized rtp_addr in process_sdp Date: Mon, 23 Mar 2026 16:07:29 +0800 Message-ID: <20260323080727.2932866-3-bestswngs@gmail.com> X-Mailer: git-send-email 2.43.0 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 Content-Type: text/plain; charset="utf-8" process_sdp() declares union nf_inet_addr rtp_addr on the stack and passes it to the nf_nat_sip sdp_session hook after walking the SDP media descriptions. However rtp_addr is only initialized inside the media loop when a recognized media type with a non-zero port is found. If the SDP body contains no m=3D lines, only inactive media sections (m=3Daudio 0 ...) or only unrecognized media types, rtp_addr is never assigned. Despite that, the function still calls hooks->sdp_session() with &rtp_addr, causing nf_nat_sdp_session() to format the stale stack value as an IP address and rewrite the SDP session owner and connection lines with it. With CONFIG_INIT_STACK_ALL_ZERO (default on most distributions) this results in the session-level o=3D and c=3D addresses being rewritten to 0.0.0.0 for inactive SDP sessions. Without stack auto-init the rewritten address is whatever happened to be on the stack. Fix this by pre-initializing rtp_addr from the session-level connection address (caddr) when available, and tracking via a have_rtp_addr flag whether any valid address was established. Skip the sdp_session hook entirely when no valid address exists. Fixes: 4ab9e64e5e3c ("[NETFILTER]: nf_nat_sip: split up SDP mangling") Reported-by: Xiang Mei Signed-off-by: Weiming Shi --- net/netfilter/nf_conntrack_sip.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/net/netfilter/nf_conntrack_sip.c b/net/netfilter/nf_conntrack_= sip.c index 4ab5ef71d96db..17af0ff4ea7ab 100644 --- a/net/netfilter/nf_conntrack_sip.c +++ b/net/netfilter/nf_conntrack_sip.c @@ -1040,6 +1040,7 @@ static int process_sdp(struct sk_buff *skb, unsigned = int protoff, unsigned int port; const struct sdp_media_type *t; int ret =3D NF_ACCEPT; + bool have_rtp_addr =3D false; =20 hooks =3D rcu_dereference(nf_nat_sip_hooks); =20 @@ -1056,8 +1057,11 @@ static int process_sdp(struct sk_buff *skb, unsigned= int protoff, caddr_len =3D 0; if (ct_sip_parse_sdp_addr(ct, *dptr, sdpoff, *datalen, SDP_HDR_CONNECTION, SDP_HDR_MEDIA, - &matchoff, &matchlen, &caddr) > 0) + &matchoff, &matchlen, &caddr) > 0) { caddr_len =3D matchlen; + memcpy(&rtp_addr, &caddr, sizeof(rtp_addr)); + have_rtp_addr =3D true; + } =20 mediaoff =3D sdpoff; for (i =3D 0; i < ARRAY_SIZE(sdp_media_types); ) { @@ -1091,9 +1095,11 @@ static int process_sdp(struct sk_buff *skb, unsigned= int protoff, &matchoff, &matchlen, &maddr) > 0) { maddr_len =3D matchlen; memcpy(&rtp_addr, &maddr, sizeof(rtp_addr)); - } else if (caddr_len) + have_rtp_addr =3D true; + } else if (caddr_len) { memcpy(&rtp_addr, &caddr, sizeof(rtp_addr)); - else { + have_rtp_addr =3D true; + } else { nf_ct_helper_log(skb, ct, "cannot parse SDP message"); return NF_DROP; } @@ -1125,7 +1131,7 @@ static int process_sdp(struct sk_buff *skb, unsigned = int protoff, =20 /* Update session connection and owner addresses */ hooks =3D rcu_dereference(nf_nat_sip_hooks); - if (hooks && ct->status & IPS_NAT_MASK) + if (hooks && ct->status & IPS_NAT_MASK && have_rtp_addr) ret =3D hooks->sdp_session(skb, protoff, dataoff, dptr, datalen, sdpoff, &rtp_addr); --=20 2.43.0