Unverified Commit b587ba7c authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!1404 bpf: cpumap: Fix memory leak in cpu_map_update_elem

parents 0e8f2fe7 37a90df3
Loading
Loading
Loading
Loading
+24 −16
Original line number Diff line number Diff line
@@ -143,22 +143,6 @@ static void get_cpu_map_entry(struct bpf_cpu_map_entry *rcpu)
	atomic_inc(&rcpu->refcnt);
}

/* called from workqueue, to workaround syscall using preempt_disable */
static void cpu_map_kthread_stop(struct work_struct *work)
{
	struct bpf_cpu_map_entry *rcpu;

	rcpu = container_of(work, struct bpf_cpu_map_entry, kthread_stop_wq);

	/* Wait for flush in __cpu_map_entry_free(), via full RCU barrier,
	 * as it waits until all in-flight call_rcu() callbacks complete.
	 */
	rcu_barrier();

	/* kthread_stop will wake_up_process and wait for it to complete */
	kthread_stop(rcpu->kthread);
}

static struct sk_buff *cpu_map_build_skb(struct bpf_cpu_map_entry *rcpu,
					 struct xdp_frame *xdpf)
{
@@ -240,6 +224,30 @@ static void put_cpu_map_entry(struct bpf_cpu_map_entry *rcpu)
	}
}

/* called from workqueue, to workaround syscall using preempt_disable */
static void cpu_map_kthread_stop(struct work_struct *work)
{
	struct bpf_cpu_map_entry *rcpu;
	int err;

	rcpu = container_of(work, struct bpf_cpu_map_entry, kthread_stop_wq);

	/* Wait for flush in __cpu_map_entry_free(), via full RCU barrier,
	 * as it waits until all in-flight call_rcu() callbacks complete.
	 */
	rcu_barrier();

	/* kthread_stop will wake_up_process and wait for it to complete */
	err = kthread_stop(rcpu->kthread);
	if (err) {
		/* kthread_stop may be called before cpu_map_kthread_run
		 * is executed, so we need to release the memory related
		 * to rcpu.
		 */
		put_cpu_map_entry(rcpu);
	}
}

static int cpu_map_kthread_run(void *data)
{
	struct bpf_cpu_map_entry *rcpu = data;