* [PATCH bpf] bpf: Fix error usage of map_fd and fdget() in generic_map_update_batch()
@ 2021-10-19 3:29 Xu Kuohai
2021-10-21 22:04 ` Alexei Starovoitov
0 siblings, 1 reply; 3+ messages in thread
From: Xu Kuohai @ 2021-10-19 3:29 UTC (permalink / raw)
To: bpf
Cc: Brian Vazquez, Alexei Starovoitov, Daniel Borkmann,
Yonghong Song, Xu Kuohai
1. The ufd in generic_map_update_batch() should be read from batch.map_fd;
2. A call to fdget() should be followed by a symmetric call to fdput().
Fixes: aa2e93b8e58e ("bpf: Add generic support for update and delete batch ops")
Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
---
kernel/bpf/syscall.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 4e50c0bfdb7d..9dab49d3f394 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -1337,12 +1337,11 @@ int generic_map_update_batch(struct bpf_map *map,
void __user *values = u64_to_user_ptr(attr->batch.values);
void __user *keys = u64_to_user_ptr(attr->batch.keys);
u32 value_size, cp, max_count;
- int ufd = attr->map_fd;
+ int ufd = attr->batch.map_fd;
void *key, *value;
struct fd f;
int err = 0;
- f = fdget(ufd);
if (attr->batch.elem_flags & ~BPF_F_LOCK)
return -EINVAL;
@@ -1367,6 +1366,7 @@ int generic_map_update_batch(struct bpf_map *map,
return -ENOMEM;
}
+ f = fdget(ufd); /* bpf_map_do_batch() guarantees ufd is valid */
for (cp = 0; cp < max_count; cp++) {
err = -EFAULT;
if (copy_from_user(key, keys + cp * map->key_size,
@@ -1386,6 +1386,7 @@ int generic_map_update_batch(struct bpf_map *map,
kvfree(value);
kvfree(key);
+ fdput(f);
return err;
}
--
2.27.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf] bpf: Fix error usage of map_fd and fdget() in generic_map_update_batch()
2021-10-19 3:29 [PATCH bpf] bpf: Fix error usage of map_fd and fdget() in generic_map_update_batch() Xu Kuohai
@ 2021-10-21 22:04 ` Alexei Starovoitov
2021-10-21 22:22 ` Brian Vazquez
0 siblings, 1 reply; 3+ messages in thread
From: Alexei Starovoitov @ 2021-10-21 22:04 UTC (permalink / raw)
To: Xu Kuohai
Cc: bpf, Brian Vazquez, Alexei Starovoitov, Daniel Borkmann, Yonghong Song
On Mon, Oct 18, 2021 at 8:24 PM Xu Kuohai <xukuohai@huawei.com> wrote:
>
> 1. The ufd in generic_map_update_batch() should be read from batch.map_fd;
> 2. A call to fdget() should be followed by a symmetric call to fdput().
>
> Fixes: aa2e93b8e58e ("bpf: Add generic support for update and delete batch ops")
> Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
Ouch. Thanks for the fix. Applied.
Brian,
when your bugs are fixed please pay attention in the future and
review the fix with Reviewed-by or Acked-by.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf] bpf: Fix error usage of map_fd and fdget() in generic_map_update_batch()
2021-10-21 22:04 ` Alexei Starovoitov
@ 2021-10-21 22:22 ` Brian Vazquez
0 siblings, 0 replies; 3+ messages in thread
From: Brian Vazquez @ 2021-10-21 22:22 UTC (permalink / raw)
To: Alexei Starovoitov
Cc: Xu Kuohai, bpf, Alexei Starovoitov, Daniel Borkmann, Yonghong Song
Oh I completely missed the first email. Sorry about that!
Thanks for the patch Xu.
On Thu, Oct 21, 2021 at 3:05 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Mon, Oct 18, 2021 at 8:24 PM Xu Kuohai <xukuohai@huawei.com> wrote:
> >
> > 1. The ufd in generic_map_update_batch() should be read from batch.map_fd;
> > 2. A call to fdget() should be followed by a symmetric call to fdput().
> >
> > Fixes: aa2e93b8e58e ("bpf: Add generic support for update and delete batch ops")
> > Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
>
> Ouch. Thanks for the fix. Applied.
>
> Brian,
> when your bugs are fixed please pay attention in the future and
> review the fix with Reviewed-by or Acked-by.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-10-21 22:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-19 3:29 [PATCH bpf] bpf: Fix error usage of map_fd and fdget() in generic_map_update_batch() Xu Kuohai
2021-10-21 22:04 ` Alexei Starovoitov
2021-10-21 22:22 ` Brian Vazquez
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).