From: Steffen Klassert <steffen.klassert@secunet.com>
To: Hyunwoo Kim <v4bel@theori.io>
Cc: Eric Dumazet <edumazet@google.com>,
Taehee Yoo <ap420073@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Dmitry Kozlov <xeb@mail.ru>, David Ahern <dsahern@kernel.org>,
<tudordana@google.com>, <netdev@vger.kernel.org>,
<imv4bel@gmail.com>
Subject: Re: [PATCH] net: Fix invalid ip_route_output_ports() call
Date: Tue, 21 Mar 2023 11:52:02 +0100 [thread overview]
Message-ID: <ZBmMUjSXPzFBWeTv@gauss3.secunet.de> (raw)
In-Reply-To: <20230321050803.GA22060@ubuntu>
On Mon, Mar 20, 2023 at 10:08:03PM -0700, Hyunwoo Kim wrote:
> On Mon, Mar 20, 2023 at 08:17:15PM -0700, Eric Dumazet wrote:
> > On Mon, Mar 20, 2023 at 7:49 PM Hyunwoo Kim <v4bel@theori.io> wrote:
>
> struct rtable *ip_route_output_flow(struct net *net, struct flowi4 *flp4,
> const struct sock *sk)
> {
> struct rtable *rt = __ip_route_output_key(net, flp4);
>
> if (IS_ERR(rt))
> return rt;
>
> if (flp4->flowi4_proto) {
> flp4->flowi4_oif = rt->dst.dev->ifindex;
> rt = (struct rtable *)xfrm_lookup_route(net, &rt->dst,
> flowi4_to_flowi(flp4), // <===[4]
> sk, 0);
> }
>
> return rt;
> }
> EXPORT_SYMBOL_GPL(ip_route_output_flow);
> ```
> This is the cause of the stack OOB. Because we calculated the struct flowi pointer address based on struct flowi4 declared as a stack variable,
> if we accessed a member of flowi that exceeds the size of flowi4, we would get an OOB.
>
>
> Finally, xfrm_state_find()[5] uses daddr, which is a pointer to `&fl->u.ip4.saddr`.
> Here, the encap_family variable can be entered by the user using the netlink socket.
> If the user chose AF_INET6 instead of AF_INET, the xfrm_dst_hash() function would be called on an AF_INET6 basis[6],
> which could cause an OOB in the `struct flowi4 fl4` variable of igmpv3_newpack()[2].
Thanks for the great analysis!
Looks like a missing sanity check when the policy gets inserted.
Can you send the output of 'ip x p' for that policy?
next prev parent reply other threads:[~2023-03-21 10:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-21 2:49 [PATCH] net: Fix invalid ip_route_output_ports() call Hyunwoo Kim
2023-03-21 3:17 ` Eric Dumazet
2023-03-21 5:08 ` Hyunwoo Kim
2023-03-21 5:19 ` Eric Dumazet
2023-03-21 10:52 ` Steffen Klassert [this message]
2023-03-21 11:14 ` Hyunwoo Kim
2023-03-21 11:19 ` Eric Dumazet
2023-03-21 11:35 ` Hyunwoo Kim
2023-03-24 9:57 ` Steffen Klassert
2023-03-30 7:42 ` Tudor Ambarus
2023-03-30 7:56 ` Steffen Klassert
2023-03-21 11:36 ` Steffen Klassert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZBmMUjSXPzFBWeTv@gauss3.secunet.de \
--to=steffen.klassert@secunet.com \
--cc=ap420073@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=imv4bel@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tudordana@google.com \
--cc=v4bel@theori.io \
--cc=xeb@mail.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).