Skip to content

Commit a8d5b4a

Browse files
Toshiaki Makitaborkmann
authored andcommitted
xdp: Helper function to clear kernel pointers in xdp_frame
xdp_frame has kernel pointers which should not be readable from bpf programs. When we want to reuse xdp_frame region but it may be read by bpf programs later, we can use this helper to clear kernel pointers. This is more efficient than calling memset() for the entire struct. Signed-off-by: Toshiaki Makita <[email protected]> Acked-by: Jesper Dangaard Brouer <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent dc22482 commit a8d5b4a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

include/net/xdp.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ struct xdp_frame {
8484
struct net_device *dev_rx; /* used by cpumap */
8585
};
8686

87+
/* Clear kernel pointers in xdp_frame */
88+
static inline void xdp_scrub_frame(struct xdp_frame *frame)
89+
{
90+
frame->data = NULL;
91+
frame->dev_rx = NULL;
92+
}
93+
8794
/* Convert xdp_buff to xdp_frame */
8895
static inline
8996
struct xdp_frame *convert_to_xdp_frame(struct xdp_buff *xdp)

0 commit comments

Comments
 (0)