public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Kui-Feng Lee <sinquersw@gmail.com>
To: Martin KaFai Lau <martin.lau@linux.dev>, Kui-Feng Lee <kuifeng@meta.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, song@kernel.org,
	kernel-team@meta.com, andrii@kernel.org, sdf@google.com
Subject: Re: [PATCH bpf-next v5 4/8] libbpf: Create a bpf_link in bpf_map__attach_struct_ops().
Date: Thu, 9 Mar 2023 10:16:24 -0800	[thread overview]
Message-ID: <742b762d-14f7-8d1e-4aeb-8bb0634dba4b@gmail.com> (raw)
In-Reply-To: <74abb86f-e0c2-8a0b-c90d-502ffda1571e@linux.dev>



On 3/9/23 09:09, Martin KaFai Lau wrote:
> On 3/8/23 4:22 PM, Kui-Feng Lee wrote:
>>
>>
>> On 3/8/23 13:42, Martin KaFai Lau wrote:
>>> On 3/7/23 4:50 PM, Kui-Feng Lee wrote:
>>>> @@ -11566,22 +11591,34 @@ struct bpf_link *bpf_program__attach(const 
>>>> struct bpf_program *prog)
>>>>       return link;
>>>>   }
>>>> +struct bpf_link_struct_ops {
>>>> +    struct bpf_link link;
>>>> +    int map_fd;
>>>> +};
>>>> +
>>>>   static int bpf_link__detach_struct_ops(struct bpf_link *link)
>>>>   {
>>>> +    struct bpf_link_struct_ops *st_link;
>>>>       __u32 zero = 0;
>>>> -    if (bpf_map_delete_elem(link->fd, &zero))
>>>> -        return -errno;
>>>> +    st_link = container_of(link, struct bpf_link_struct_ops, link);
>>>> -    return 0;
>>>> +    if (st_link->map_fd < 0) {
>>>
>>> map_fd < 0 should always be true?
>>
>> If the user pass a wrong link, it can fail.
> 
> I may have missed something. How can user directly pass a link to this 
> static function?

Ouch! You are right. This check is not necessary. I mixed it with the 
old detach feature.


> 
>> I check it here explicitly even the kernel returns
>> an error for deleting an element of a struct_ops w/ link.
> Yep, the kernel should have stopped the delete if the user somehow 
> corrupted the map_fd to -1.
> 
>>
>>>
>>>> +        /* Fake bpf_link */
>>>> +        if (bpf_map_delete_elem(link->fd, &zero))
>>>> +            return -errno;
>>>> +        return 0;
>>>> +    }
>>>> +
>>>> +    /* Doesn't support detaching. */
>>>> +    return -EOPNOTSUPP;
> 

  reply	other threads:[~2023-03-09 18:16 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-08  0:50 [PATCH bpf-next v5 0/8] Transit between BPF TCP congestion controls Kui-Feng Lee
2023-03-08  0:50 ` [PATCH bpf-next v5 1/8] bpf: Retire the struct_ops map kvalue->refcnt Kui-Feng Lee
2023-03-08 18:30   ` Martin KaFai Lau
2023-03-08 22:30     ` Kui-Feng Lee
2023-03-08  0:50 ` [PATCH bpf-next v5 2/8] net: Update an existing TCP congestion control algorithm Kui-Feng Lee
2023-03-08 18:59   ` Martin KaFai Lau
2023-03-08 22:51     ` Kui-Feng Lee
2023-03-08  0:50 ` [PATCH bpf-next v5 3/8] bpf: Create links for BPF struct_ops maps Kui-Feng Lee
2023-03-08 15:01   ` kernel test robot
2023-03-08 15:32   ` kernel test robot
2023-03-08 16:03   ` kernel test robot
2023-03-08 20:04   ` Martin KaFai Lau
2023-03-08 23:46     ` Kui-Feng Lee
2023-03-08  0:50 ` [PATCH bpf-next v5 4/8] libbpf: Create a bpf_link in bpf_map__attach_struct_ops() Kui-Feng Lee
2023-03-08 21:42   ` Martin KaFai Lau
2023-03-09  0:22     ` Kui-Feng Lee
2023-03-09 17:09       ` Martin KaFai Lau
2023-03-09 18:16         ` Kui-Feng Lee [this message]
2023-03-09 18:19           ` Kui-Feng Lee
2023-03-08  0:50 ` [PATCH bpf-next v5 5/8] bpf: Update the struct_ops of a bpf_link Kui-Feng Lee
2023-03-08 22:21   ` Martin KaFai Lau
2023-03-09  3:09     ` Kui-Feng Lee
2023-03-08  0:50 ` [PATCH bpf-next v5 6/8] libbpf: Update a bpf_link with another struct_ops Kui-Feng Lee
2023-03-08 22:32   ` Martin KaFai Lau
2023-03-08  0:50 ` [PATCH bpf-next v5 7/8] libbpf: Use .struct_ops.link section to indicate a struct_ops with a link Kui-Feng Lee
2023-03-08  0:50 ` [PATCH bpf-next v5 8/8] selftests/bpf: Test switching TCP Congestion Control algorithms Kui-Feng Lee
2023-03-08 23:10   ` Martin KaFai Lau
2023-03-09  3:34     ` Kui-Feng Lee

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=742b762d-14f7-8d1e-4aeb-8bb0634dba4b@gmail.com \
    --to=sinquersw@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=kernel-team@meta.com \
    --cc=kuifeng@meta.com \
    --cc=martin.lau@linux.dev \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    /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