Skip to content

Commit

Permalink
queueing: use CFI-safe ptr_ring cleanup function
Browse files Browse the repository at this point in the history
We make too nuanced use of ptr_ring to entirely move to the skb_array
wrappers, but we at least should avoid the naughty function pointer cast
when cleaning up skbs. Otherwise RAP/CFI will honk at us. This patch
uses the __skb_array_destroy_skb wrapper for the cleanup, rather than
directly providing kfree_skb, which is what other drivers in the same
situation do too.

Reported-by: PaX Team <pageexec@freemail.hu>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Change-Id: Idb0e8cfe2ecf9fa55534ddebab33a879b47afde5
(cherry picked from commit ae92cac0ff0842e21075a8532de7b17913e2bcdc)
Signed-off-by: TogoFire <togofire@mailfence.com>
  • Loading branch information
zx2c4 authored and TogoFire committed Jun 9, 2023
1 parent 5a87068 commit 9f3e8ab
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions drivers/net/wireguard/compat/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ ifeq ($(wildcard $(srctree)/include/linux/ptr_ring.h),)
ccflags-y += -I$(kbuild-dir)/compat/ptr_ring/include
endif

ifeq ($(wildcard $(srctree)/include/linux/skb_array.h),)
ccflags-y += -I$(kbuild-dir)/compat/skb_array/include
endif

ifeq ($(wildcard $(srctree)/include/linux/siphash.h),)
ccflags-y += -I$(kbuild-dir)/compat/siphash/include
wireguard-y += compat/siphash/siphash.o
Expand Down
11 changes: 11 additions & 0 deletions drivers/net/wireguard/compat/skb_array/include/linux/skb_array.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef _WG_SKB_ARRAY_H
#define _WG_SKB_ARRAY_H

#include <linux/skbuff.h>

static void __skb_array_destroy_skb(void *ptr)
{
kfree_skb(ptr);
}

#endif
3 changes: 2 additions & 1 deletion drivers/net/wireguard/queueing.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include "queueing.h"
#include <linux/skb_array.h>

struct multicore_worker __percpu *
wg_packet_percpu_multicore_worker_alloc(work_func_t function, void *ptr)
Expand Down Expand Up @@ -42,7 +43,7 @@ void wg_packet_queue_free(struct crypt_queue *queue, bool purge)
{
free_percpu(queue->worker);
WARN_ON(!purge && !__ptr_ring_empty(&queue->ring));
ptr_ring_cleanup(&queue->ring, purge ? (void(*)(void*))kfree_skb : NULL);
ptr_ring_cleanup(&queue->ring, purge ? __skb_array_destroy_skb : NULL);
}

#define NEXT(skb) ((skb)->prev)
Expand Down

0 comments on commit 9f3e8ab

Please sign in to comment.