Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1191454

Re: [PATCH v3 1/3] bpf: Add new bpf map type to store the pointer to struct perf_event

From Alexei Starovoitov <ast@plumgrid.com>
Newsgroups linux.kernel
Subject Re: [PATCH v3 1/3] bpf: Add new bpf map type to store the pointer to struct perf_event
Date 2015-07-24 04:30 +0200
Message-ID <pPAUh-xE-3@gated-at.bofh.it> (permalink)
References <pPlix-2VS-3@gated-at.bofh.it> <pPlix-2VS-1@gated-at.bofh.it> <pPxD5-433-27@gated-at.bofh.it> <pPAUh-xE-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 7/23/15 7:22 PM, xiakaixu wrote:
>>> +    /* check if the value is already stored */
>>> >>+    if (array->events[index])
>>> >>+        return -EINVAL;
>>> >>+
>>> >>+    /* convert the fd to the pointer to struct perf_event */
>>> >>+    event = convert_map_with_perf_event(value);
>> >
>> >imo helper name is misleading and it's too short to be separate
>> >function. Just inline it and you can reuse 'index' variable.
>> >
>>> >>+    if (!event)
>>> >>+        return -EBADF;
>>> >>+
>>> >>+    xchg(array->events + index, event);
>> >
>> >refcnt leak of old event! Please think it through.
>> >This type of bugs I shouldn't be finding.
> Maybe the commit message is not elaborate. Here I prevent
> user space from updating the existed event, so the return
> value of xchg() is NULL and no refcnt leak of old event.
> I will do the same as prog_array in next version.

I see then it's even worse.
You think that above check:
+    if (array->events[index])
+        return -EINVAL;
will protect the double insert?
It won't, since there are no locks here.
You can have two processes both seeing empty slot and
racing to do xchg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [PATCH v3 1/3] bpf: Add new bpf map type to store the pointer to  struct perf_event Alexei Starovoitov <ast@plumgrid.com> - 2015-07-24 01:00 +0200
  Re: [PATCH v3 1/3] bpf: Add new bpf map type to store the pointer to  struct perf_event Alexei Starovoitov <ast@plumgrid.com> - 2015-07-24 04:30 +0200
  Re: [PATCH v3 1/3] bpf: Add new bpf map type to store the pointer  to struct perf_event xiakaixu <xiakaixu@huawei.com> - 2015-07-24 04:30 +0200

csiph-web