Message ID | 20220415181442.551228-1-eric.dumazet@gmail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 99c07327ae11e24886d552dddbe4537bfca2765d |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net] netlink: reset network and mac headers in netlink_dump() | expand |
Hello: This patch was applied to netdev/net.git (master) by Paolo Abeni <pabeni@redhat.com>: On Fri, 15 Apr 2022 11:14:42 -0700 you wrote: > From: Eric Dumazet <edumazet@google.com> > > netlink_dump() is allocating an skb, reserves space in it > but forgets to reset network header. > > This allows a BPF program, invoked later from sk_filter() > to access uninitialized kernel memory from the reserved > space. > > [...] Here is the summary with links: - [net] netlink: reset network and mac headers in netlink_dump() https://git.kernel.org/netdev/net/c/99c07327ae11 You are awesome, thank you!
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index 47a876ccd28816a6065d1c4b7de8cfc97e887a69..05a3795eac8e9a7c8343460d9a41e0755a64c36e 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -2263,6 +2263,13 @@ static int netlink_dump(struct sock *sk) * single netdev. The outcome is MSG_TRUNC error. */ skb_reserve(skb, skb_tailroom(skb) - alloc_size); + + /* Make sure malicious BPF programs can not read unitialized memory + * from skb->head -> skb->data + */ + skb_reset_network_header(skb); + skb_reset_mac_header(skb); + netlink_skb_set_owner_r(skb, sk); if (nlk->dump_done_errno > 0) {