Netdev List
 help / color / mirror / Atom feed
From: Jesper Dangaard Brouer <brouer@redhat.com>
To: netdev@vger.kernel.org, BjörnTöpel <bjorn.topel@intel.com>,
	magnus.karlsson@intel.com
Cc: eugenia@mellanox.com, Jason Wang <jasowang@redhat.com>,
	John Fastabend <john.fastabend@gmail.com>,
	Eran Ben Elisha <eranbe@mellanox.com>,
	Saeed Mahameed <saeedm@mellanox.com>,
	galp@mellanox.com, Jesper Dangaard Brouer <brouer@redhat.com>,
	Daniel Borkmann <borkmann@iogearbox.net>,
	Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	Tariq Toukan <tariqt@mellanox.com>
Subject: [net-next V11 PATCH 17/17] xdp: avoid leaking info stored in frame data on page reuse
Date: Tue, 17 Apr 2018 16:46:43 +0200	[thread overview]
Message-ID: <152397640301.20272.9781402055431898663.stgit@firesoul> (raw)
In-Reply-To: <152397622657.20272.10121948713784224943.stgit@firesoul>

The bpf infrastructure and verifier goes to great length to avoid
bpf progs leaking kernel (pointer) info.

For queueing an xdp_buff via XDP_REDIRECT, xdp_frame info stores
kernel info (incl pointers) in top part of frame data (xdp->data_hard_start).
Checks are in place to assure enough headroom is available for this.

This info is not cleared, and if the frame is reused, then a
malicious user could use bpf_xdp_adjust_head helper to move
xdp->data into this area.  Thus, making this area readable.

This is not super critical as XDP progs requires root or
CAP_SYS_ADMIN, which are privileged enough for such info.  An
effort (is underway) towards moving networking bpf hooks to the
lesser privileged mode CAP_NET_ADMIN, where leaking such info
should be avoided.  Thus, this patch to clear the info when
needed.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
---
 net/core/filter.c |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/net/core/filter.c b/net/core/filter.c
index 3bb0cb98a9be..a374b8560bc4 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -2692,6 +2692,7 @@ static unsigned long xdp_get_metalen(const struct xdp_buff *xdp)
 
 BPF_CALL_2(bpf_xdp_adjust_head, struct xdp_buff *, xdp, int, offset)
 {
+	void *xdp_frame_end = xdp->data_hard_start + sizeof(struct xdp_frame);
 	unsigned long metalen = xdp_get_metalen(xdp);
 	void *data_start = xdp->data_hard_start + metalen;
 	void *data = xdp->data + offset;
@@ -2700,6 +2701,13 @@ BPF_CALL_2(bpf_xdp_adjust_head, struct xdp_buff *, xdp, int, offset)
 		     data > xdp->data_end - ETH_HLEN))
 		return -EINVAL;
 
+	/* Avoid info leak, when reusing area prev used by xdp_frame */
+	if (data < xdp_frame_end) {
+		unsigned long clearlen = xdp_frame_end - data;
+
+		memset(data, 0, clearlen);
+	}
+
 	if (metalen)
 		memmove(xdp->data_meta + offset,
 			xdp->data_meta, metalen);

  parent reply	other threads:[~2018-04-17 14:46 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-17 14:45 [net-next V11 PATCH 00/17] XDP redirect memory return API Jesper Dangaard Brouer
2018-04-17 14:45 ` [net-next V11 PATCH 01/17] mlx5: basic XDP_REDIRECT forward support Jesper Dangaard Brouer
2018-04-17 14:45 ` [net-next V11 PATCH 02/17] xdp: introduce xdp_return_frame API and use in cpumap Jesper Dangaard Brouer
2018-04-17 14:45 ` [net-next V11 PATCH 03/17] ixgbe: use xdp_return_frame API Jesper Dangaard Brouer
2018-04-17 14:45 ` [net-next V11 PATCH 04/17] xdp: move struct xdp_buff from filter.h to xdp.h Jesper Dangaard Brouer
2018-04-17 14:45 ` [net-next V11 PATCH 05/17] xdp: introduce a new xdp_frame type Jesper Dangaard Brouer
2018-04-17 14:45 ` [net-next V11 PATCH 06/17] tun: convert to use generic xdp_frame and xdp_return_frame API Jesper Dangaard Brouer
2018-04-17 14:45 ` [net-next V11 PATCH 07/17] virtio_net: " Jesper Dangaard Brouer
2018-04-17 14:45 ` [net-next V11 PATCH 08/17] bpf: cpumap convert to use generic xdp_frame Jesper Dangaard Brouer
2018-04-17 14:46 ` [net-next V11 PATCH 09/17] i40e: convert to use generic xdp_frame and xdp_return_frame API Jesper Dangaard Brouer
2018-04-17 14:46 ` [net-next V11 PATCH 10/17] mlx5: register a memory model when XDP is enabled Jesper Dangaard Brouer
2018-04-17 14:46 ` [net-next V11 PATCH 11/17] xdp: rhashtable with allocator ID to pointer mapping Jesper Dangaard Brouer
2018-04-17 14:46 ` [net-next V11 PATCH 12/17] page_pool: refurbish version of page_pool code Jesper Dangaard Brouer
2018-04-17 14:46 ` [net-next V11 PATCH 13/17] xdp: allow page_pool as an allocator type in xdp_return_frame Jesper Dangaard Brouer
2018-04-17 14:46 ` [net-next V11 PATCH 14/17] mlx5: use page_pool for xdp_return_frame call Jesper Dangaard Brouer
2018-04-17 14:46 ` [net-next V11 PATCH 15/17] xdp: transition into using xdp_frame for return API Jesper Dangaard Brouer
2018-04-17 14:46 ` [net-next V11 PATCH 16/17] xdp: transition into using xdp_frame for ndo_xdp_xmit Jesper Dangaard Brouer
2018-04-17 14:46 ` Jesper Dangaard Brouer [this message]
2018-04-17 15:04   ` [net-next V11 PATCH 17/17] xdp: avoid leaking info stored in frame data on page reuse Daniel Borkmann
2018-04-17 14:48 ` [net-next V11 PATCH 00/17] XDP redirect memory return API Alexei Starovoitov
2018-04-17 15:18   ` David Miller
2018-04-17 15:24     ` Daniel Borkmann
2018-04-17 15:35       ` David Miller
2018-04-17 16:27         ` Jesper Dangaard Brouer

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=152397640301.20272.9781402055431898663.stgit@firesoul \
    --to=brouer@redhat.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=bjorn.topel@intel.com \
    --cc=borkmann@iogearbox.net \
    --cc=eranbe@mellanox.com \
    --cc=eugenia@mellanox.com \
    --cc=galp@mellanox.com \
    --cc=jasowang@redhat.com \
    --cc=john.fastabend@gmail.com \
    --cc=magnus.karlsson@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@mellanox.com \
    --cc=tariqt@mellanox.com \
    /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