bpf: Fix NULL dereference in bpf_task_storage
PATCH 1/1 bpf: Fix NULL dereference in bpf_task_storage
In bpf_pid_task_storage_update_elem(), it missed to test the !task_storage_ptr(task) which then could trigger a NULL pointer exception in bpf_local_storage_update().
--- kernel/bpf/bpf_task_storage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/bpf_task_storage.c +1 -1
@@ -150,7 +150,7 @@ static int bpf_pid_task_storage_update_elem(struct bpf_map *map, void *key,*/ WARN_ON_ONCE (!rcu_read_lock_held ()); task =pid_task (pid,PIDTYPE_PID ); -if (!task) { +if (!task || !task_storage_ptr (task)) { err = -ENOENT ; goto out; }
Signature · 1 line
2.24.1
Quoted 9 lines · Martin KaFai Lau
In
bpf_pid_task_storage_update_elem(), it missed to test the !task_storage_ptr(task) which then could trigger a NULL pointer exception inbpf_local_storage_update().Fixes 4cf1bc1f1045 ("bpf: Implement task local storage")Tested-by Roman Gushchin <[email protected]>Cc KP Singh <[email protected]>Signed-off-by Martin KaFai Lau <[email protected]>
Thanks for fixing this! I had it in v1 and while actioning:
https://lore.kernel.org/bpf/20201028011321.4yu62347lfzisxwy@kafai-mbp
I inadvertently removed it from bpf_pid_task_storage_update_elem too.
Quoted 20 lines
--- kernel/bpf/bpf_task_storage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/bpf/bpf_task_storage.c +1
-2@@ -150,7 +150,7 @@ static int bpf_pid_task_storage_update_elem(struct bpf_map *map, void *key,*/ WARN_ON_ONCE (!rcu_read_lock_held ()); task =pid_task (pid,PIDTYPE_PID ); -if (!task) { +if (!task || !task_storage_ptr (task)) { err = -ENOENT ; goto out; } --2.24.1
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, 11 Nov 2020 16:19:19 -0800 you wrote:
In
bpf_pid_task_storage_update_elem(), it missed to test the !task_storage_ptr(task) which then could trigger a NULL pointer exception inbpf_local_storage_update().Fixes 4cf1bc1f1045 ("bpf: Implement task local storage")Tested-by Roman Gushchin <[email protected]>Cc KP Singh <[email protected]>Signed-off-by Martin KaFai Lau <[email protected]>[...]
Here is the summary with links:
- [bpf-next] bpf: Fix NULL dereference in bpf_task_storage
https://git.kernel.org/bpf/bpf-next/c/09a3dac7b579
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html