[<prev] [next>] [day] [month] [year] [list]
Message-ID: <01100196af6a2191-3abcd0ea-31eb-4cb7-a1a2-ffc925cdbeed-000000@eu-north-1.amazonses.com>
Date: Thu, 8 May 2025 10:21:30 +0000
From: Ozgur Kara <ozgur@...sey.org>
To: Eric Dumazet <edumazet@...gle.com>, Neal Cardwell <ncardwell@...gle.com>
Cc: "David S. Miller" <davem@...emloft.net>,
Kuniyuki Iwashima <kuniyu@...zon.com>,
David Ahern <dsahern@...nel.org>, Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>, Simon Horman <horms@...nel.org>,
netdev@...r.kernel.org,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: [PATCH] net: ipv4: Fix destination address determination in flowi4_init_output
From: Ozgur Karatas <ozgur@...sey.org>
flowi4_init_output() function returns an argument and if opt->srr is
true and opt->faddr is assigned to be checked before opt->faddr is
used but if opt->srr seems to be true and opt->faddr is not set
properly yet.
opt itself will be an incompletely initialized struct and this access
may cause a crash.
* added daddr
* like readability by passing a single daddr argument to
flowi4_init_output() call.
Signed-off-by: Ozgur Karatas <ozgur@...sey.org>
---
net/ipv4/syncookies.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
index 5459a78b9809..2ff92d512825 100644
--- a/net/ipv4/syncookies.c
+++ b/net/ipv4/syncookies.c
@@ -408,6 +408,7 @@ struct sock *cookie_v4_check(struct sock *sk,
struct sk_buff *skb)
struct flowi4 fl4;
struct rtable *rt;
__u8 rcv_wscale;
+ __be32 daddr;
int full_space;
SKB_DR(reason);
@@ -442,6 +443,17 @@ struct sock *cookie_v4_check(struct sock *sk,
struct sk_buff *skb)
goto out_free;
}
+ /* Safely determine destination address considered SRR option.
+ * The flowi4 destination address is derived from opt->faddr
if opt->srr is set.
+ * However IP options are not always present in the skb and
accessing opt->faddr
+ * without validating opt->optlen and opt->srr can lead to
undefined behavior.
+ */
+ if (opt && opt->optlen && opt->srr) {
+ daddr = opt->faddr;
+ } else {
+ daddr = ireq->ir_rmt_addr;
+ }
+
tcp_ao_syncookie(sk, skb, req, AF_INET);
/*
@@ -453,7 +465,7 @@ struct sock *cookie_v4_check(struct sock *sk,
struct sk_buff *skb)
flowi4_init_output(&fl4, ireq->ir_iif, ireq->ir_mark,
ip_sock_rt_tos(sk), ip_sock_rt_scope(sk),
IPPROTO_TCP, inet_sk_flowi_flags(sk),
- opt->srr ? opt->faddr : ireq->ir_rmt_addr,
+ daddr,
ireq->ir_loc_addr, th->source, th->dest, sk->sk_uid);
security_req_classify_flow(req, flowi4_to_flowi_common(&fl4));
rt = ip_route_output_key(net, &fl4);
--
2.39.5
Powered by blists - more mailing lists