Skip to contentSkip to conversation

media: bpf: do not copy more entries than user space requested

PATCH Applied Sean Young 2 participants 3 messages Jun 23, 2021 – Jun 24, 2021

Subsystems (3)
lore
Share & tools
lore

Sean Young

author maintainer
#0 lore raw

PATCH 1/1 media: bpf: do not copy more entries than user space requested

The syscall bpf(BPF_PROG_QUERY, &attr) should the prog_cnt field to see how many entries user space provided and return ENOSPC if there are more programs than that. Before this patch, this is not checked and ENOSPC is never returned.

Note that one lirc device is limited to 64 bpf programs, and user space I'm aware of -- ir-keytable -- always gives enough space for 64 entries already. However, we should not copy program ids than are requested.

---
 drivers/media/rc/bpf-lirc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/rc/bpf-lirc.c +2 -1
index 3fe3edd80876..afae0afe3f81 100644
@@ -326,7 +326,8 @@ int lirc_prog_query(const union bpf_attr *attr, union bpf_attr __user *uattr)
 	}
 
 	if (attr->query.prog_cnt != 0 && prog_ids && cnt)
-		ret = bpf_prog_array_copy_to_user(progs, prog_ids, cnt);
+		ret = bpf_prog_array_copy_to_user(progs, prog_ids,
+						  attr->query.prog_cnt);
 
 unlock:
 	mutex_unlock(&ir_raw_handler_lock);
Signature · 1 line
2.31.1
author maintainer
#1 lore raw
Quoted 1 line · Sean Young

The syscall bpf(BPF_PROG_QUERY, &attr) should the prog_cnt field to see

s/should the/should use the/

Quoted 29 lines

how many entries user space provided and return ENOSPC if there are more programs than that. Before this patch, this is not checked and ENOSPC is never returned.

Note that one lirc device is limited to 64 bpf programs, and user space I'm aware of -- ir-keytable -- always gives enough space for 64 entries already. However, we should not copy program ids than are requested.

---
 drivers/media/rc/bpf-lirc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/rc/bpf-lirc.c +2 -1
index 3fe3edd80876..afae0afe3f81 100644
@@ -326,7 +326,8 @@ int lirc_prog_query(const union bpf_attr *attr, union bpf_attr __user *uattr)
 	}
 
 	if (attr->query.prog_cnt != 0 && prog_ids && cnt)
-		ret = bpf_prog_array_copy_to_user(progs, prog_ids, cnt);
+		ret = bpf_prog_array_copy_to_user(progs, prog_ids,
+						  attr->query.prog_cnt);
 
 unlock:
 	mutex_unlock(&ir_raw_handler_lock);
Signature · 1 line
2.31.1
#2 lore raw
In reply to Sean Young
This patch was applied to bpf/bpf-next.git (refs/heads/master):

Hello:

This patch was applied to bpf/bpf-next.git (refs/heads/master):

Quoted 10 lines · On Wed, 23 Jun 2021 22:37:54 +0100 you wrote:

The syscall bpf(BPF_PROG_QUERY, &attr) should the prog_cnt field to see how many entries user space provided and return ENOSPC if there are more programs than that. Before this patch, this is not checked and ENOSPC is never returned.

Note that one lirc device is limited to 64 bpf programs, and user space I'm aware of -- ir-keytable -- always gives enough space for 64 entries already. However, we should not copy program ids than are requested.

[...]

Here is the summary with links:
- media: bpf: do not copy more entries than user space requested

    https://git.kernel.org/bpf/bpf-next/c/647d446d66e4

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html